Make Window invisible

Posted on 2001-06-06
Last Modified: 2013-11-20
I want to create a program that when executed, the dialog box does not appear.  I unchecked the visible box in the propeties, but it is still visible.

Question by:Brez
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1

Expert Comment

ID: 6160972
how are you creating the dialog? Are you calling ShowWindow() or DoModal()?
LVL 32

Expert Comment

ID: 6160980
If you call ShowWindow(SW_HIDE) it will be invisible.

Expert Comment

ID: 6161236
Go into the dialogs initdialog function and call ShowWindow(SW_HIDE)
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 32

Expert Comment

ID: 6161252
Gosh there is a nasty echo on this question.....


Author Comment

ID: 6161539
I used the wizard to create a dialog based application. What I want is to make the default dialog box invisible upon startup.  I only want to see an icon in the Status Area of the taskbar.  Only after clicking on the icon do I want the dialog box to appear.  ShowWindow(SW_HIDE) is no good because the application still appears in the taskbar. I tried to use ShowWindow(FALSE) in the Initdialog, but it will not become invisible.  If I call ShowWindow(FALSE) after the Initdialog is complete, then the window will become invisible. I hope this make sense.

Accepted Solution

Dak_Programmer earned 50 total points
ID: 6161557
MFC dialog-based apps default to using a modal dialog, which causes problems if your application requires to be invisible. This situation most commonly occurs when developing applications which place icons in the system tray, and therefore need their main dialog to be invisible until the user interacts with the icon. You can make a modeless dialog version of your app as follows :

  Make your dialog resource invisible using the styles tab in the dialog properties.
  Remove all the DoModal gunk from your InitInstance, so you end up with something like this :
  BOOL CMyApp::InitInstance()
   #ifdef _AFXDLL
    Enable3dControls(); // using MFC in a shared DLL
    Enable3dControlsStatic();    // linking to MFC statically

   m_pMainWnd = new CMyModelessDlg;

   if (m_pMainWnd)
      return TRUE;
      return FALSE;
  I place the call to Create (...) in my dialog constructor and make it public. Other people organise things differently but it works for me... curse the OOP thought police <g> :
  CMyModelessDlg::CMyModelessDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CMyModelessDlg::IDD, pParent)
   m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

   Create (IDD, pParent); // Create modeless dialog.
  You will need to handle PostNcDestroy and delete the dialog object yourself (ClassWizard can set up the handler for you) :
  void CMyModelessDlg::PostNcDestroy()
   delete this;
  You may find that if you call DestroyWindow from within your dialog in order to shut down, you will have to call your own PostNcDestroy in order to avoid a leak. Watch the debug output from your app running in debug mode - if this is the case MFC will helpfully give you a warning there. Here's the normal WM_CLOSE handler:
void CMyModelessDlg::OnClose()
   if (m_bOkToClose)
      CleanUp ();
      DestroyWindow ();
      ShowWindow (SW_HIDE);

I use the m_bOkToClose flag to distinguish when I'm permitting the user to close down and when I want that action to simply hide the window. Cleanup is a function that does any necessary CloseHandles, removes any tray icons and deletes any allocated memory.

Now you have a dialog based application that can be shown or hidden as necessary.


Expert Comment

ID: 6161576
. How do I put an icon in the system tray ?

 This loads the systray icon, giving it an ID because I have more than one
tray icon. The private message is also specified.

void CMainFrame::AddMyIcon (void)
   CString csTip ;

   tnid.cbSize = sizeof(NOTIFYICONDATA);
   tnid.hWnd = GetSafeHwnd();
   tnid.uID = SYSTRAY_QUICK_ID; // personal ID
   tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
   tnid.uCallbackMessage = PRIV_SYSTRAY_ICON;
   tnid.hIcon = m_hIconPhone ;

   if (csTip.LoadString (IDS_QUICKMENU))
      strncpy (tnid.szTip, csTip, sizeof(tnid.szTip));
      tnid.szTip[0] = '\0';

   Shell_NotifyIcon(NIM_ADD, &tnid);

 This appears in the mainframe message map, and specifies a message sent when the user
interacts with the icon. Note that the message ID matches that specified in the uCallbackMessage
structure member.


 This handles the click message declared above.

afx_msg LONG CMainFrame::OnSysTrayIconClick (WPARAM wParam, LPARAM lParam)
   switch (wParam)
      // bunch of other code omitted here. Note that the
      // ID here matches that specified when the icon
      // was inserted, in the uID structure member.

      case SYSTRAY_QUICK_ID:

           switch (lParam)
              case WM_LBUTTONDOWN:
              case WM_RBUTTONDOWN:
                   ShowQuickMenu ();
                   break ;
           break ;

           DebugMessage ("......");
           break ;

   return TRUE ;

 This shows the menu for the systray icon. The popup menu is loaded elsewhere (and it MUST be a popup, or you'll get a bizarre minimal-width empty menu appearing). You can create a single bar menu with several popups, and use GetSubMenu to choose the one you want for any particular circumstance.

void CMainFrame::ShowQuickMenu ()
   POINT CurPos ;

   GetCursorPos (&CurPos);
   SetForegroundWindow ();// Bodge to get around bug in Explorer

   // Display the menu. This menu is a popup loaded elsewhere.

   TrackPopupMenu (m_hQuickMenu,

   PostMessage (WM_NULL, 0, 0);// Bodge to get around bug in Explorer


Author Comment

ID: 6161968
Thanks you very much.  That was just what I was looking for.

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Expand LInux Boot partition remotly 3 102
deburging in oracle form 12 112
Whole sheet autoscrub still needed 19 54
Change owner from userA to server Local Administrators 7 71
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question