Tray icon (taskbar) questions

This is a discussion on Tray icon (taskbar) questions within the Windows Programming forums, part of the Platform Specific Boards category; I've already searched the forums and google. Found something useful: http://cboard.cprogramming.com/showt...highlight=tray But the balloon tip thing is not working... Also ...

  1. #1
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318

    Tray icon (taskbar) questions

    I've already searched the forums and google.
    Found something useful: System Tray

    But the balloon tip thing is not working...
    Also I would like to add menu to my tray icon (I've found some samples but they're all buggy, they don't disappear when I press somewhere else on the screen).
    Here's the code:
    Code:
    #include <windows.h>
    #include "main.h"
    
    /*  Make the class name into a global variable  */
    int WINAPI WinMain (HINSTANCE hThisInstance,
    					HINSTANCE hPrevInstance,
    					LPSTR lpszArgument,
    					int nFunsterStil)
    
    {
    	MSG messages;			/* Here messages to the application are saved */
    	WNDCLASSEX wincl;		/* Data structure for the windowclass */
    
    	/* The Window structure */
    	wincl.hInstance = hThisInstance;
    	wincl.lpszClassName = szClassName;
    	wincl.lpfnWndProc = WindowProcedure;	  /* This function is called by windows */
    	wincl.style = CS_DBLCLKS;				 /* Catch double-clicks */
    	wincl.cbSize = sizeof (WNDCLASSEX);
    
    	/* Use default icon and mouse-pointer */
    	wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    	wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    	wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    	wincl.lpszMenuName = NULL;				 /* No menu */
    	wincl.cbClsExtra = 0;					  /* No extra bytes after the window class */
    	wincl.cbWndExtra = 0;					  /* structure or the window instance */
    	/* Use Windows's default color as the background of the window */
    	wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
    
    	/* Register the window class, and if it fails quit the program */
    	if (!RegisterClassEx (&wincl))
    		return 0;
    
    	/* The class is registered, let's create the program*/
    	hwnd = CreateWindowEx (
    		   0,				   /* Extended possibilites for variation */
    		   szClassName,		 /* Classname */
    		   "Windows App",	   /* Title Text */
    		   WS_OVERLAPPEDWINDOW, /* default window */
    		   CW_USEDEFAULT,	   /* Windows decides the position */
    		   CW_USEDEFAULT,	   /* where the window ends up on the screen */
    		   544,				 /* The programs width */
    		   375,				 /* and height in pixels */
    		   HWND_DESKTOP,		/* The window is a child-window to desktop */
    		   NULL,				/* No menu */
    		   hThisInstance,	   /* Program Instance handler */
    		   NULL				 /* No Window Creation data */
    		   );
    
    	/* Make the window visible on the screen */
    	ShowWindow (hwnd, nFunsterStil);
    	MinimizeToTray();
    
    	/* Run the message loop. It will run until GetMessage() returns 0 */
    	while (GetMessage (&messages, NULL, 0, 0))
    	{
    		/* Translate virtual-key messages into character messages */
    		TranslateMessage(&messages);
    		/* Send message to WindowProcedure */
    		DispatchMessage(&messages);
    	}
    
    	/* The program return-value is 0 - The value that PostQuitMessage() gave */
    	return messages.wParam;
    }
    
    
    /*  This function is called by the Windows function DispatchMessage()  */
    
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	static NOTIFYICONDATA NData;
    	/*POINT pt;
    	HMENU hPopupMenu = CreatePopupMenu();
    	AppendMenu(hPopupMenu, MF_STRING, 1000, "Restore");
    	AppendMenu(hPopupMenu, MF_STRING, 1001, "Minimize");
    	AppendMenu(hPopupMenu, MF_STRING, 1002, "Close Program");*/
    	switch (message)				  /* handle the messages */
    	{
    		case WM_CREATE:
    			break;
    		case WM_SIZE:{
    			switch (LOWORD(wParam)){
    				case SIZE_MINIMIZED:{
    					ShowWindow(hwnd,SW_HIDE);
    					break;
    				}
    				default:
    					break;
    			}
    			break;
    		}
    		case WM_USER_SHELLNOTIFY:{
    			if (wParam == ID_TRAYICON){
    				UINT uMouseMsg = (UINT) lParam;	
    				switch (uMouseMsg){
    					case WM_LBUTTONDBLCLK:
    						RestoreFromTray();
    						EditBalloonText(hwnd,ID_TRAYICON,"Fofa","Cofa",10000,NIIF_INFO);
    						break;
    					/*case WM_MBUTTONDOWN:
    						GetCursorPos(&pt);
    						TrackPopupMenu(hPopupMenu, TPM_RIGHTALIGN, pt.x, pt.y, 0, hwnd, NULL);
    						break;*/
    					default: 
    						break;
    				}
    			}
    			return 0;}
    		case WM_DESTROY:
    			DeleteTrayIcon();
    			PostQuitMessage (0);	   /* send a WM_QUIT to the message queue */
    			break;
    		default:					  /* for messages that we don't deal with */
    			return DefWindowProc (hwnd, message, wParam, lParam);
    	}
    	return 0;
    }
    
    void MinimizeToTray(void){
    	NOTIFYICONDATA nid;
    	TCHAR tooltip[] = TEXT("Tray Icon");
    
    	nid.cbSize = sizeof(NOTIFYICONDATA);
    	nid.hWnd = hwnd;
    	nid.uID = ID_TRAYICON;
    	nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
    	nid.uCallbackMessage = WM_USER_SHELLNOTIFY;
    	nid.szInfo;
    	nid.hIcon = LoadIcon(GetModuleHandle(NULL), (const char*)IDI_ICON1);
    	lstrcpyn(nid.szTip, tooltip, sizeof(tooltip));
    	
    	Shell_NotifyIcon(NIM_ADD, &nid);   // add our icon to the system tray
    }
    
    void DeleteTrayIcon(void){
    	NOTIFYICONDATA nid;
    	nid.cbSize = sizeof(NOTIFYICONDATA);
    	nid.hWnd = hwnd;
    	nid.uID = ID_TRAYICON;
    	Shell_NotifyIcon(NIM_DELETE, &nid);  // remove tray icon when restored
    }
    
    void RestoreFromTray(void){
    	ShowWindow(hwnd, SW_RESTORE);	  // unhide main window
    	SetForegroundWindow(hwnd);		 // bring main window to foreground
    }
    
    BOOL EditBalloonText(HWND hwnd,UINT uID,PTSTR szBalloonTitle,PTSTR szBalloonMsg,UINT nTimeOut,DWORD messageType){
    	NOTIFYICONDATA tnid;
    	tnid.cbSize = sizeof(NOTIFYICONDATA);
    	tnid.hWnd = hwnd;
    	tnid.uID = uID;
    	tnid.uFlags = NIF_INFO;
    	if (szBalloonMsg){
    		strncpy(tnid.szInfo, szBalloonMsg, sizeof(tnid.szInfo));
    	}
    	else{
    		tnid.szInfo[0] = 0;
    	}
    	tnid.uTimeout=nTimeOut;
    	strcpy(tnid.szInfoTitle,szBalloonTitle);
    	tnid.dwInfoFlags=messageType;
    
    	return Shell_NotifyIcon(NIM_MODIFY, &tnid);
    }
    And I would like to add a checkbox to my tray icon menu.

    Edit: The balloon tip is working! WM_LBUTTONDBLCLK is double click and i tried to do this with single click...
    Last edited by maxorator; 09-25-2006 at 07:18 AM.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  2. #2
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Today I found some better tutorials from google by including some important functions in the search query. Otherwise I got pages and pages of MFC samples.

    It seems that the menu used there is quite the same than all the other menus, so I'm going to search for adding the checkbox in front of it. If anyone knows any good samples, please give me the link.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  3. #3
    Registered User
    Join Date
    Sep 2006
    Location
    USA
    Posts
    1
    To early.

  4. #4
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    I feel kinda stupid right now.

    I googled about this for some time. Then I posted this thread. And AFTER I posted this thread, I found these things. Why does it always have to happen to me?
    "The Internet treats censorship as damage and routes around it." - John Gilmore

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Popup taskbar icon
    By CondorMan in forum Windows Programming
    Replies: 5
    Last Post: 06-11-2006, 11:14 AM
  2. Problem with taskbar icon
    By maxorator in forum Windows Programming
    Replies: 2
    Last Post: 05-16-2006, 02:55 AM
  3. GTK+ Gnome desktop system tray app problem
    By BobS0327 in forum Linux Programming
    Replies: 2
    Last Post: 04-01-2006, 09:54 PM
  4. Problem with an icon in the TaskBar status area
    By dit6a9 in forum Windows Programming
    Replies: 2
    Last Post: 08-16-2004, 11:33 PM
  5. Hiding Another Progs System Tray Icon
    By (TNT) in forum Windows Programming
    Replies: 2
    Last Post: 04-29-2002, 02:20 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21