Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6631285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:31:27+00:00 2026-05-25T22:31:27+00:00

I’ll get right to the point: a custom menu item that I added to

  • 0

I’ll get right to the point: a custom menu item that I added to the system menu of every window through Windows global hooks doesn’t cause GetMsgProc to be invoked when the user clicks it.

Here is how I add the menu items:

void HookCore::AppendTasksMenu(HWND windowHandle)
{
    // make the popup menu and set up the appearance flags for the sub-items
    m_mnuMoveToTasks = CreatePopupMenu();
    UINT tasksAppearanceFlags = MF_STRING | MF_ENABLED;

    //TODO: need to make proper iterator for MenuItemList
    list<MenuItemInfo*>::iterator iter;
    for (iter = m_menuItems->Begin(); iter != m_menuItems->End(); iter++)
    {
        // check if we are adding a separator
        if ((*iter)->GetSpecial() == MenuItemInfo::SEPARATOR)
        {
            AppendMenu(m_mnuMoveToTasks, MF_SEPARATOR, (*iter)->GetItemId(), NULL);
        }
        else
        {
            AppendMenu(m_mnuMoveToTasks,
                ((*iter)->IsChecked() ? tasksAppearanceFlags | MF_CHECKED : tasksAppearanceFlags),
                (*iter)->GetItemId(), (*iter)->GetItemName().c_str());
        }
    }

    // get the system menu and set up the appearance flag for our new system sub-menu
    HMENU mnuSystem = GetSystemMenu(windowHandle, FALSE);
    UINT itemAppearanceFlags =  MF_STRING | MF_ENABLED | MF_POPUP;

    AppendMenu(mnuSystem, MF_SEPARATOR, ID_MOVE_TO_TASK_SEP, NULL);
    // append the sub-menu we just created
    AppendMenu(mnuSystem, itemAppearanceFlags, (UINT_PTR)m_mnuMoveToTasks, MOVE_TO_TASK);
}

This creates a new sub-menu in the system menu, and the sub-menu contains my additional items. The item IDs start with 1001, and increment by 1 for each new item. The items can be checked or unchecked.

When a user clicks one of my items I’m expecting to get a WM_SYSCOMMAND message through GetMsgProc, but it never gets called. GetMsgProc does get called however a few times during the initialization with other messages. I do see the WM_SYSCOMMAND message in CallWndProcRetProc though, but it doesn’t contain the correct item ID. I was expecting to get the item ID from the low-order word of wParam (as specified here: [http://www.codeproject.com/KB/dialog/AOTop.aspx]), but instead it just contains SC_MOUSEMENU.

Here is how I assign the GetMsgProc hook:

myhookdata[GET_MSG_HOOK].nType = WH_GETMESSAGE;
myhookdata[GET_MSG_HOOK].hkprc = GetMsgProc;
myhookdata[GET_MSG_HOOK].hhook = SetWindowsHookEx(
    myhookdata[GET_MSG_HOOK].nType,
    myhookdata[GET_MSG_HOOK].hkprc,
    AppHandle, 0);

Any ideas? Are my item IDs wrong? What is the right way to get the ID of the clicked item?

Thanks!

Update:

Based on the suggestions below, I tried catching the ‘WM_SYSCOMMAND’ and ‘WM_COMMAND’ messages in CallWndProc, CallWndProcRetProc, GetMsgProc, and SysMsgProc. The item selection message wasn’t delivered.

I also tried subclassing the window to which the menu belongs, and my WndProc never got the item selection message, although other messages like ‘WM_MENUSELECT’ and ‘WM_UNINITMENUPOPUP’ were delivered.

Any pointers where else to check?

Update 2:

So when I subclass/unsubclass the window, I do it in my CallWndProc hook. I subclass when I get the WM_INITMENUPOPUP message, and I unsubclass when I get the WM_MENUSELECT message for menu closing (when lParam equals NULL and HIWORD(wParam) equals 0xFFFF).

I click on the system menu (at which point the WM_INITPOPUPMENU gets raised), move the mouse cursor into my sub-menu that contains the custom items, and then click on one of the items. I log every message I get in my new WndProc during this process. Here is the list of messages I get in my WndProc during this test:

WM_INITMENUPOPUP
147 (0x0093) - what is this message?
148 (0x0094) [9 times] - what is this message?
WM_NCMOUSELEAVE
WM_ENTERIDLE [2 times]
WM_NOTIFY [2 times]
WM_ENTERIDLE [2 times]
WM_NOTIFY
WM_ENTERIDLE [11 times]
WM_MENUSELECT
WM_ENTERIDLE [5 times]
WM_MENUSELECT
WM_ENTERIDLE [6 times]
WM_MENUSELECT
WM_ENTERIDLE [7 times]
WM_MENUSELECT
WM_ENTERIDLE [8 times]
WM_NOTIFY
WM_ENTERIDLE [5 times]
WM_NOTIFY
WM_ENTERIDLE
WM_NOTIFY
WM_ENTERIDLE
WM_UNINITMENUPOPUP
WM_CAPTURECHANGED

The message I’m expecting to see when the user clicks the item is either WM_COMMAND or WM_SYSCOMMAND. I don’t have much experience with windows messages or working with the Windows API. Is one of those two the right message to look for? Neither message is there, yet it should be, right? Is there something I’m missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:31:28+00:00Added an answer on May 25, 2026 at 10:31 pm

    Ok, I figured it out. I’m not sure why, but I don’t see the correct message in any of the hooks. I do, however, see it in WndProc if I subclass the window. In the 2nd Update above I said that I don’t see the correct message when subclassing – I was unsubclassing too soon.

    So, this is how I subclass:

    if (oldWndProc == -1)
    {
        oldWndProc = SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)NewWndProc);
        currentSubclassedHandle = hwnd;
    }
    

    And here is how I unsubclass:

    if (oldWndProc != -1)
    {
        SetWindowLongPtr(currentSubclassedHandle, GWL_WNDPROC, (LONG)oldWndProc);
        oldWndProc = -1;
        currentSubclassedHandle = NULL;
    }
    

    The message I get is WM_SYSCOMMAND, where the wParam is the custom menu item ID. This message gets delivered to the NewWndProc a little bit after the last message that I posted in the 2nd Update.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.