does InvalidateRect() always invokes WM_PAINT

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ayan4u
    New Member
    • Apr 2007
    • 86

    does InvalidateRect() always invokes WM_PAINT

    hi,
    I am using InvalidataRect( hWnd, &rect, TRUE) to clear my client rect....does this mean that a WM_PAINT message will the invoked automatically by it....

    neways fot the time being lets assume it does....

    look at this code snippet...
    Code:
    switch(message)
    {
    case WM_CREATE:
    		 srand(time(0));
    		 break;
    case WM_SIZE:
    		 GetClientRect(hWnd, &rect);
    		 break;
    case WM_LBUTTONUP:
    		 InvalidateRect(hWnd, &rect, TRUE); // TRUE so that it clears 
    																	 // the screen
    		 break;
    case WM_PAINT:
    		 BeginPaint(hWnd, &ps);
    		 ShowText(hWnd, rect); 
    		EndPaint(hWnd, &ps);		 
    		break;
    case WM_DESTROY:
    		 PostQuitMessage(0);
    		 break:
    ...
    ...
    ...
    ...
    }
    now ShowText() does nothin but prints a text at random position on screen

    Now my question is if InvalidateRect( ) invokes WM_PAINT every time its called then it should print the desired text every time i click on a blank screen....but the fact is nothin happens after just for once the text is being displayed...
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Yes, InvalidateRect( ) always dispatches a WM_PAINT to redraw the window.

    This code:
    [code=c]
    case WM_PAINT:
    BeginPaint(hWnd , &ps);
    ShowText(hWnd, rect);
    EndPaint(hWnd, &ps);
    break;
    [/code]

    I'm not sure what ShowText() is. Do you mean RedrawWindow()? If ShowText is your function then it has to GetRect on hWnd so ti knows where to drop the text. Probably, you should use TextOut().

    Comment

    • ayan4u
      New Member
      • Apr 2007
      • 86

      #3
      Originally posted by weaknessforcats
      Yes, InvalidateRect( ) always dispatches a WM_PAINT to redraw the window.

      This code:
      [code=c]
      case WM_PAINT:
      BeginPaint(hWnd , &ps);
      ShowText(hWnd, rect);
      EndPaint(hWnd, &ps);
      break;
      [/code]

      I'm not sure what ShowText() is. Do you mean RedrawWindow()? If ShowText is your function then it has to GetRect on hWnd so ti knows where to drop the text. Probably, you should use TextOut().
      yes ShowText is my function and i have passed hWnd to GetClientRect.. .ok now that i have solved this problem i am facing another...

      now,
      [CODE=c]

      case WM_LBUTTONDOWN:
      InvalidateRect( hWnd, &rect, TRUE);
      break;
      [/CODE]

      must clear the client rect of window "hWnd" when i click left mouse button and invoke WM_PAINT and the text will be written again on the screen....but nothn happening on mouse click...(the story is different if i pass NULL as the first argument....whi ch in case repaints all the active windows)

      Comment

      • ayan4u
        New Member
        • Apr 2007
        • 86

        #4
        ok this problem solved too....just to add GetClientRect() before InvalidateRect( ) so that the structure "rect" is filled with enough informations... .

        Comment

        Working...