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; }
, , . , .