How to open the menu system window by right-clicking?

I have a borderless screen saver screen shape that displays the download progress and contains the Minimize and Close buttons (something similar to the screensaver screens that are visible in Office 2013). I would also like to provide a window system menu that opens by right-clicking anywhere in the form.

Classic system menu of a window

I am currently opening a menu by sending Alt + Space keys .

    System.Windows.Forms.SendKeys.SendWait("% ")   'sending Alt+Space

With this approach, the window system window always opens in the upper left corner of the window.

Is there a way to programmatically open the system menu in the same way as Windows initially when the user right-clicks the window title bar? An API call or a message that pops up in a menu?

, "" "" . ( .)

WPF Windows Forms (- SendWait()). VB # .

+3
1

bap-in winapi. , pinvoke. GetSystemMenu() , TrackPopupMenu(), , SendMessage WM_SYSCOMMAND.

, , , :

using System.Runtime.InteropServices;
...
    private void Window_MouseDown(object sender, MouseButtonEventArgs e) {
        if (e.ChangedButton == MouseButton.Right) {
            IntPtr hWnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
            RECT pos;
            GetWindowRect(hWnd, out pos);
            IntPtr hMenu = GetSystemMenu(hWnd, false);
            int cmd = TrackPopupMenu(hMenu, 0x100, pos.left, pos.top, 0, hWnd, IntPtr.Zero);
            if (cmd > 0) SendMessage(hWnd, 0x112, (IntPtr)cmd, IntPtr.Zero);
        }
    }
    [DllImport("user32.dll")]
    static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
    [DllImport("user32.dll")]
    static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
    [DllImport("user32.dll")]
    static extern int TrackPopupMenu(IntPtr hMenu, uint uFlags, int x, int y,
       int nReserved, IntPtr hWnd, IntPtr prcRect);
    [DllImport("user32.dll")]
    static extern bool GetWindowRect(IntPtr hWnd, out RECT rect);
    struct RECT { public int left, top, right, bottom; }

, , . , .

+3

All Articles