How to hide a window in TaskBar

13 01 2009




Sometimes we may want to hide an application or window while it’s minimizing or some other situations and need to show our application icon in the taskbar notification area or tray area  just like Messenger applications hide it to taskbar once it closed but the application is still running.





We could establish this by using the NOTIFYICONDATA  and Shell_NotifyIcon functions. The NOTIFYICONDATA   structure contains information that the system needs to process taskbar status area messages and the Shell_NotifyIcon function sends a message to the system to add, modify, or delete an icon from the taskbar status area. Please check these functions in the MSDN to get more information about the parameters.




Please check the code sample, which hide the application icon to tray area once it minimize and it will popup a menu when we right click on it. 

header file

afx_msg void OnMaximizeApp();
afx_msg void OnAbout();
afx_msg void OnExit();

Implementation file

ON_COMMAND(WM_USER+1,  OnMaximizeApp)
void CMyDialog::OnSize(UINT nType, int cx, int cy)
   CDialog::OnSize(nType, cx, cy);
   //track the window minimizing message
   if(nType == SIZE_MINIMIZED)
      niData.cbSize = sizeof(niData);
      niData.hWnd   = this->m_hWnd;
      niData.uID    = 100;
      niData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
      //u could load ur own icon here
      niData.hIcon  = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
      //set the CALLBACK message ID
      niData.uCallbackMessage =  WM_USER + 200; 
      //Adds our App. icon to the taskbar status area
      Shell_NotifyIcon( NIM_ADD, &niData);     
      //hide our application/window
LRESULT CMyDialog::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
   //if  the message is from our application
   //which is hiding in the tray area
   if( message == (WM_USER + 200) )
      //trace the right mouse click msg
      if(lParam == WM_RBUTTONDOWN)
         CMenu myMenu;
         POINT pt;
         //Get the current cursor point
         //add menu items
         myMenu.AppendMenu( MF_POPUP, WM_USER + 1, _T("Maximize App.") );
         myMenu.AppendMenu( MF_POPUP, WM_USER + 2, _T("About.") );
         myMenu.AppendMenu( MF_POPUP, WM_USER + 3, _T("Exit") );
         myMenu.TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON,pt.x,pt.y,this );
   return CDialog::WindowProc(message, wParam, lParam);
void CMyDialog::OnAbout()
   //Add code here
void CMyDialog::OnMaximizeApp()
void CMyDialog::OnExit()





You can keep your application compatible with all Shell32.dll version by checking the dll version installed on your machine by the function DllGetVersion.




7 responses

10 02 2010
Carlos Olmedo

Your code is working fine for me but.. do you know how to make a CDialog hidden at startup? I’m searching on google and none of the tips i found works for me.


11 02 2010
Sanoop S P

Do you want to run your application at system startup and then it hide?

1 07 2011

Nice post. Helped me solve my task.

One little remark:
line 19: niData.hWnd = this->m_hWnd;
“this” may be omitted =)

1 07 2011
Sanoop S P

Thanks a lot for your comment 🙂

5 10 2011
top criminal attorneys wv

This could be this blog’s best writing on the web

13 10 2011
hotel charme provence

This definitely makes great sense

11 02 2012
How to prevent desktop from locking « C++ and VC++ Tips

[…] you want to hide this sample application to taskbar please see one of the oldest post. Rate this: Like this:LikeBe the first to like this […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: