BHO the right-click menu in multiple threads

Source: Internet
Author: User

BHO in the implementation of the right-click menu related articles Many, can be achieved through the implementation of IDocHostUIHandler interface ShowContextMenu, intercept HTMLDocumentEvents2 oncontextmenu messages.

However, both of these methods must be implemented in the browser thread in order to properly eject the right-click menu, when you need to implement the right-click menu in another thread, this is not the case, TrackPopupMenuEx will skip directly.

The way I take it is to build an invisible window that trackpopupmenuex the window handle that you want to set for that window.

To build a lightweight form class:

#include <atlbase.h> #include <atlwin.h>class cmenuwindow:public Atl::cwindowimpl < Cmenuwindow >{ Public:begin_msg_map (Cmenuwindow) End_msg_map ();};

  

Examples of right-click menus:

HMENU HMENU = CreatePopupMenu (); AppendMenu (HMenu, mf_string, 1001, L "AAA"); AppendMenu (HMenu, mf_string, 1002, L "BBB"); AppendMenu (HMenu, mf_string, 1003, L "CCC"); Point pt; GetCursorPos (&PT); RECT Wndrect;wndrect.left = Pt.x;wndrect.top = Pt.y;wndrect.right = wndrect.left + 1;wndrect.bottom = wndRect.top + 1; Cmenuwindow Wnd;wnd. Create (NULL, Wndrect, _t (""), ws_overlapped | ws_caption); int cmd = TrackPopupMenuEx (HMenu, Tpm_leftalign | tpm_nonotify | Tpm_returncmd | Tpm_leftbutton, Pt.x, Pt.y, Wnd.m_hwnd, NULL);D Estroymenu (HMenu); wnd. DestroyWindow (); Atl::cstring msg;msg. Format (L "id =%d", cmd); MessageBox (NULL, MSG, L "", MB_OK);

  

BHO the right-click menu in multiple threads

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.