How to open the context menu of any window?

How to open the window context menu (the usual Windows context that appears when you right-click the window title).

Things I tried (at the click of a button)

ReleaseCapture(); SendMessage(this.Handle, WM_NCRBUTTONDOWN, 0, 0); SendMessage(this.Handle, WM_RBUTTONUP, 0, 0); SendMessage(this.Handle, WM_CONTEXTMENU, 0, 0); 

And this:

 ReleaseCapture(); SendMessage(this.Handle, WM_NCRBUTTONDOWN, HT_CAPTION, 0); SendMessage(this.Handle, WM_RBUTTONUP, HT_CAPTION, 0); SendMessage(this.Handle, WM_CONTEXTMENU, HT_CAPTION, 0); 
+5
source share
1 answer

To open the system’s context menu in a window, you can press Alt + Space. Therefore, in your case, you can send these keys to this window to open the context menu for you.

The part you did with SendMessage actually sends a notification that the specified window simulates right-clicks. But it is still important where the mouse is.

Also important: if you use "SendKeys.Send" (for Windows forms), this will only affect the currently active window.

+4
source

All Articles