+ Reply to Thread
Results 1 to 2 of 2

Thread: handle mouse notification messages from system tray icon

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    29

    handle mouse notification messages from system tray icon

    I have system tray icon and I would like to display a pop-up menu when user presses on the system tray icon. How can I do this using WIN32 APIs? Please suggest some way.

  2. #2
    Junior Member
    Join Date
    Feb 2012
    Posts
    49
    Code:
    //register for a message
    const UINT WM_TRAY_ICON_NOTIFYICON = ::RegisterWindowMessage(_T("NotifyIcon")) ;
    
    //message handler registration
    BEGIN_MESSAGE_MAP(Dlg, CDialog)
    ON_REGISTERED_MESSAGE(WM_TRAY_ICON_NOTIFYICON, OnNotifyIcon)
    END_MESSAGE_MAP()
    
    BOOL Dlg::AddIcon()
    {
    	NOTIFYICONDATA notifyIconData ; 
     
        notifyIconData.cbSize			= sizeof(NOTIFYICONDATA) ; 
        notifyIconData.hWnd				= m_hWnd ; 
        notifyIconData.uID				= IDI_SYS_TRAY_ICON ; 
        notifyIconData.uFlags			= NIF_MESSAGE | NIF_ICON; 
        notifyIconData.hIcon			= m_hSysTrayIcon ; 
    	notifyIconData.uCallbackMessage	= WM_TRAY_ICON_NOTIFYICON ; 
    
    	return Shell_NotifyIcon(NIM_ADD, (NOTIFYICONDATA *) &notifyIconData) ;
    }
    
    //message handler
    void Dlg::OnNotifyIcon(WPARAM wParam, LPARAM lParam)
    {
        UINT nID		= (UINT) wParam ;
        UINT nMouseMsg	= (UINT) lParam ; 
     
    	switch(nMouseMsg)
    	{
    	case WM_LBUTTONDOWN:
    		{
    			//do whatever you want!
    		}
    		break ;
    	}
    }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts