[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


Make Window invisible

Posted on 2001-06-06
Medium Priority
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)
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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 200 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


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

650 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