TrayIcon



  • ich habe in mein Programm TrayIcon und Tooltips eingebaut dabei bin ich nach folgendem Beispiel vorgegangen

    http://www.codeproject.com/shell/LiviuBirjegaCode.asp

    dies funktioniert auch bestens habe dazu aber 2 fragen.
    icwürde gern zur Laufzeit das kleine icon im Tray bei statusänderungen austauschen genauso wie es bei antivir oder Jana-server auch gemacht wird (ich programmiere einen Server und wenn ich den stoppe möcht ich ein rotes icon darstellen

    und die Nächste frage betrifft infos wie man im tray ein Menü darstellen kann
    wenn man mit der rechten maustaste aufs icon clickt.



  • "Shell_NotifyIcon" mit "NIM_MODIFY" und "NIF_ICON" und dem hIcon in der NOTIFYICONDATA Struktur...



  • so hab das mal als funktion probiert hier der aufrauf

    ChangeTrayIcon( this, 
    		        WM_TRAY_NOTIFY, // user defined 
    				"SkippSerV - (gestoppt)",    
    				"SkippSerV - ist deaktiviert",  
    				"SkippSerV - (tool tip)",
    				10, //sec
    				theApp.LoadIcon( IDI_ICONSTOP) );
    
    		return;
    

    und hier der code

    void CWebServerDlg::ChangeTrayIcon( CWnd    *pWnd, 
    	  	                      UINT	  uCallbackMessage,
    				              CString sInfoTitle, // title for a balloon ToolTip.
    												  // This title appears in boldface above the text.
    												  // It can have a maximum of 63 characters
    				              CString sInfo, // the text for a balloon ToolTip, it can have
    							                 // a maximum of 255 characters
    				              CString sTip, // the text for a standard ToolTip. 
    											// It can have a maximum of 128 characters, 
    											// including the terminating NULL.
    			                  int     uTimeout, // in sec.
    				              HICON	  icon )
    {
    	//NOTIFYICONDATA contains information that the system needs to process taskbar status area messages
    
    	ZeroMemory( &_tnd, sizeof( NOTIFYICONDATA ) );
    
    	_tnd.cbSize		      = sizeof( NOTIFYICONDATA );
    	_tnd.hWnd			  = pWnd->GetSafeHwnd();
    	_tnd.uID			  = 0;
    
    	_tnd.uFlags		      = NIF_MESSAGE | NIF_ICON | NIF_TIP | NIF_INFO;
    			// Flag Description:
    			// - NIF_ICON	 The hIcon member is valid.  
    	        // - NIF_MESSAGE The uCallbackMessage member is valid. 
    	        // - NIF_TIP	 The szTip member is valid. 
    	        // - NIF_STATE	 The dwState and dwStateMask members are valid. 
    	        // - NIF_INFO	 Use a balloon ToolTip instead of a standard ToolTip. The szInfo, uTimeout, szInfoTitle, and dwInfoFlags members are valid. 
                // - NIF_GUID	 Reserved. 
    
    	_tnd.dwInfoFlags      = NIIF_INFO; // add an icon to a balloon ToolTip
    			// Flag Description 
    			// - NIIF_ERROR     An error icon. 
    			// - NIIF_INFO      An information icon. 
    			// - NIIF_NONE      No icon. 
    			// - NIIF_WARNING   A warning icon. 
    			// - NIIF_ICON_MASK Version 6.0. Reserved. 
    			// - NIIF_NOSOUND   Version 6.0. Do not play the associated sound. Applies only to balloon ToolTips 
    
    	_tnd.uCallbackMessage = uCallbackMessage;  
    	_tnd.uTimeout         = uTimeout * 1000;
    	_tnd.hIcon		   	  = icon;
    
    	strcpy( _tnd.szInfoTitle, sInfoTitle );
    	strcpy( _tnd.szInfo,      sInfo      );
    	strcpy( _tnd.szTip,       sTip       );
    
    	Shell_NotifyIcon( NIM_MODIFY, &_tnd ); // add to the taskbar's status area
    }
    

    aber es passiert nichts keine fehlermeldung



  • Du musst "uFlags" auf "NIF_ICON" setzen und "dwInfoFlags" auf 0 belassen!
    Hast Du auch das gleiche hWnd und ID angegeben?



  • hab einfach die funktion LoadToTray genommen und kopiert.( die funktion erstellt das icon



  • entschuldigung ich bin doch einfach nur Blöd hab übersehen das genau die Zeile vor dem Funktionsaufruf das schon wörtchen

    return;
    

    stand
    da konnte also auch nix funktionier egal was ich gemacht hätte 😃

    nun noch zu dem kontextmenü oder wie auch immer das heisst
    ich durchwühle zwar schon ein paar Beispielcodes dazu . aber so richtig verteh ich net was ich da machen muss

    das einzige was in irgendeiner form schon bei mir nen sinn ergibt und wo ich weiss was wo hin muss.

    Ich weiss das ich in nachfolgenderfunktion case WM_RBUTTONCLK:
    oder so ähnlich einfügen muss und irgendwas mit menü resource einfügen aber danach is ebbe

    LONG CWebServerDlg::OnTrayNotify( WPARAM wParam, LPARAM lParam )
    {
    	switch( lParam )
    	{
    	case WM_LBUTTONDBLCLK: //on double-click the left mouse button restore the dialog
    		_bVisible = TRUE;
    		this->ShowWindow( SW_RESTORE );
    		break;
    	}
    
    	return (0);
    }
    

    hier mal noch den Link zu dem Beispiel was mir am besten gefällt

    http://www.codeproject.com/shell/trayicons.asp



  • komm bei der sache nicht weiter so ich hab im rousourceneditor nen menü engefügt

    dannoch das abfangen ob rechtsklick der maustaste.
    aber dann keine ahnung wie ich dafür sorge das das menü unten bei der maus auftaucht.



  • So habs endlich hinbekommen. und da ja hier so zahlreiche Hinweise kamen die Zur Lösung führten *IRONIE*.

    hier mal der Code wie ichs gemacht habe:

    -erstmal ganz normal den Code eingebaut um nen Trayicon darzustellen
    -dann ne Menü Resource eingebaut

    dann hab ich folgenden code eingebaut

    LONG CWebServerDlg::OnTrayNotify( WPARAM wParam, LPARAM lParam )
    {
    	switch( lParam )
    	{
    	case WM_LBUTTONDBLCLK: //on double-click the left mouse button restore the dialog
    		_bVisible = TRUE;
    		this->ShowWindow( SW_RESTORE );
            BOOL SetForegroundWindow();// fenster in den Vordergrund stellen
    		break;
    
    	case WM_RBUTTONDOWN: //rechtsklick öffnet menü
    
            HMENU hMenu = ::LoadMenu(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDR_POPUP_MENU));
            if (!hMenu)
                return 0;
    
            HMENU hSubMenu = ::GetSubMenu(hMenu, 0);
            if (!hSubMenu)
    		{
                ::DestroyMenu(hMenu);        //alte menü vorher zerstören 
    			return 0;
    		}
    
            POINT pos;
            GetCursorPos(&pos);
    
    		::SetForegroundWindow(_tnd.hWnd);  
            ::TrackPopupMenu(hSubMenu, 0, pos.x, pos.y, 0, _tnd.hWnd, NULL);
    
            // BUGFIX: See "PRB: Menus for Notification Icons Don't Work Correctly"
            ::PostMessage(_tnd.hWnd, WM_NULL, 0, 0);
    
            DestroyMenu(hMenu);
    
    		break;
    	}
    
    	return (0);
    }
    

    fertig das wars !!!

    wenn jemand offensichtlich sieht das ich etwas vergessen habe im bezug auf fehlerabfrage oder so wäre ich dankbar wenn er das mal postet


Anmelden zum Antworten