speedy6
June 21st, 2006, 06:59 PM
Hello!
I have an opengl application in c++ which draws some shapes for a period of time (30minutes or so). If I minimize the window it stops drawing the shapes. It only draws when I bring the window up.
How can I make it continue to draw even when minimized?
Thank you.
ovidiucucu
June 22nd, 2006, 07:57 AM
30 minutes just to draw "some shapes"? Wow! ;)
Well, let's say what can be done. Here are two alternatives:
First - Create a memory device context, and draw in it. After finishing, restore (if minimized) the window by calling ShowWindow and bit-blit in the window's device context by calling BitBlt function in WM_PAINT message handler (you can use a variable to take care if drawing was finished or not). Ugh... hard to control that, and and maybe the user wants to see the drawing progress, and maybe seeing nothing 30 seconds becomes nervous. So I would like to recommend the...
second - Disallow user minimizing the window during the long drawing task.
You have to remove WS_MINIMIZEBOX style and disable the "Minimize" sytem menu item
Using MFC
// remove minimize box
ModifyStyle(WS_MINIMIZEBOX, 0, SWP_FRAMECHANGED);
// disable "Minimize" system menu item
CMenu* pSysMenu = GetSystemMenu(FALSE);
pSysMenu->EnableMenuItem(SC_MINIMIZE, MF_BYCOMMAND|MF_GRAYED|MF_DISABLED);
// ......... drawing code here .............
// enable "Minimize" system menu item.
pSysMenu->EnableMenuItem(SC_MINIMIZE, MF_BYCOMMAND|MF_ENABLED);
// put back minimize box
ModifyStyle(0, WS_MINIMIZEBOX, SWP_FRAMECHANGED);
Using Windows API
// remove minimize box
LONG nStyle = ::GetWindowLong(hWnd, GWL_STYLE);
nStyle &= ~WS_MINIMIZEBOX;
::SetWindowLong(hWnd, GWL_STYLE, nStyle);
::SetWindowPos(hWnd, NULL, 0, 0, 0, 0,
SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_FRAMECHANGED);
// disable "Minimize" system menu item
HMENU hMenu = ::GetSystemMenu(hWnd, FALSE);
::EnableMenuItem(hMenu, SC_MINIMIZE, MF_BYCOMMAND|MF_GRAYED|MF_DISABLED);
// ......... drawing code here .............
// put back minimize box
nStyle = ::GetWindowLong(hWnd, GWL_STYLE);
nStyle |= WS_MINIMIZEBOX;
::SetWindowLong(hWnd, GWL_STYLE, nStyle);
::SetWindowPos(hWnd, NULL, 0, 0, 0, 0,
SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_FRAMECHANGED);
// enable "Minimize" system menu item
hMenu = ::GetSystemMenu(hWnd, FALSE);
::EnableMenuItem(hMenu, SC_MINIMIZE, MF_BYCOMMAND|MF_ENABLED);
A last one: simply remove WS_MINIMIZEBOX style and SC_MINIMIZE system menu item at all.