Aug 132011

After changing to Visual Studio 2010 many of my old ways of doing things didn’t work well anymore.

Recently I had a “SDI” (not really SDI since it doesn’t use the Doc/View way) that needed to be minimized @ startup.
My good old way used the ActivateFrame(int nCmdShow) and setting to SW_HIDE / SW_MINIMIZE / SW_MAXIMIZE didn’t work at all.
(The “SDI” uses the new visual styles, so I guess we don’t have full control over the ShowWindow() being called)

First in your MainFrm.h file, add this:

class CMainFrame : public CFrameWndEx
BOOL bIsHidden;

Then in the MainFrm.cpp

// CMainFrame construction/destruction
// TODO: add member initialization code here
bIsHidden = TRUE;

//This is where you block the window for showing
void CMainFrame::OnWindowPosChanging(WINDOWPOS* lpwndpos)

//When hidden we remove all the showwindow parameters (giving you the power back)
lpwndpos->flags &= ~SWP_SHOWWINDOW ;

Finally in your CWinAppEx derivated class

BOOL CAcrobatMDIishApp::InitInstance()

// The one and only window has been initialized, minimize it (or maximize it).
pFrame->ShowWindow(SW_MINIMIZE); //Comment these two out to keep the windows hidden (like a hide to systray function for instance)

It is a simple way to control the visibilty of “SDI”/”MDI” application based on the CFrameWndEx and CWinAppEx classes.

 Posted by at 22:27:14

  2 Responses to “Hide, minimize or maximize your CFrameWndEx based window at start (MFC 10.0 tip)”

  1. I have tried all that you have wrote above, but there is a flicker in taskbar … on Windows 10 64bit …

    • Hmm, I have tested it on a Win10 64-bit and it works. Could you try using the spy++ and see if any other messages are messing things up for you?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: