john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

win32 erase invalidaterect

BOOL InvalidateRect(
  __in  HWND hWnd,
  __in  const RECT *lpRect,
  __in  BOOL bErase
);

Parameters

hWnd [in]

A handle to the window whose update region has changed. If this parameter is NULL, the system invalidates and redraws all windows, and sends the WM_ERASEBKGND and WM_NCPAINT messages to the window procedure before the function returns.

lpRect [in]

A pointer to a RECT structure that contains the client coordinates of the rectangle to be added to the update region. If this parameter is NULL, the entire client area is added to the update region.

bErase [in]

Specifies whether the background within the update region is to be erased when the update region is processed. If this parameter is TRUE, the background is erased when the BeginPaint function is called. If this parameter is FALSE, the background remains unchanged.

Return Value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. Remarks

The invalidated areas accumulate in the update region until the region is processed when the next WM_PAINT message occurs or until the region is validated by using the ValidateRect or ValidateRgn function.

The system sends a WM_PAINT message to a window whenever its update region is not empty and there are no other messages in the application queue for that window.

If the bErase parameter is TRUE for any part of the update region, the background is erased in the entire region, not just in the specified part.

RECT rc;
POINT aptPentagon[6] = {50,2, 98,35, 79,90, 21,90, 2,35, 50,2}, 
      aptHexagon[7]  = {50,2, 93,25, 93,75, 50,98, 7,75, 7,25, 50,2}; 
POINT *ppt = aptPentagon; 
int cpt = 6;

  . 
  . 
  .

case WM_CHAR: 
    switch (wParam) 
    { 
        case '5': 
            ppt = aptPentagon; 
            cpt = 6; 
            break; 
        case '6': 
            ppt = aptHexagon; 
            cpt = 7; 
            break; 
    } 
    InvalidateRect(hwnd, NULL, TRUE); 
    return 0L;

case WM_PAINT: 
    hdc = BeginPaint(hwnd, &ps); 
    GetClientRect(hwnd, &rc); 
    SetMapMode(hdc, MM_ANISOTROPIC); 
    SetWindowExtEx(hdc, 100, 100, NULL); 
    SetViewportExtEx(hdc, rc.right, rc.bottom, NULL); 
    Polyline(hdc, ppt, cpt); 
    EndPaint(hwnd, &ps); 
    return 0L;

In this example, the NULL argument used by InvalidateRect specifies the entire client area; the TRUE argument causes the background to be erased. If you do not want the application to wait until the application's message queue has no other messages, use the UpdateWindow function to force the WM_PAINT message to be sent immediately. If there is any invalid part of the client area, UpdateWindow sends the WM_PAINT message for the specified window directly to the window procedure.

ShowWindow( hButtonBar[BUTTON_START], SW_HIDE ); // Hide the child window
ShowWindow( hButtonBar[BUTTON_START], SW_SHOW ); // Show the child window

OR We have retained the window handle, so we can destroy all the windows in a similar loop using a call such as

DestroyWindow(hButtonBar[i]);

  • « win32 win ce mouse input
  • Win CE to Windows XP quitbutton »

Published

Mar 16, 2010

Category

c-programming-guides

~427 words

Tags

  • c-programming-guides 25
  • erase 1
  • invalidaterect 1
  • win32 6