Windows CE

Saturday, April 11, 2009

Minimize / Hide Applications on startup

Hi Guys..
 In my last post I discussed about how to Add an MFC application into tray Icon. The sample application can be Minimized to tray icon, without even shown in task bar when HIDE menu Item is clicked. And again can be relaunched when SHOW menu in tray icon is clicked.
 But one problem is there. We can not start the Sample MFC application as a tray icon from the  startup.Even a call to  ShowWindow(SW_HIDE) from the  OnInitDialog() function, will not work.
Well here is a trick of doing this, by modifying the initinstance() function of the App class.
The Normal code for creating the dialog in InitInstance() looks like

CDialogBasedDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();


Edit this code as follows :

CDialogBasedDlg dlg;
if(dlg.Create( CDialogBasedDlg::IDD ))
 {
dlg.ShowWindow( SW_HIDE );
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.RunModalLoop();
}
And you are done.. Integrating it with previous sample application will result in a Dialog based application starting as a trayicon, Always Minimized and will not appear in System tray. ;))