Thread: Systray menu messages

  1. #1
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470

    Systray menu messages

    Hi,

    I decided not to use a template for my systray menu, and created a function to add menu items into a created menu:

    Code:
    void AddMenuItem(int id, char* str)
    {
      MENUITEMINFO mi;
      mi.cbSize = sizeof(MENUITEMINFO);
      mi.fMask = MIIM_TYPE|MIIM_ID;
      mi.fType = MFT_STRING;
      mi.wID = id;
      mi.dwTypeData = str;
    	
      InsertMenuItem(menu,0,TRUE, &mi);
    }
    I created a menu with 2 items:

    Code:
    case WM_RBUTTONDOWN: 
     menu = CreatePopupMenu();
     AddMenuItem(IDEXIT, "Exit!");
     AddMenuItem(IDSTARTM, "Stop wall cycling");
    
     SetForegroundWindow(hWndDlg);
     GetCursorPos(&p);
     TrackPopupMenu(menu,TPM_LEFTALIGN |TPM_RETURNCMD|TPM_RIGHTBUTTON,
    			p.x,p.y,0,hWndDlg,NULL);
     break;
    The menu appears correctly.
    Then i had to process the menu item messages:
    Code:
    case WM_COMMAND:
     switch(wParam)
     {
      case IDSTARTM:		
       //dostuff
       MessageBeep(0);
       break;
    
      case IDEXIT:		
       //dostuff
       MessageBeep(0);
       break;
    ....
     }
    But when i select a menu item, nothing happens. What i'm doing wrong here please?

    Thanks alot.
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    When i create systray apps, i create the menu manually:
    Code:
      case WM_ICONNOTIFY:
    		switch(lParam){
    		case WM_RBUTTONUP:
    			SetForegroundWindow(d.hWndMain);
    			GetCursorPos(&p1);
    			mPopup = CreatePopupMenu();
    			AppendMenu(mPopup, MF_STRING|MF_ENABLED, 1, "Restore");
    			AppendMenu(mPopup, MF_SEPARATOR, 0, 0);
    			AppendMenu(mPopup, MF_STRING|MF_ENABLED, 3, "Close");
    			switch(TrackPopupMenu(mPopup ,TPM_RIGHTALIGN|TPM_LEFTBUTTON|TPM_RETURNCMD, p1.x, p1.y,0, d.hWndMain , NULL)){
    			case 1:// Restore				SetForegroundWindow(d.hWndMain);
    				TrayRemove();
    				d.bInTray = false;
    				ShowWindow(d.hWndMain, SW_SHOWNORMAL);
    				break;
    			case 3:// End				SendMessage(d.hWndMain, WM_CLOSE, 0, 0); break;
    			}
    			DestroyMenu(mPopup);
    			break;
    		case WM_LBUTTONDBLCLK:
    		case NIN_BALLOONUSERCLICK:
    			SetForegroundWindow(d.hWndMain);
    			TrayRemove();
    			d.bInTray = false;
    			ShowWindow(d.hWndMain, SW_SHOWNORMAL);
    			break;
    		}
    		break;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2009, 10:25 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Trouble with systray menu
    By geek@02 in forum Windows Programming
    Replies: 3
    Last Post: 05-06-2005, 10:19 AM
  4. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 03:41 AM