I just started learning the Win API,
this is the first code i wrote by referring some various tutorials i found in the internet...
i have a problem, the program won't close. when i click the X on the corner the window is destroyed, but the process still keeps running ( i can see it on the Task Manager )...
how do i make the process end/quit... dosen't WM_QUIT do that??
--------------------------------------------------------------------------------------------------------------------------------------Code:#include <Windows.h> // message handler LRESULT CALLBACK WndProc(HWND hWindow, UINT iMessage,WPARAM wParam, LPARAM lParam); int WINAPI WinMain( HINSTANCE hInstance, // Handle to the current instance HINSTANCE hPrevInst, // Handle to the previous instance LPSTR lpCmdLine, // Pointer to the command line int nShowCmd // Shows the state of the window ) { WNDCLASS kWndClass; // window object // set visual properties of the window kWndClass.hCursor = LoadCursor(NULL, IDC_ARROW); kWndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); kWndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); // set system properties of the window kWndClass.hInstance = hInstance; kWndClass.lpfnWndProc = (WNDPROC)WndProc; kWndClass.lpszClassName = TEXT("01 Basic Window"); // set extra properties kWndClass.lpszMenuName = NULL; kWndClass.cbClsExtra = NULL; kWndClass.cbWndExtra = NULL; kWndClass.style = NULL; // register the window object if(!RegisterClass(&kWndClass)) { MessageBox(NULL, TEXT("Window Registration Failed!"), TEXT("Error!"), MB_ICONEXCLAMATION | MB_OK); return -1; } HWND hWindow; // The window hWindow = CreateWindow( TEXT("01 Basic Window"), // Registered class name TEXT("A Blank Window"), // Application window name WS_OVERLAPPEDWINDOW | WS_VISIBLE, // Window style CW_USEDEFAULT, // Horizontal position of the window CW_USEDEFAULT, // Vertical position of the window CW_USEDEFAULT, // Window width CW_USEDEFAULT, // Window height NULL, // Handle to the parent window NULL, // Handle to the menu the identifier hInstance, // Handle to the application instance NULL // Pointer to the window-creation data ); // Check if it failed to create the window successfully if(!hWindow) return FALSE; ShowWindow(hWindow,nShowCmd); UpdateWindow(hWindow); MSG kMessage; // Message // Message Loop while( GetMessage(&kMessage,hWindow,0,0)!= FALSE ) { TranslateMessage(&kMessage); DispatchMessage(&kMessage); } return kMessage.wParam; } LRESULT CALLBACK WndProc(HWND hWindow, UINT iMessage,WPARAM wParam, LPARAM lParam) { switch(iMessage) { case WM_CLOSE: DestroyWindow(hWindow); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWindow,iMessage,wParam,lParam); } return 0; }
by the way,
i am using windows 7 32 bit.
do i have to use WNDCLASSEX other than WNDCLASS in win 7 ??
i now tried the code from this site,
Tutorial: A Simple Window
and it worked correctly...![]()
That code is using WNDCLASSEX and relevent "Ex" functions....
--------------------------------------------------------------------------------------------------------------------------------------



LinkBack URL
About LinkBacks




