CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2003
    Location
    Sweden
    Posts
    129

    Exclamation Tray Icon(urgent)

    Hi!
    I need to make a tray icon for my program.
    How can i do that (please do not tell me to learn C#, cuz i know that its easy to do there, but i need to make it in C++)

    Can anyone please help me?! Id like this icon to appear when i start the program... then that icon is supposed to open my programs window if it was minimized.

    Please help! MSDN didnt help
    Last edited by Alexei Kubarev; November 22nd, 2003 at 05:51 PM.
    Regards,
    Alexei

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940
    Have a look at the Shell_NotifyIcon function and all its associated functions in MSDN.

    This should give you enough information to go on.

    I'm pretty sure there are going to be loads of resources in the articles of CodeGuru as well as The Code Project to tell you how to do this.

    Don't worry, it's not hard.

    Darwen.

  3. #3
    Join Date
    Nov 2003
    Location
    Sweden
    Posts
    129

    Thumbs up

    Thanks alot!
    I hope you are right...

    God, i love this forums -- lots of smart people
    Regards,
    Alexei

  4. #4
    Join Date
    Nov 2003
    Location
    Sweden
    Posts
    129
    I think i found it...
    Code:
    NOTIFYICONDATA not;
    not.cbSize =sizeof(NOTIFYICONDATA);
    not.hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    not.hWnd =this->m_hWnd ;
      strcpy(not.szTip ,"iChat Standard");
    not.uCallbackMessage=ID_TRAY;
    not.uFlags =NIF_ICON|NIF_MESSAGE|NIF_TIP;
    not.uID =1;
      Shell_NotifyIcon(NIM_ADD ,&not);
    Where do i put it?
    Regards,
    Alexei

  5. #5
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940
    If I remember correctly you need to elect a window to receive events which happen to your icon : e.g. left mouse button down, up etc etc.

    So it therefore follows that the sensible place to put this code is in the WM_CREATE handler (OnCreate) for whichever window you want to handle the events. It could be the mainframe of your application for instance.

    Darwen.

  6. #6
    Join Date
    Nov 2003
    Location
    Sweden
    Posts
    129

    Thumbs up

    Yapp...that worked....
    Id iserted it to the IniiInstanse part of my dialogs cpp...
    even thou now a bit harder thing--making the window appear on a double-click and disappear on the second double click... i saw 1 article... but somehow i didnt really understand it... maybe you can help me? or someone else?
    Regards,
    Alexei

  7. #7
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940
    ShowWindow(SW_SHOW) will show the window appropriately.

    If you're proposing to have a menu pop up because of a mouse click its really important that you call SetForegroundWindow before the TrackPopupMenu otherwise it'll not work properly.

    This foxed me for a while if I remember.

    Darwen.

  8. #8
    Join Date
    Nov 2003
    Location
    Sweden
    Posts
    129
    I ment just a double click on an icon to show the window and a double click to hide it....

    But im not sure how to write that code... im a newbie and im not really good with it....
    Can you please help me with that code? I used the icon code here:
    Code:
    BOOL CFavoritesDlg::OnInitDialog()
    {
    	CDialog::OnInitDialog();
    		// Add "About..." menu item to system menu.
    
    	// IDM_ABOUTBOX must be in the system command range.
    	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    	ASSERT(IDM_ABOUTBOX < 0xF000);
    //Starting the "Homepage" 
    	m_browser.Navigate("http://www.malakapower.com:112/pgrms/mf/", 0, 0, 0, 0);
    		
      // handle to icon
         HICON hIcon;
      // text for tool tip
         char lpszTip[] = "Malaka Favorites v1.0a BETA";
    
         HINSTANCE hInst =
             AfxFindResourceHandle(MAKEINTRESOURCE(IDR_MAINFRAME),
                                   RT_GROUP_ICON);
         hIcon = (HICON)LoadImage( hInst,
                                   MAKEINTRESOURCE(IDR_MAINFRAME),
                                   IMAGE_ICON,
                                   16,
                                   16,
                                   LR_DEFAULTCOLOR);
        
      // set NOTIFYCONDATA structure
    
         NOTIFYICONDATA tnid;
    
         tnid.cbSize = sizeof(NOTIFYICONDATA);
         tnid.hWnd = m_hWnd;
         tnid.uID = IDR_MAINFRAME;
         tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
         tnid.hIcon = hIcon;
    
         if (lpszTip)
            lstrcpyn(tnid.szTip, lpszTip, sizeof(tnid.szTip));
         else
            tnid.szTip[0] = '\0';
    
      // call to Shell_NotifyIcon with NIM_ADD parameter
    
         Shell_NotifyIcon(NIM_ADD, &tnid);
     
      // free icon 
    
         if (hIcon) 
         DestroyIcon(hIcon);
    //End of Icon initialization
    
    	CMenu* pSysMenu = GetSystemMenu(FALSE);
    	if (pSysMenu != NULL)
    	{
    		CString strAboutMenu;
    		strAboutMenu.LoadString(IDS_ABOUTBOX);
    		if (!strAboutMenu.IsEmpty())
    		{
    			pSysMenu->AppendMenu(MF_SEPARATOR);
    			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    		}
    	}
    
    	// Set the icon for this dialog.  The framework does this automatically
    	//  when the application's main window is not a dialog
    	SetIcon(m_hIcon, TRUE);			// Set big icon
    	SetIcon(m_hIcon, FALSE);		// Set small icon
    	
    	// TODO: Add extra initialization here
    	return TRUE;  // return TRUE  unless you set the focus to a control
    }
    If u can give me the code or atleast a sample or anything like it -- i will be really gratefull
    Regards,
    Alexei

  9. #9
    Join Date
    Nov 2003
    Posts
    13
    I remember seeing an article and a sample code to do this in codeguru, but I do not remeber the link.

    Searching the codeguru existing code base may help you.

    csheng

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured