1

我想知道如何将 createpopupmenu() 与 api 一起使用,我这样编写类:

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace test
{
   public static extern int DestroyIcon(IntPtr hIcon);

    [System.Runtime.InteropServices.DllImport("user32.dll")]
    public extern static bool ShowWindow(IntPtr hWnd, int nCmdShow);

    public const int GWL_EXSTYLE = -20;
    public const int WM_CLOSE = 16;
    public const int WM_COPY = 0x0301;
    public const int WM_PASTE = 0x0302;
    public const int WM_CUT = 0x0300;
    public const int WM_ERASEBKGND = 0x0014;
    public const int WM_USER = 0x400;
    public const int WM_DEVICECHANGE = 0x219;

    public const int EM_GETSCROLLPOS = (WM_USER + 221);
    public const int EM_SETSCROLLPOS = (WM_USER + 222);

    [DllImport("user32.dll")]
    public static extern IntPtr SetWindowLong(IntPtr hWnd, Int32 nIndex, IntPtr dwNewLong);

    [DllImport("user32.dll")]
    public static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);

    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
    public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
    public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, ref POINT point);

    [DllImport("user32.dll", SetLastError = true)]
    public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

    [DllImport("user32.dll")]
    public static extern IntPtr CreatePopupMenu();

    [DllImport("user32", SetLastError = true, CharSet = CharSet.Auto)]
    public static extern bool InsertMenu(IntPtr hmenu, int position, uint flags, IntPtr item_id, [MarshalAs(UnmanagedType.LPTStr)]string item_text);

    [Flags]
    public enum MenuFlags : uint
    {
        MF_STRING = 0,
        MF_BYPOSITION = 0x400,
        MF_SEPARATOR = 0x800,
        MF_REMOVE = 0x1000,
        MF_POPUP = 0x00000010,
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct POINT
    {
        public int x;
        public int y;
    }
}
}

但是我尝试使用此类和createpopupmenu()方法为我的表单制作菜单但它不起作用?谁能指导我我在做什么...?

4

0 回答 0