0

In CWinApp::InitInstance() I have:

if (!ProcessShellCommand(cmdInfo))
  return FALSE;
m_pMainWnd->ShowWindow(m_MinimizeOnStartup ? SW_SHOWMINIMIZED : SW_SHOWNORMAL);
m_pMainWnd->UpdateWindow();

But my ShowWindow call is not resulting in an OnSize() or OnShowWindow() callback? During the ProcessShellCommand() those are called a few times as the first OnShowWindow() restores the window size when last shutdown via SetWindowPlacement(). That all works good, restoring to last state, but ProcessShellCommand() afterwards calls ShowWindow with SW_SHOW which causes a my hidden when minimized window to show on the taskbar. Where is the proper place to either show the window or minimize it (to hide it). Basically what happens is the minimize comes in (on SetWindowPlacement(), window is hidden, MFC later calls SW_SHOW which makes it minimized on the taskbar instead of hidden, my forced ShowWindow() doesn't do anything.

TIA!!

Werner Henze
  • 16,404
  • 12
  • 44
  • 69
df234987
  • 513
  • 2
  • 13
  • So it appears when already minimized it doesn't send it if request minimize. – df234987 Feb 19 '20 at 05:37
  • In Win32 C++ application, I can receive [`WM_SIZE`](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-size) message even if I set `SW_SHOWMINIMIZED` via [`ShowWindow`](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow)function after the window create like this: `ShowWindow(hWnd, SW_SHOWMINIMIZED);` But you can't receive corresponding [`OnSize`](https://learn.microsoft.com/en-us/cpp/mfc/reference/cwnd-class?view=vs-2019#onsize) call of MFC, is this your issue right? – Rita Han Feb 19 '20 at 07:37
  • yes, there was no OnSize nor OnShowWindow when it was already in that state. I found I could set `m_nCmdShow=SW_HIDE` in the `CAppWnd` and then later I would do the `SetWindowPlacement()` and let it do its thing. However, that function sends a `SIZE_RESTORED` prior to `SIZE_MINIMIZED` when using `wp->showCmd=SW_SHOWMINIMIZED;` so you get a flash of the window before it goes away (since my OnSize will `ShowWindow(SW_SHOW)` on `SIZE_RESTORED` if hidden). Not sure if a trick to get around that? – df234987 Feb 19 '20 at 07:58
  • I took out my `ShowWindow(SW_SHOW)` on `SIZE_RESTORED` when not visible and it still ended up showing the window and now without the flash. So I'm good now! – df234987 Feb 19 '20 at 08:03
  • If the issue solved you can post an answer and accept it. – Rita Han Feb 19 '20 at 09:04

1 Answers1

0

There is no OnSize() nor OnShowWindow() callback on ShowWindow() when already in those states. Set m_nCmdShow=SW_HIDE in CAppWnd then at the end of the InitInstance() call the SetWindowPlacement()

df234987
  • 513
  • 2
  • 13