Valhalla Legends Forums Archive | C/C++ Programming | Console Application -> Minimize to System Tray?

AuthorMessageTime
Sargera
Is this possible?
July 21, 2004, 7:49 PM
Spht
[quote author=Sargera link=board=30;threadid=7801;start=0#msg71707 date=1090439370]
Is this possible?
[/quote]

Yes. Very similar to how you'd do it for a non-console window.
July 21, 2004, 8:57 PM
Sargera
Do you have a link?
July 21, 2004, 9:59 PM
UserLoser.
Look into this.
July 21, 2004, 11:41 PM
LordVader
[quote author=Sargera link=board=30;threadid=7801;start=0#msg71729 date=1090447196]
Do you have a link?
[/quote]

I use this class for systray stuff:
http://www.codeproject.com/shell/ss_trayicon.asp

To use it in a non MFC project do:
[code]
//This is a global Variable:
SS_TrayIcon* m_pTrayIcon;
LRESULT CALLBACK OnMouseRightClickTI(WPARAM wParam, LPARAM lParam)
{
   m_pTrayIcon->ShowMenuAtMouse(IDR_TRAYMENU, hMainWnd);// --- hMainWnd is the dialog/window pointer, and IDR_TRAYMENU is a menu resource to show.
return 0;
}

void AddTaskbarIcons()
{
   m_pTrayIcon = new SS_TrayIcon( hWndInst, 1, 1 );
   m_pTrayIcon->LoadIcon( 0, 0, IDI_MAIN_ICON ); // ---- point to a icon resource
   m_pTrayIcon->ShowIcon( 0 );
   m_pTrayIcon->ToolTip( 0, _T("Some Text") );   
   m_pTrayIcon->MapMessageToFunction(WM_RBUTTONDOWN, ::OnMouseRightClickTI); // ---- Display a menu on right click jumps to the functions above.
}
[/code]

Then in your callback for the main window or dialog being created it needs to be fired up:
[code]
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{

   static UINT s_uTaskbarRestart; // ---- declare a new msg see below
switch(uMsg)
{
      case WM_CREATE:
         hMainWnd = hwnd;
         // ---- Init msg to windows so we can replace systray icon if explorer crashes
         s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));

         // ---- Add the systray icons using a offloaded function
         AddTaskbarIcons();

         // ---- Add a Status area to the main window
         //hStatusWnd = CreateWindowEx(0, STATUSCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP, 0, 0, 0, 0,hwnd, (HMENU)IDC_MAIN_STATUS, GetModuleHandle(NULL), NULL);
         //SendMessage(hStatusWnd, SB_SETTEXT, 0, (LPARAM)" Status - Disconnected");
         break;
/**rest of your cases, then give a default**/
default:
         if(uMsg == s_uTaskbarRestart){
// ---- This will fire "IF" explorer crashes, as noted from Skywings reference in the documents.
            AddTaskbarIcons();
         }
   }
   return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
[/code]

*Note this example is a window NOT a dialog or console slight adjustments needed dialog doesn't "Create" it uses WM_INIT etc. figure it out for a console should be easy ;D.

Edit: Also need to add the SS_Trayicon.cpp/.h and SS_Wnd.cpp/h files to your project workspace.

Alot of ppl need to read that or figure it out from Skywings reference on how to replace icons when explorer crashes *Pokes DM and half the other bot developer's out there* who's icons vanish if explorer goes poof.
I'm just picky tho heh.

Come to think of it Stealthbot is the only Bot I've used that wont loose it's icon in systray (if present) so hey..
September 2, 2004, 1:19 PM

Search