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

  • Home
  • SEARCH
  • 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 4234962
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:25:53+00:00 2026-05-21T02:25:53+00:00

I’m writing add-on for Internet Explorer 9 and I have to change default context

  • 0

I’m writing add-on for Internet Explorer 9 and I have to change default context menu to my own. I’m writing a BHO in C++ and I’m using ATL. I managed to handle event of showing context menu (HTMLDocumentEvents2::oncontextmenu), but I can’t display my own one. Here is the code fired when you click right mouse button:

VARIANT_BOOL STDMETHODCALLTYPE CSpellCheckerBHO::OnContextMenu( IHTMLEventObj *pEvtObj)
{
    HMENU contextMenu = CreatePopupMenu();

    MENUITEMINFO item_info = { 0 };
    item_info.cbSize = sizeof(MENUITEMINFO);
    item_info.fMask = MIIM_TYPE | MIIM_ID;
    item_info.fType = MFT_STRING;
    item_info.wID = 0;
    item_info.dwTypeData = L"TEST";
    item_info.cch = 4;

    BOOL result = InsertMenuItem(contextMenu, 0, FALSE, &item_info);
    HWND browserHandle = 0;
    HRESULT hr = _webBrowser->get_HWND((LONG_PTR*)&browserHandle);

    result = TrackPopupMenuEx(contextMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, 0,0, browserHandle , NULL);

    return VARIANT_FALSE;
}

_webBrowser is a pointer to IWebBrowser2 object, I got it from SetSite function.

The standard context menu is not displayed (due to returning VARIANT_FALSE), but TrackPopupMenuEx does nothing and returns 0.

Do you know what I am doing wrong? I need simple menu with some text items.

  • 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-21T02:25:54+00:00Added an answer on May 21, 2026 at 2:25 am

    I fgured it out. Igor Tandetnik helped me on IE addon forum. HWND was from different proccess and TrackPopupMenuEx expects HWND belonging to the calling thread. Here’s the code that works:

    VARIANT_BOOL STDMETHODCALLTYPE CSpellCheckerBHO::OnContextMenu( IHTMLEventObj *pEvtObj)
    {
        HMENU contextMenu = CreatePopupMenu();
    
        MENUITEMINFO item_info = { 0 };
        item_info.cbSize = sizeof(MENUITEMINFO);
        item_info.fMask = MIIM_ID | MIIM_STRING;
        item_info.wID = 0;
        item_info.dwTypeData = L"TEST";
        item_info.cch = 4;
    
        BOOL result = InsertMenuItem(contextMenu, 0, TRUE, &item_info);
    
        CComPtr<IDispatch> dispDoc;
        _webBrowser->get_Document(&dispDoc);
        CComQIPtr<IOleWindow> oleWindow = dispDoc;
        HWND browserHandle;
        oleWindow->GetWindow(&browserHandle);
    
    
        CComQIPtr<IHTMLEventObj2> htmlEventObj = pEvtObj;
        long x, y;
        htmlEventObj->get_screenX(&x);
        htmlEventObj->get_screenY(&y);  
    
        result = TrackPopupMenuEx(contextMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, browserHandle , NULL);
    
        return VARIANT_FALSE;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
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
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.