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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:17:00+00:00 2026-05-18T04:17:00+00:00

I am trying to implement a custom menu for Internet Explorer 7.0. For this

  • 0

I am trying to implement a custom menu for Internet Explorer 7.0. For this i have to use IDocHostUIHandler::ShowContextMenu only. Till now i am able to implement a basic context menu with two options. The problem is that they are disabled by default. The sample code for the same is:

HRESULT CWebEventHandler::ShowContextMenu(DWORD dwID,POINT *ppt, IUnknown *pcmdTarget, IDispatch *pdispObject) 
{
    if (false) // I will put some guard code here. as of now do not consider it
        return S_FALSE;      // Show standard context menus.
    else
    {
        IOleWindow* pWnd = NULL;
        HRESULT hr = pcmdTarget->QueryInterface(IID_IOleWindow,
            (void**) &pWnd);

        if (SUCCEEDED(hr))
        {
            HWND hwnd;

            if (SUCCEEDED(pWnd->GetWindow(&hwnd)))
            {
                HMENU menu = ::CreatePopupMenu();
                ::AppendMenu(menu, MF_STRING, ID_HELLO, L"&Hello" ); // ID_HELLO & ID_WORLD are two menu resource items
                ::AppendMenu(menu, MF_STRING, ID_WORLD, L"&World" );

                long myRetVal = ::TrackPopupMenu(menu, 
                    TPM_RIGHTBUTTON | TPM_LEFTALIGN | TPM_RETURNCMD, 
                    ppt->x, ppt->y, NULL, hwnd, NULL);

                // Send the command to the browser.
                //
                LRESULT myResult = ::SendMessage(hwnd, WM_COMMAND,
                    myRetVal, NULL);
            }

            pWnd->Release();
        }
    }
    return S_OK; 
}

Kindly suggest what is wrong with this code & why my menu entries are disabled??

Thanks

EDIT

The same post is available on this link also ( http://social.msdn.microsoft.com/Forums/en/ieextensiondevelopment/thread/13584f76-21bd-4764-b5b7-e81932561574 )

  • 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-18T04:17:01+00:00Added an answer on May 18, 2026 at 4:17 am

    I think i have solved the problem. After getting the hwnd object in if (SUCCEEDED(pWnd->GetWindow(&hwnd))) install your own CALLBACK for context menu. In the callback

    if ((uMsg == WM_INITMENUPOPUP) && (wParam == (WPARAM) menu)) {
            return 0;       
        }
    

    otherwise let the original handler process it.

    once done with

    long myRetVal = ::TrackPopupMenu(g_hPubMenu,TPM_RIGHTBUTTON | TPM_LEFTALIGN | TPM_RETURNCMD, 
                        ppt->x, ppt->y, NULL, hwnd, NULL);
    

    revert back to the original proc handler….

    Sample

    WNDPROC g_lpPrevWndProc = NULL;
    
    HRESULT CWebEventHandler::ShowContextMenu(DWORD dwID, POINT *ppt, IUnknown *pcmdTarget, IDispatch *pdispObject) 
        {
    
    
    if (false)
            return S_FALSE;      // Show standard context menus.
        else
        {
            IOleWindow* pWnd = NULL;
            HRESULT hr = pcmdTarget->QueryInterface(IID_IOleWindow,
                (void**) &pWnd);
    
            if (SUCCEEDED(hr))
            {
                HWND hwnd;
    
                if (SUCCEEDED(pWnd->GetWindow(&hwnd)))
                {
                    g_lpPrevWndProc = (WNDPROC)SetWindowLong(hwnd, GWL_WNDPROC, (LONG)CtxMenuWndProc);
    
                    if (g_hPubMenu)
                    {
                        DestroyMenu(g_hPubMenu);
                        g_hPubMenu = NULL;
                    }
                    g_hPubMenu = ::CreatePopupMenu();
    
                    ::AppendMenu(g_hPubMenu, MF_STRING|MF_ENABLED   , ID_HELLO, L"&Hello" );
                    ::AppendMenu(g_hPubMenu, MF_STRING|MF_ENABLED   , ID_WORLD, L"&World" );
    
                    long myRetVal = ::TrackPopupMenu(g_hPubMenu, 
                        TPM_RIGHTBUTTON | TPM_LEFTALIGN | TPM_RETURNCMD, 
                        ppt->x, ppt->y, NULL, hwnd, NULL);
    
                    SetWindowLong(hwnd, GWL_WNDPROC, (LONG)g_lpPrevWndProc);
    
                    // Send the command to the browser.
                    //
    
                    if (myRetVal == ID_HELLO)
                    {
                        box(_T("Hello"));
                    }else if(myRetVal == ID_WORLD)
                    {
                        box(_T("World"));
                    }else{
                            LRESULT myResult = ::SendMessage(hwnd, WM_COMMAND,myRetVal, NULL);
                    }
    
                }
    
                pWnd->Release();
            }
        }
        return S_OK; 
    }
    
    
    LRESULT CALLBACK CtxMenuWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        if ((uMsg == WM_INITMENUPOPUP) && (wParam == (WPARAM) g_hPubMenu)) {
            return 0;       
        }
        return CallWindowProc(g_lpPrevWndProc, hwnd, uMsg, wParam, lParam);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement the Media Player custom field control described in this MSDN
I'm trying to implement a custom MapView. Inside my MapActivity (named mainmap) I have
I'm trying to implement a view controller for a custom NSOpenGLView based view (this
I am trying to implement a custom broken image icon to appear if I
I'm trying to implement a DataGrid in ASP.NET, and want to achieve custom paging
I have been trying to implement Win32's MessageBox using GTK. The app uses SDL/OpenGL,
I'm trying to implement something like this: <div> <table> <thead> <tr> <td>Port name</td> <td>Current
I'm trying to implement a custom panel control that would act as a naming
I've been trying to implement a custom ORM for our project and am interested
UPDATE - No need to answer this now, I have solved below. Hi, I'm

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.