[MPLAY32]

- Display formatted system messages in case of diverse failues.
- Add an error check for RegisterClassEx() and CreateWindow() in _tWinMain().
Patch by Ricardo Hanke.

CORE-7880 #resolve #comment Committed, thanks!

svn path=/trunk/; revision=63936
This commit is contained in:
Hermès Bélusca-Maïto 2014-08-24 14:10:49 +00:00
parent cb9669d967
commit c4ffcdd3ad

View file

@ -54,16 +54,27 @@ void DisableMenuItems(void)
EnableMenuItem(hMainMenu, IDM_DEVPROPS, MF_BYCOMMAND | MF_GRAYED); EnableMenuItem(hMainMenu, IDM_DEVPROPS, MF_BYCOMMAND | MF_GRAYED);
} }
static VOID
ShowLastWin32Error(HWND hwnd)
{
DWORD dwError;
LPTSTR lpMessageBuffer;
dwError = GetLastError();
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, 0, (LPWSTR)&lpMessageBuffer, 0, NULL);
MessageBox(hwnd, lpMessageBuffer, szAppTitle, MB_OK | MB_ICONERROR);
LocalFree(lpMessageBuffer);
}
static VOID static VOID
SetImageList(HWND hwnd) SetImageList(HWND hwnd)
{ {
HIMAGELIST hImageList; HIMAGELIST hImageList;
hImageList = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR24, 1, 1); hImageList = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR24, 1, 1);
if (!hImageList) if (!hImageList)
{ {
MessageBox(hwnd, _T("ImageList it is not created!"), NULL, MB_OK); ShowLastWin32Error(hwnd);
return; return;
} }
@ -138,7 +149,7 @@ InitControls(HWND hwnd)
NULL); NULL);
if (!hTrackBar) if (!hTrackBar)
{ {
MessageBox(hwnd, _T("TrackBar it is not created!"), NULL, MB_OK); ShowLastWin32Error(hwnd);
return; return;
} }
@ -158,7 +169,7 @@ InitControls(HWND hwnd)
NULL); NULL);
if (!hToolBar) if (!hToolBar)
{ {
MessageBox(hwnd, _T("ToolBar it is not created!"), NULL, MB_OK); ShowLastWin32Error(hwnd);
return; return;
} }
@ -743,7 +754,11 @@ _tWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR lpCmdLine, INT nCmdShow)
WndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); WndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
WndClass.lpszMenuName = MAKEINTRESOURCE(IDR_MAINMENU); WndClass.lpszMenuName = MAKEINTRESOURCE(IDR_MAINMENU);
RegisterClassEx(&WndClass); if (!RegisterClassEx(&WndClass))
{
ShowLastWin32Error(0);
return 0;
}
hwnd = CreateWindow(szClassName, hwnd = CreateWindow(szClassName,
szAppTitle, szAppTitle,
@ -756,6 +771,11 @@ _tWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR lpCmdLine, INT nCmdShow)
NULL, NULL,
hInstance, hInstance,
NULL); NULL);
if (!hwnd)
{
ShowLastWin32Error(0);
return 0;
}
DragAcceptFiles(hwnd, TRUE); DragAcceptFiles(hwnd, TRUE);
@ -780,5 +800,5 @@ _tWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR lpCmdLine, INT nCmdShow)
DispatchMessage(&msg); DispatchMessage(&msg);
} }
return 0; return (INT)msg.wParam;
} }