Window system menu on image
21/06/2021
Aucun commentaire
If you have an image replacing standard icon for window you can show window system menu by using
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { POINT point = default(POINT); GetCursorPos(out point); IntPtr handle = GetSystemMenu(new WindowInteropHelper(this).Handle, bRevert: false); IntPtr hd = new WindowInteropHelper(this).Handle; int retvalue = TrackPopupMenu(handle, 256u, point.X, point.Y, 0, hd, (IntPtr)0); PostMessage(hd, 274u, retvalue, 0); } public struct POINT { public int X; public int Y; public POINT(int x, int y) { X = x; Y = y; } } private const int WM_SYSCOMMAND = 274; private const int TPM_RETURNCMD = 256; [DllImport("user32.dll")] private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert); [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern bool GetCursorPos(out POINT pt); [DllImport("user32.dll")] private static extern int TrackPopupMenu(IntPtr hMenu, uint uFlags, int x, int y, int nReserved, IntPtr hWnd, IntPtr prcRect); [DllImport("user32.dll", SetLastError = true)] private static extern int PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam); |
like this
Categories: Non classé
Commentaires récents