4
votes

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.

2
For IsIconic you could try checking the window styles (via GetWindowLong) and see if WS_MINIMIZE is set. For OpenIcon you could try posting a WM_SYSCOMMAND message with SC_RESTORE.Jonathan Potter
I tried SendMessage(hWnd,WM_SYSCOMMAND,SC_RESTORE,NULL) but same as before, nothing happened.Max Kielland
Not a real answer for you but a quick test discovered that IsIconic returns true (in a WM_PAINT for me) if you are not using Windows Explorer Taskbar. Kill all explorer instances so that minimizing a windows will show its minmimal frame and IsIconic() will return true if your Window was registered with a NULL icon (in RegisterClass)ChristianWimmer

2 Answers

0
votes

Without knowing anything about the external app in question, my guess is that the window you are manipulating is not the actual window being minimized to the Taskbar, which would account for why IsIconic() is always false but IsWindowVisible() varies.

It is not uncommon, especially in legacy apps written before Vista, or apps using older versions of frameworks like Borland's VCL before they were updated to support Vista, to have a top-level hidden window that owns other windows in the same app, especially the main window. One reason (amongst others) is to group multiple windows on the same Taskbar button, before Microsoft created APIs to control that.

In such an app, when the "main" window is "minimized", the app would intercept that action, hide the "main" window, and minimize the owner window instead. When the "main" window is "restored", the app would restore the owner window and then show the "main" window.

Try checking if GetWindow(MyHWND, GW_OWNER) returns an HWND and if so then check what IsIconic() says about it.

Vista made some dramatic changes to how apps interact with the Taskbar and Alt+Tab dialog. Some coding techniques and assumptions that had been true and working fine since Win95 no longer worked correctly in Vista onwards. Some apps and frameworks adapted to the changes, some did not.

0
votes

Had similar issue in Windows 7 Pro. 32-bit.

IsIconic() function is from user32.dll.

IsIconic function correctly working once copied below files to current folder. user32.dll, advapi32.dll, gdi32.dll, kernel32.dll, ntdll.dll

Note: These dependencies can be find usnig DEPENDS.EXE in VC 6.0 ++. Also these files copied from Windows 7 64-bit pc (IsIconic is working fine in this pc).

May be windows update is not installed on Windows 7 32-bit pc.