Tray Icon



  • Hi Leute,
    weiß vielleicht zufällig jemand, wie ich statt mein Programm zu minimieren, es als Tray Icon anzeigen kann???

    Wäre echt net, wenn mir jemand helfen könnte

    Alexander



  • Also fang einfach DefWindowProc ab und änders bissl ab. WM_USER ist für eigene Messages zu definieren und gibt den abstand zur letzten message an, wenn ichs richtig verstanden hab.( Falls es dich interessiert)

    #define WM_ICONNOTIFY (WM_USER+1)
    
    LRESULT CMainFrame::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
    {
    	if( message == WM_SYSCOMMAND )
    	{
    		if( wParam == SC_MINIMIZE )
    		{
    			NOTIFYICONDATA	tnid;
    
    			tnid.cbSize				= sizeof( NOTIFYICONDATA );
    			tnid.hWnd				= AfxGetMainWnd()->GetSafeHwnd();
    			tnid.uID				= 0;
    			tnid.uFlags				= NIF_MESSAGE | NIF_ICON | NIF_TIP;
    			tnid.uCallbackMessage	= WM_ICONNOTIFY;
    			tnid.hIcon				= AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    			lstrcpyn( tnid.szTip, AfxGetAppName(), sizeof(tnid.szTip) );
    
    			Shell_NotifyIcon( NIM_ADD, &tnid );
    
    			AfxGetApp()->HideApplication();
    
    			return 0;
    		}
    	}
    	else if( message == WM_ICONNOTIFY && lParam != WM_MOUSEMOVE )
    	{
    		NOTIFYICONDATA	tnid;
    
    		tnid.cbSize				= sizeof( NOTIFYICONDATA );
    		tnid.hWnd				= AfxGetMainWnd()->GetSafeHwnd();
    		tnid.uID				= 0;
    
    		Shell_NotifyIcon( NIM_DELETE, &tnid );
    
    		AfxGetMainWnd()->ShowWindow( SW_SHOW );
    		AfxGetMainWnd()->UpdateWindow();
    		AfxGetMainWnd()->SetActiveWindow();
    
    		return 0;
    	}
    
    	return CFrameWnd::DefWindowProc(message, wParam, lParam);
    }
    

    Edit: hatte "es dich" zusammen geschrieben 😉
    MFG

    Hansi



  • Ich hab dafür mal ne Dialogklasse geschrieben, falls deine
    Anwendung Dialogbasiert ist, einfach als Basisklasse verwenden,
    ansonsten musst du es noch einwenig umstricken.

    CTrayDlg

    Devil


Anmelden zum Antworten