GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 27-Mar-2006, 21:53
abhisekjana abhisekjana is offline
New Member
 
Join Date: Mar 2006
Posts: 1
abhisekjana is on a distinguished road

How to minimize window in to system tray using WIN32


Hi,

I want help regarding, how to minimize window to system tray using Win32. Anyone please help me with some sample code.
  #2  
Old 03-Apr-2006, 09:29
mithunjacob's Avatar
mithunjacob mithunjacob is offline
Junior Member
 
Join Date: Jun 2004
Location: Vellore, India
Posts: 65
mithunjacob will become famous soon enough

Re: How to minimize window in to system tray using WIN32


Firstly you need the CFrameWnd* pointer to the frame (window) of your application. If you want to minimize it from a DialogBox, pass the pointer to the DialogBox's class while initializing it.

Once you've got the pointer, all you have to do is call the
ShowWindow(SW_SHOWMINIMIZED).

Therefore if you want to minimize from the frame itself, use:
this->ShowWindow(SW_SHOWMINIMIZED);
else use the pointer assigned to it.

If you want to minimize ANY window (assuming you have the handle) use:
ShowWindow(HWND hWnd, int ShowCmd)
__________________
[b]There are times when the Phantom walks the streets as an ordinary man...this is one of those times.
  #3  
Old 04-Apr-2006, 20:10
wkbjerry wkbjerry is offline
New Member
 
Join Date: Apr 2006
Posts: 8
wkbjerry is on a distinguished road

Re: How to minimize window in to system tray using WIN32


Follow the steps below:

Step 1:
Define a user message that will be used to handle the events happening on your app's system tray icon. For example:

CPP / C++ / C Code:
#define WM_MYMESSAGE (WM_USER + 1)

Step 2:
When you want to show your app icon in the system tray, call the win API Shell_NotifyIcon() some way like this:

CPP / C++ / C Code:
NOTIFYICONDATA tnd;
tnd.cbSize = sizeof(NOTIFYICONDATA);
tnd.hWnd = this->m_hWnd;
tnd.uID = IDR_MAINFRAME;
tnd.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
tnd.uCallbackMessage = WM_MYMESSAGE;
tnd.hIcon = LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME));
strcpy(tnd.szTip,"MyApp");
Shell_NotifyIcon(NIM_ADD,&tnd);

Explanation about Shell_NotifyIcon() and NOTIFYICONDATA structure can be found in MSDN. By now, your application's icon has appeared in the system tray. You may also change your window's style if necessary, ie. hiding the window.

Step 3:
The WM_MESSAGE handler looks somewhat like this:

CPP / C++ / C Code:
 UINT uID; // The icon ID sending the message
 UINT uMouseMsg; //Mouse event
 POINT pt;
 uID=(UINT) wParam;
 uMouseMsg=(UINT) lParam;
 if(uMouseMsg==WM_RBUTTONDOWN)
 {
  switch(uID)
  {
  case IDR_MAINFRAME: // Only handle the message sent by our app's tray icon
   GetCursorPos(&pt);// Get mouse's current position
   // AfxGetApp( )-> m_pMainWnd->ShowWindow(SW_SHOWNORMAL);
        // ...
   break;
   default:
  }
 }
 return;


Step4:
When you want to delete your tray icon, call Shell_NotifyIcon() again with NIM_DELETE parameter:

CPP / C++ / C Code:
NOTIFYICONDATA tnid;
tnid.cbSize=sizeof(NOTIFYICONDATA);
tnid.hWnd=this->m_hWnd;
tnid.uID=IDR_MAINFRAME;//Make sure to the icon to be deleted is of your app
Shell_NotifyIcon(NIM_DELETE,&tnid);

That's it! I hope it will be of any help.
 
 

Recent GIDBlogObservations of Iraq by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Fltk app in system tray? hcker2000 FLTK Forum 3 31-Jan-2006 01:29
How to minimize a application to the system tray? Thomas555 C++ Forum 12 20-May-2005 13:35
Win32 Window Shading behavior (like linux) WillyumYum C++ Forum 3 18-Apr-2005 14:36
#including resource file causing window procedure to be undeclared??? ubergeek C++ Forum 3 07-Feb-2005 14:39
Changing window start colour Rosdahale C++ Forum 5 19-Jan-2005 15:51

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 11:19.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.