How to force window to repaint? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to force window to repaint?

I thought UpdateWindow(hwnd) would do it, but it
doesn't. Do I need to actually create a separate
function to redraw the window and call this function
whenever I want to repaint the window?

Comments

  • HEPHEP Posts: 113Member
    Maybe this works, but I didn't try:

    HDC hdc = GetWindowDC(hWnd);
    SendMessage(hWnd, WM_PAINT, (WPARAM)hdc, 0);
    ReleaseDC(hdc);
  • AsmGuru62AsmGuru62 Posts: 6,519Member
    : Maybe this works, but I didn't try:
    :
    : HDC hdc = GetWindowDC(hWnd);
    : SendMessage(hWnd, WM_PAINT, (WPARAM)hdc, 0);
    : ReleaseDC(hdc);
    :
    [blue]The code above can cause trouble in some situations... This is how to force the redraw the right way:
    [code]
    InvalidateRect (hWnd, NULL, TRUE);
    UpdateWindow (hWnd);
    [/code]
    Also, this link:

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/pantdraw_88ac.asp

    mentions: "...The WM_PAINT message is generated by the system and should not be sent by an application..."[/blue]
  • HEPHEP Posts: 113Member
    : [blue]The code above can cause trouble in some situations... This is how to force the redraw the right way:
    : [code]
    : InvalidateRect (hWnd, NULL, TRUE);
    : UpdateWindow (hWnd);
    : [/code]
    : Also, this link:
    :
    : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/pantdraw_88ac.asp
    :
    : mentions: "...The WM_PAINT message is generated by the system and should not be sent by an application..."[/blue]
    :

    I also read that, but there was no explanation other than "The WM_PAINT message is generated by the system" why it should not be used.
    I'm curious. Why is it problematic? What do you mean with "in some situations"?
  • AsmGuru62AsmGuru62 Posts: 6,519Member
    : : [blue]The code above can cause trouble in some situations... This is how to force the redraw the right way:
    : : [code]
    : : InvalidateRect (hWnd, NULL, TRUE);
    : : UpdateWindow (hWnd);
    : : [/code]
    : : Also, this link:
    : :
    : : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/pantdraw_88ac.asp
    : :
    : : mentions: "...The WM_PAINT message is generated by the system and should not be sent by an application..."[/blue]
    : :
    :
    : I also read that, but there was no explanation other than "The WM_PAINT message is generated by the system" why it should not be used.
    : I'm curious. Why is it problematic? What do you mean with "in some situations"?
    :
    [blue]No idea why, but I trust Microsoft - if they say - it is no good, then it is no good.[/blue]
  • HEPHEP Posts: 113Member
    -- I trust Microsoft --

    No comment. ;-)
  • Johnny13Johnny13 Posts: 128Member
    : -- I trust Microsoft --
    :
    : No comment. ;-)
    :
    <-Never heard of any programmer would send a WM_PAINT message. ;-)
Sign In or Register to comment.