Platform: Windows 7 64bit.
First of, the Windows API IsIconic() always return false. Doesn't matter if the window is maximized, normal or minimized (where IsIconic()
should return true).
The window belongs to another process and has been retrieved with enumWindows()
Here is a small excerpt from my test code.
TCHAR WndCaption[100];
TCHAR NewCaption[] = TEXT("My Window handle is valid");
BOOL res;
GetWindowText(MyHWND,WndCaption,100);
SetWindowText(MyHWND,NewCaption);
// This always return 0, no matter what state the window is in.
res = IsIconic(MyHWND);
if(res) {
...
}
I know the window handle is valid because I can get and set the window's caption text. The Is Iconic()
function however always return 0 (false) even when the window has been minimized.
But if we change the IsIconic()
to IsWindowVisible()
it reports correctly false when the window is minimized and true when it is maximized or normal.
TCHAR WndCaption[100];
TCHAR NewCaption[] = TEXT("My Window handle is valid");
BOOL res;
GetWindowText(MyHWND,WndCaption,100);
SetWindowText(MyHWND,NewCaption);
// This works correctly.
res = IsWindowVisible(MyHWND);
if(!res) {
// This always fail
OpenIcon(MyHWND);
}
So now when I can detect the window being minimized I want to restore it. IsIconic's counterpart OpenIcon() does nothing. It returns true, telling that the operation was successful, but the window is still minimized. In fact, it always return true no matter what state the window is in.
So lets try the old fashion way.
TCHAR WndCaption[100];
TCHAR NewCaption[] = TEXT("My Window handle is valid");
BOOL res;
GetWindowText(MyHWND,WndCaption,100);
SetWindowText(MyHWND,NewCaption);
// Only works if the window wasn't minimized by clicking the minimize button
res = ShowWindow(MyHWND,SW_MINIMIZE);
res = ShowWindow(MyHWND,SW_NORMAL);
res = ShowWindow(MyHWND,SW_MAXIMIZE);
If the window is in the normal or maximized state it will first minimize it, restores it back again and then maximize it. But if I run the program when the window has been minimized by clicking the minimize button, nothing happens. It doesn't restore it or maximize it.
It feels like the window becomes unresponsive if I minimize it by clicking the minimize button. After hours of searching I have only found posts with similar problems but no solutions.
Can some one please help me to figure out how to restore a window (owned by another process) after it has been minimized by the minimize button.
IsIconic
you could try checking the window styles (viaGetWindowLong
) and see ifWS_MINIMIZE
is set. ForOpenIcon
you could try posting aWM_SYSCOMMAND
message withSC_RESTORE
. – Jonathan PotterSendMessage(hWnd,WM_SYSCOMMAND,SC_RESTORE,NULL)
but same as before, nothing happened. – Max Kielland