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);

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.

链接地址: http://www.djcxy.com/p/57388.html

上一篇: AvalonDock:DockableContent上下文菜单显示错误的菜单列表

下一篇: 如何打开任何窗口的上下文菜单?