Original Post
I don't understand why i get the message box "CreateWindow!", i.e. the CreateWindow function fails...
#include <windows.h>
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) {
switch( msg ) {
case WM_DESTROY:
PostQuitMessage( 0 );
break;
default:
DefWindowProc( hwnd, msg, wParam, lParam );
break;
}
return (LRESULT)0;
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, char * szCmdLine, int nCmdShow ) {
WNDCLASS wnd;
MSG msg;
HWND hwnd;
wnd.style = 0;
wnd.cbClsExtra = 0;
wnd.cbWndExtra = 0;
wnd.hbrBackground = (HBRUSH) GetStockObject( WHITE_BRUSH );
wnd.hCursor = LoadCursor( NULL, IDC_ARROW );
wnd.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wnd.hInstance = hInstance;
wnd.lpfnWndProc = WndProc;
wnd.lpszClassName = "GDI";
wnd.lpszMenuName = NULL;
if( !RegisterClass( &wnd ) ) {
MessageBox( NULL, "RegisterClass!", "Error", 0 );
return 0;
}
hwnd = CreateWindow( "GDI", "",
WS_OVERLAPPEDWINDOW,
100, 100, 300, 400,
NULL, NULL, hInstance, NULL );
if( NULL == hwnd ) {
MessageBox( NULL, "CreateWindow!", "Error", 0 );
return 0;
}
ShowWindow( hwnd, SW_SHOWNORMAL );
UpdateWindow( hwnd );
while( TRUE ) {
while( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) ) {
if( !GetMessage( &msg, NULL, 0, 0 ) ) {
return 0;
}
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
}