Thread: Display system menu

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    2

    Display system menu

    I am trying to make a system menu display from another application at the current position of cursor.(though currently I can not get it to display at all)

    Exactly the same as when you right click on a a task in the task bar at the bottom of screen.

    I have the window handle of the other application.

    The following code is executed when the event WM_CONTEXTMENU is received(i know it passes here as it displays a message box if i put it in there.


    Code:
    HMENU hMenu;
    hMenu = GetSystemMenu(testItem->hWnd, 0);
    TrackPopupMenuEx(hMenu, TPM_LEFTBUTTON || TPM_LEFTALIGN, 50, 50, testItem->hWnd, NULL);
    It compiles fine but i get no menu.
    I can not get it to work for the life of me.

  2. #2
    Registered User
    Join Date
    Feb 2009
    Posts
    2
    This is how to do it

    Code:
        HMENU hmenu = GetSystemMenu(testItem->hWnd, FALSE);
        if (hmenu) {
            POINT pt;
    					
            GetCursorPos(&pt);
            int cmd = TrackPopupMenu(hmenu, TPM_LEFTBUTTON|TPM_RIGHTBUTTON|TPM_RETURNCMD, pt.x, pt.y, 0, hwnd, NULL);
    					
            if (cmd) {
                SetForegroundWindow(testItem->hWnd);	// reactivate window after the context menu has closed
                PostMessage(testItem->hWnd, WM_SYSCOMMAND, cmd, 0);
            }
        }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. HELP!!!!emergency ~expert please help
    By unknowppl in forum C Programming
    Replies: 1
    Last Post: 08-19-2008, 07:35 AM
  2. System calls stopping my function ...
    By twomers in forum C++ Programming
    Replies: 1
    Last Post: 06-20-2006, 09:01 AM
  3. Operating system construction
    By AdamLAN in forum Tech Board
    Replies: 7
    Last Post: 03-05-2005, 01:31 PM
  4. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 11:14 AM
  5. quick question about C Dos text menu pgm i was doing
    By Shadow in forum C Programming
    Replies: 2
    Last Post: 09-16-2001, 10:26 AM