Microsoft KB Archive/198583

= BUG: PeekMessage does not retrieve WM_PAINT messages =

Article ID: 198583

Article Last Modified on 11/14/2003

-

APPLIES TO


 * Microsoft Windows CE 2.0 for the Handheld PC
 * Microsoft Windows CE 2.0 for the Handheld PC
 * Microsoft Windows CE 1.0

-



This article was previously published under Q198583



SYMPTOMS
Applications that use the PeekMessage function to process or to determine the existence of window messages in a thread's message queue may experience painting problems.



CAUSE
The PeekMessage function under Windows CE does not check for WM_PAINT messages posted to a window and therefore will not return any WM_PAINT messages when PeekMessage is called.



RESOLUTION
Applications should call GetMessage in order to handle all WM_PAINT messages.



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.



Steps to Reproduce Behavior
Compile the following sample code as a WinCE Windows Application. When the application is run, the application's window will paint correctly when maximized from a minimized state since a WM_PAINT message is sent to the window.

However, if the user clicks on the Start button twice, first to open the Start menu then to dismiss the menu, the application's window will not paint the area covered by the Start menu. This is due to the WM_PAINT message being posted to the window.

Sample Code: // PeekMsgTest.cpp #include 

#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

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.