0
votes

I made a little exe giving me the state of a window and maximize it when minimized. It works with regular application like Calculator. But it does not work with the application I need to maximize. The application is minimized in the task bar, it is a full screen application displaying images in a dual screen setup.

IsIconic work on Calculator but return false on the application.

IsWindowVisible return false, but ShowWindow is not working but if the command is reruned IsWindowVisible return true.

If I use nircmd.exe the command nircmd win max title "App name" The application return fullscreen on the two screen.

tried PostMessage with SC_RESTORE or SC_MAXIMIZE to no avail

Here's the code

HWND hWnd = FindWindow(NULL, "Application name"); 
if (IsWindow(hWnd)) 
{
    SetForegroundWindow(hWnd); // I'll give focus to my window. This is always working.
    std::cout << "Visible " << IsWindowVisible(hWnd) << std::endl;

 if(!IsWindowVisible(hWnd))
    {
        std::cout << "Maximized " << std::endl;
     ShowWindow(hWnd, SW_MAXIMIZE); // This is working only if the window is minimized while in fullscreen mode
     //PostMessage(hWnd, WM_SYSCOMMAND, SC_RESTORE, 0);
    }
}
1
Maybe the app in question is simply ignoring that message? - Bartek Banachewicz
but nircmd.exe succed to restore the widows so there must be a way. - Régis

1 Answers

0
votes
HWND hWnd = FindWindow(NULL, "Application name"); 

RECT rect;
// initial rect to your desired size
int width = rect.right - rect.left;
int height =rect.bottom - rect.top;

::MoveWindow(hWnd,rect.left,rect.top,width,height,TRUE);
::BringWindowToTop(hWnd);
FromHandle(hWnd)->ShowWindow(TRUE);
FromHandle(hWnd)->SetWindowPos(&CWnd::wndTopMost,rect.left,rect.top,width,height,SWP_FRAMECHANGED |SWP_SHOWWINDOW  );`