Når jeg kører følgende kode:
#include <windows.h>
const char g_szClassName[] = "myWindowClass";
HINSTANCE hInst;
HWND hWndMain;
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
return 0;
}
static bool initApplication(void)
{
WNDCLASS wc;
memset(&wc, 0, sizeof(WNDCLASS));
wc.style = CS_HREDRAW|CS_VREDRAW |CS_DBLCLKS;
wc.lpfnWndProc = (WNDPROC)MainWndProc;
wc.hInstance = hInst;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszClassName = (LPCWSTR)g_szClassName;
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
if (!RegisterClass(&wc))
return false;
return true;
}
HWND createMainWndClassWnd(void)
{
return CreateWindowA(g_szClassName, "Test Window",
WS_MINIMIZEBOX|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_MAXIMIZEBOX|
WS_CAPTION|WS_BORDER|WS_SYSMENU,
CW_USEDEFAULT,0,CW_USEDEFAULT,0,
NULL,
NULL,
hInst,
NULL);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nShowCmd)
{
MSG msg;
hInst = hInstance;
if (!initApplication()) {
MessageBoxA(NULL, "initApplication: failed", "Error", MB_OK);
return 0;
}
if ((hWndMain = createMainWndClassWnd()) == (HWND)0) {
MessageBoxA(NULL, "Failed to create window!", "Error", MB_OK);
return 0;
}
ShowWindow(hWndMain, SW_SHOW);
while (GetMessage(&msg, NULL, 0,0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
Kommer der en fejl om at den ikke kan oprette vinduet. Håber i kan hjælpe.