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