Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open the context menu of any window?

How do you open the context menu of a window (the normal Windows context that appears when you Right-Click the title-bar of a window).

Things I've tried (on a button click)

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);
like image 604
Andrew Gee Avatar asked Sep 29 '22 06:09

Andrew Gee


1 Answers

To open the system context menu on a window you can press Alt+Space. So in your case you could send those keys to that window, which should open the context menu for you.

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

Also important: If you use "SendKeys.Send" (for windows forms), this will only affect the window that is currently active.

like image 184
Alex Endris Avatar answered Oct 05 '22 08:10

Alex Endris