How to get window behind dialog box to redraw when dialog is moved?

On Windows, when I display a dialog box (either a custom one, or a standard open/save file dialog), and move the dialog box around over the parent window, the parent window does not redraw, leaving trails of the dialog behind as it's dragged. (The parent window uses OpenGL to draw, but not sure this is relevant.) How do I get the main window to redraw as the dialog is moved in front of it?

I tried adding a call to redraw my main window whenever the dialog's callback is sent a message, but this only causes redrawing to occur whenever a button is pushed or an edit field is typed in. It doesn't redraw when the dialog's window is moved. How can I detect this movement?


I suspect your opengl app is just using a window for the explicit purposes of rendering via opengl onto it, and then goes into a tight loop of checking for mouse/kb input followed by a redraw of the opengl surface. An I'm guessing you are not pumping messages after drawing a frame. And more importantly, that little stub WndProc you setup for your window, probably doesn't have a WM_PAINT handler.

Two things to consider. Your WndProc for your main window needs to catch WM_PAINT, redraw, and validate the surface. That is....

LRESULT __stdcall YourMainWndProcHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    switch (uMsg)
        case WM_PAINT:
            PAINTSTRUCT ps;
            BeginPaint(hwnd, &ps);
            EndPaint(hwnd, &ps);
            // redraw your stuff here
            return 0;

Instead of calling BeginPaint/EndPaint to handle WM_APINT above you could likely just call ValidateRect.

And preferably, you are catching other window messages in your draw loop. That way, if a window gets obscured by something else outside of your app (e.g. resize operation, minimize/restore, other windows app takes foreground, etc...), then you can handle the repaint notifications as well.

A typical game tries to pump 1 message per drawing frame.

void MainLoop()
    MSG msg;
    if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))

    // your code to simulate and render below

Need Your Help

DIV with <br> new line text

javascript html css ajax dom

in my project i have an xmlhttpresponse object with some node, and i need to print element of one (serps) in a div obj but formatted.

A memory leak in cvCaptureFromCAM?

c++ debugging video memory-leaks opencv

It turns out that using cvCaptureFromCAM creates a memory in initialization. Usage of cvCaptureFromCAM creates a 48 byte memory leak of a NSAutoreleasePool object. I initially thought my program ha...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.