Ok i have decent experience with c++, however
it was consoel use, i finally decided that i understood enough
to start a win32 windowed application. So i got a tutorial
and got started, a little into the tutorial everything going
great and it running like i expected, however the problem
comes in when i close the program. The window
disappears when i press the X, but the process remains
in the task manager? Based on the following code
any idea why it doesnt quit running even though
the window disappears?
Code:
#include <windows.h>
#include "resource.h"
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstace, LPSTR lpCmdLine, int nCmdShow)
{
HWND hWnd;
MSG Msg;
WNDCLASSEX WndClsEx;
const char ClsName[] = "BasicApp";
const char WndName[] = "A Simple Window!";
WndClsEx.cbSize = (sizeof(WNDCLASSEX));
WndClsEx.style = CS_HREDRAW | CS_VREDRAW;
WndClsEx.lpfnWndProc = WndProcedure;
WndClsEx.cbClsExtra = 0;
WndClsEx.cbWndExtra = 0;
WndClsEx.hIcon = LoadIcon(NULL, IDI_INFORMATION);
WndClsEx.hCursor = LoadCursor(hInstance, MAKEINTRESOURCE(IDC_CURSOR1));
WndClsEx.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
WndClsEx.lpszMenuName = NULL;
WndClsEx.lpszClassName = ClsName;
WndClsEx.hInstance = hInstance;
WndClsEx.hIconSm = LoadIcon(NULL, IDI_INFORMATION);
RegisterClassEx(&WndClsEx);
hWnd = CreateWindow(ClsName, WndName, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
if(!hWnd)
{
return 0;
}
ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);
while( GetMessage(&Msg, hWnd, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
Sleep(1);
}
return 0;
}
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_DESTROY :
{
PostQuitMessage(WM_QUIT);
break;
}
default :
{
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
}
return 0;
}
EDIT : I didn't add the soruce for resource.h because the
problem was there before i added it.