Howdy, Stranger!

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

Categories

Unable to draw to a window's dc that is minimized or hidden

rydirydi Member Posts: 4
im working on a tiny application.
but dunno how to overcome this strange problem.

the application starts and does nothing until i hit the minimize button on the system menu (upper right corner), the window get's minimized and a timer starts. then after 5 secs the window's device context should in theory be updated with some draw-text information (which it does not!) however, if i maximize the window before the 5 seconds have gone it updates the device context! so it the drawing works when window is maximized and not when its minimized. i've tried UpdateWindow and InvalidateRect etc.. when window is minimized without any luck. drawing-code looks something like this:
[code]case WM_TIMER:
update = 1;

window.KillTimer();
window.ShowBaloonTip();

SendMessage(window.GetHwnd(), WM_PAINT, 0, 0);
break;

case WM_PAINT:
if (update == 1)
{
window.BeginPaint();
window.PrintfNL("Test");
window.PrintfNL("Test 2");
window.EndPaint();
}
InvalidateRect(window.GetHwnd(), &window.rc, TRUE);
window.UpdateWindow();
update = 0;
break;[/code]


Comments

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    [color=Blue]Can you tell me what exactly are you trying to do? There are few issues in that code:

    1. The application [b]should not[/b] send WM_PAINT messages directly. It will cause strange behaviours in your application. If you need something to be redrawn - call InvalidateRect() and if you need immediate redraw - call UpdateWindow() AFTER InvalidateRect().

    2. WM_PAINT message is only for drawing. You cannot call any InvalidateRect() or other refreshing functions there - because they will cause WM_PAINT to be sent again and again - the result is an endless loop of redrawing. Also, BeginPaint/EndPaint brackets are not optional in WM_PAINT - these calls must be there - if you avoid these brackets - you must call DefWindowProc() to force Windows to handle the WM_PAINT message. Otherwise, same result - endless redrawing.

    And how exactly are you drawing on MINIMIZED window? Minimized window does not have client area and WM_PAINT is for client area only.

    Again, my question is why timer, why 5 seconds and what do you need to do?[/color]

    : im working on a tiny application.
    : but dunno how to overcome this strange problem.
    :
    : the application starts and does nothing until i hit the minimize
    : button on the system menu (upper right corner), the window get's
    : minimized and a timer starts. then after 5 secs the window's device
    : context should in theory be updated with some draw-text information
    : (which it does not!) however, if i maximize the window before the 5
    : seconds have gone it updates the device context! so it the drawing
    : works when window is maximized and not when its minimized. i've
    : tried UpdateWindow and InvalidateRect etc.. when window is minimized
    : without any luck. drawing-code looks something like this:
    : [code]: case WM_TIMER:
    : update = 1;
    :
    : window.KillTimer();
    : window.ShowBaloonTip();
    :
    : SendMessage(window.GetHwnd(), WM_PAINT, 0, 0);
    : break;
    :
    : case WM_PAINT:
    : if (update == 1)
    : {
    : window.BeginPaint();
    : window.PrintfNL("Test");
    : window.PrintfNL("Test 2");
    : window.EndPaint();
    : }
    : InvalidateRect(window.GetHwnd(), &window.rc, TRUE);
    : window.UpdateWindow();
    : update = 0;
    : break;[/code]:
    :
    :
    :
  • rydirydi Member Posts: 4
    okay, sorry for not being more specific.

    This is what i try to do:
    When i minimize the window it jumps down to the systray. This works fine! Then a timer starts. After 5 seconds (I used 5 seconds just as to test the timer for the application). When the timer hits 5 seconds it calls for a WM_TIMER message. Then what i want to do is to update the window with some text while running in the background. Like draw some text-info to the window with DrawText. I know i could use a listbox for this, but i just wanted to use DrawText also i could add some more graphical stuff if i want. The Speed window in bit-torrent has a tray-icon and draws to a client window in the background just to give you an bad example of what i mean.

    [code]void Window::BeginPaint()
    {
    hdc = ::BeginPaint(hWnd, &ps);
    }

    void Window::EndPaint()
    {
    ::EndPaint(hWnd, &ps);
    }[/code]
  • untiountio Member Posts: 14
    Hi,
    Yo do not need WM_PAINT to change a window when it is not visible. You'll get a WM_PAINT message when the window becomes visible.
    Another point is update the text of the minimized window. If you take a look at any minimized window, you'll see that the text on it is the title of the window when it is maximized. If this is your case, use WM_SETTEXT to change it.

    Please, forgive me if this is not useful.
  • untiountio Member Posts: 14
    Hi,
    Yo do not need WM_PAINT to change a window when it is not visible. You'll get a WM_PAINT message when the window becomes visible.
    Another point is update the text of the minimized window. If you take a look at any minimized window, you'll see that the text on it is the title of the window when it is maximized. If this is your case, use WM_SETTEXT to change it.

    Please, forgive me if this is not useful.
  • rydirydi Member Posts: 4
    well, i fixed the problem with using a listbox.
    but all information is usefull _for later use_ so thanks.
Sign In or Register to comment.