Re: Starting SDI application as invisible
"Lubo" <Lubo@discussions.microsoft.com> wrote in message
news:DF9546FD-F27E-450A-A15A-8419B41D1D41@microsoft.com...
I need to start an VS 2008 MFC feature pack application (Vstudio like,SDI )
as invisible and to show\hide it only as a reaction to user mouse action
over
its the system tray icon.
I tried to experiment with different wnd styles and overriding some
virtual
functions but it seems that there are a lot of code called from
OnFileNew()
and its descendants that still shows it.
The simplest thing is to move the code that construct the CMainFrame, the
CDocument, etc. out of CWinApp::InitInstance() and into the code which
handles the tray icon menu item to show the window.
In CWinApp::InitIntance(), construct a simple CWnd derived class (with a
WS_POPUP flag, but no WS_VISIBLE flag so it is hidden) that owns the tray
icon, and set CWinApp::m_pMainWnd to that. Then MFC won't make any window
visible, and yet your tray icon is put there.
In addition, if you don't need Doc/View, you can do something like this - it
bypasses the OnFileNew stuff and just creates the frame where you have more
control over its visibility.
CMainFrame* pFrame = new CMainFrame;
m_pMainWnd = pFrame;
// create and load the frame with its resources
BOOL bFrameCreated = pFrame->LoadFrame(IDR_MAINFRAME,
WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL,
NULL);
if ( bFrameCreated )
{
CString CmdLine = m_lpCmdLine;
CmdLine.MakeUpper();
BOOL bTrayOnly = ( CmdLine.Find("-AUTOSTART") > -1 );
// Load window position from profile
CWindowPlacement wp; // google "CWindowPlacement", this is by Paul
di Lascia
if ( !wp.Restore( _T("WindowPos"), pFrame, (bTrayOnly) ? SW_HIDE :
0xFFFFFFFF) )
pFrame->ShowWindow ( m_nCmdShow );
pFrame->UpdateWindow();
-- David