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
{
//(...)
public:
BOOL bIsHidden;
//(...)
};
Then in the MainFrm.cpp
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
bIsHidden = TRUE;
}
//This is where you block the window for showing
void CMainFrame::OnWindowPosChanging(WINDOWPOS* lpwndpos)
{
CFrameWndEx::OnWindowPosChanging(lpwndpos);
//When hidden we remove all the showwindow parameters (giving you the power back)
if(bIsHidden)
lpwndpos->flags &= ~SWP_SHOWWINDOW ;
}
Finally in your CWinAppEx derivated class
BOOL CAcrobatMDIishApp::InitInstance()
{
//(...)
pFrame->LoadFrame(IDR_MAINFRAME,
WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL,
NULL);
// 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)
pFrame->UpdateWindow();
}
It is a simple way to control the visibilty of “SDI”/”MDI” application based on the CFrameWndEx and CWinAppEx classes.