Article ID: 198583
Article Last Modified on 11/14/2003
// PeekMsgTest.cpp
#include <windows.h>
#define WINDOW_TITLE L"PeekMessage Test"
#define CLASS_NAME L"SampleWndClass"
#define MESSAGE L"Click on the window to close"
HINSTANCE hAppInstance = NULL;
LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_PAINT:
{
PAINTSTRUCT ps = {0};
RECT rc = {10, 10, 200, 100};
OutputDebugString (L"WndProc (WM_PAINT)\r\n");
BeginPaint (hWnd, &ps);
DrawText (ps.hdc, MESSAGE, lstrlen (MESSAGE),
&rc, DT_LEFT);
EndPaint (hWnd, &ps);
return 0;
}
case WM_LBUTTONUP:
DestroyWindow (hWnd);
return 0;
case WM_DESTROY:
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hWnd, uMsg, wParam, lParam);
}
int WINAPI WinMain (HINSTANCE hInst, HINSTANCE, LPWSTR, int)
{
WNDCLASS wc = {0};
MSG msg = {0};
HWND hWnd = NULL;
hAppInstance = hInst;
wc.lpfnWndProc = WndProc;
wc.hInstance = hAppInstance;
wc.hIcon = NULL;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszClassName = CLASS_NAME;
if (RegisterClass (&wc) == NULL) return -1;
hWnd = CreateWindow (CLASS_NAME, WINDOW_TITLE,
WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hAppInstance, NULL);
if (hWnd == NULL) return -1;
ShowWindow (hWnd, SW_SHOW);
UpdateWindow (hWnd);
while (1)
{
if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;
DispatchMessage (&msg);
}
}
return 0;
}
Additional query words: kbDSupport WM_PAINT PeekMessage
Keywords: kbbug kbnofix KB198583