Window not closing and taking 100% of processor
Alright I know this is just a window with black background but I am starting a windows tic tac toe I already have one written but lost the source code in a reformat of a hard drive. Alright after the window closes it takes up 100% of processor in my task manager and doesn't close down anybody see any errors in my code.
Code:
#include <windows.h>
static char szApp[] = "win32ttt";
static int grid[9];
static int cyClient, cxClient;
static int R, G, B;
static int turn = 1;
void DrawGrid(HWND, HDC, HPEN);
void DrawX(HWND, HDC, HPEN, int, int, int, int);
void DrawO(HWND, HDC, HPEN, int, int);
void Check(int, HWND);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASS wc;
HWND hWnd;
MSG message;
wc.style = CS_VREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDC_ARROW);
wc.hbrBackground= (HBRUSH) GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName= szApp;
cxClient = 400;
cyClient = 450;
if(!RegisterClass(&wc))
{
MessageBox(NULL, "Could Not Register Class", "Windows Tic Tac Toe", MB_OK);
return 0;
}
hWnd = CreateWindow(szApp,
"Windows Tic Tac Toe",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
400,
450,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd, nShowCmd);
UpdateWindow(hWnd);
while(GetMessage(&message, hWnd, 0, 0))
{
TranslateMessage(&message);
DispatchMessage(&message);
}
return message.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}