Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by whitelisting our website.

Hide, minimize or maximize your CFrameWndEx based window at start (MFC 10.0 tip)

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.

%d bloggers like this: