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 269465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:50:38+00:00 2026-05-11T23:50:38+00:00

I am hosting a web browser control, and want to provide my own context

  • 0

I am hosting a web browser control, and want to provide my own context menu.

Ideally, I want to present my own context menu, that contains the original browser’s context menu (with all addins etc.) as a sub menu.

If that’s not possible / to tricky, I’d be ok with e.g. normally showing my context menu, and showing the original one when the user presses SHIFT.

Do I need to implement IDocHostUIHandler? if yes, how do I specify a custom context menu, how can I force the original one? How do I get the control to use my implementation?

The control is created as such (error handling omitted):

HRESULT hr=AtlAxCreateControlEx(
   L"Shell.Explorer",m_wndWebCtrl.m_hWnd,
   NULL,NULL,(IUnknown**)&unk,
   IID_IWebBrowser2, NULL); // (IPersistStreamInit*)this);

hr = AtlAdviseSinkMap( this, true);

IUnknownPtr unk;
AtlAxGetControl(m_wndWebCtrl.m_hWnd, &unk);

IWebBrowser2Ptr browser2 = unk;
  • 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-11T23:50:39+00:00Added an answer on May 11, 2026 at 11:50 pm

    Yes, you do need to implement IDocHostUIHandler.

    Ok, i guess you could intercept right-clicks, keystrokes, and that other message that’ll normally display a context menu… But that’s probably gonna break badly sooner or later; at very least, i’d expect it to break accessibility.

    Once you’ve intercepted IDocHostUIHandler::ShowContextMenu(), you have the option of returning S_OK to squelch the built-in menu after showing your own. You can use the normal Win32 menu routines for this purpose, a custom control, or even fancy HTML if that’s what does it for you. Per the documentation, enough context is provided to allow you to determine what element context is requested for, and what the default context menu would be.

    Unfortunately, I know of no way to get a handle to the built-in menu. You could probably fake it by showing your context menu and then returning S_FALSE if the user chose the “original” option, but even then there’s no way to attach the resulting menu to an existing popup menu (which really should be gone by the time you return anyway if you’re running the modal-loop common to such popups). It is possible to add options to the built-in menus.

    You should be able to use GetKeyboardState() to determine the state of the shift key when the menu was requested.


    Assuming you only want a subset of the normal browser functionality anyway, you might be better served by just re-implementing the options you want (back, forward, print) and invoking the appropriate command if the user chooses them. Alternately, if you only want normal menus in a very specific scenario (for instance: editing commands in a textarea), use the ShowContextMenu() arguments to identify this and only then return S_FALSE to trigger the default. I’ve had pretty good luck with this latter technique; after all, they are supposed to be context menus…

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

Sidebar

Related Questions

I am hosting the web browser control in my own window. Here are the
I'm hosting some web content in a WPF app using the WebBrowser control (or
Recently our Web hosting provider moved to a medium trust level for all shared
I am hosting a web application that serves static html pages that are refreshed
I know that lots of web hosting providers are offering FreeBSD, but how good
I have a web server hosting an HTTP chat application that works with long-polling.
I am hosting a webbrowser control, that usually loads an external documents, then makes
I'm making a web browser based multiplayer game. I've determined that websockets are the
For an image hosting web application: For my stored images, is it feasible to
Are there other possibilities besides IIS for hosting web sites and web services based

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.