将WinORD中的DWORD事件常量转换为C#中的名称

时间:2013-04-10 13:29:19

标签: c#

我正在使用SetWinEventHookWinEventProc来捕获窗口消息

在WinEventProc中有一个参数“DWORD event”,其中包含一个代表该事件的数字

我想将此号码转换为名称

有没有c#功能呢?

我的代码基于此处的答案 Setting up Hook on Windows messages

2 个答案:

答案 0 :(得分:1)

public enum SystemEventContants : uint
{
    EVENT_SYSTEM_SOUND = 0x1,
    EVENT_SYSTEM_ALERT = 0x2,
    EVENT_SYSTEM_FOREGROUND = 0x3,
    EVENT_SYSTEM_MENUSTART = 0x4,
    EVENT_SYSTEM_MENUEND = 0x5,
    EVENT_SYSTEM_MENUPOPUPSTART = 0x6,
    EVENT_SYSTEM_MENUPOPUPEND = 0x7,
    EVENT_SYSTEM_CAPTURESTART = 0x8,
    EVENT_SYSTEM_CAPTUREEND = 0x9,
    EVENT_SYSTEM_MOVESIZESTART = 0xa,
    EVENT_SYSTEM_MOVESIZEEND = 0xb,
    EVENT_SYSTEM_CONTEXTHELPSTART = 0xc,
    EVENT_SYSTEM_CONTEXTHELPEND = 0xd,
    EVENT_SYSTEM_DRAGDROPSTART = 0xe,
    EVENT_SYSTEM_DRAGDROPEND = 0xf,
    EVENT_SYSTEM_DIALOGSTART = 0x10,
    EVENT_SYSTEM_DIALOGEND = 0x11,
    EVENT_SYSTEM_SCROLLINGSTART = 0x12,
    EVENT_SYSTEM_SCROLLINGEND = 0x13,
    EVENT_SYSTEM_SWITCHSTART = 0x14,
    EVENT_SYSTEM_SWITCHEND = 0x15,
    EVENT_SYSTEM_MINIMIZESTART = 0x16,
    EVENT_SYSTEM_MINIMIZEEND = 0x17
}

public enum ObjectEventContants : uint
{
    EVENT_OBJECT_CREATE = 0x8000,
    EVENT_OBJECT_DESTROY = 0x8001,
    EVENT_OBJECT_SHOW = 0x8002, 
    EVENT_OBJECT_HIDE = 0x8003,  
    EVENT_OBJECT_REORDER = 0x8004,
    EVENT_OBJECT_FOCUS = 0x8005,
    EVENT_OBJECT_SELECTION = 0x8006,
    EVENT_OBJECT_SELECTIONADD = 0x8007,
    EVENT_OBJECT_SELECTIONREMOVE = 0x8008,
    EVENT_OBJECT_SELECTIONWITHIN = 0x8009,
    EVENT_OBJECT_STATECHANGE = 0x800A,
    EVENT_OBJECT_LOCATIONCHANGE = 0x800B,
    EVENT_OBJECT_NAMECHANGE = 0x800C,
    EVENT_OBJECT_DESCRIPTIONCHANGE = 0x800D,  
    EVENT_OBJECT_VALUECHANGE = 0x800E,
    EVENT_OBJECT_PARENTCHANGE= 0x800F,  
    EVENT_OBJECT_HELPCHANGE= 0x8010,
    EVENT_OBJECT_DEFACTIONCHANGE = 0x8011, 
    EVENT_OBJECT_ACCELERATORCHANGE = 0x8012
}
// possible marshaling unmanaged type conflict/problem between 32/64 bit
public enum SystemObjectIDs 
{
    OBJID_WINDOW = 0x00000000,
    OBJID_SYSMENU = 0xFFFFFFFF,
    OBJID_TITLEBAR = 0xFFFFFFFE,
    OBJID_MENU = 0xFFFFFFFD,
    OBJID_CLIENT = 0xFFFFFFFC,
    OBJID_VSCROLL = 0xFFFFFFFB,
    OBJID_HSCROLL = 0xFFFFFFFA,
    OBJID_SIZEGRIP = 0xFFFFFFF9,
    OBJID_CARET = 0xFFFFFFF8,
    OBJID_CURSOR = 0xFFFFFFF7,
    OBJID_ALERT = 0xFFFFFFF6,
    OBJID_SOUND = 0xFFFFFFF5,
    OBJID_QUERYCLASSNAMEIDX = 0xFFFFFFF4,
    OBJID_NATIVEOM = 0xFFFFFFF0
}

public enum Flags
{
    WINEVENT_OUTOFCONTEXT = 0x0000,
    WINEVENT_SKIPOWNTHREAD = 0x0001,
    WINEVENT_SKIPOWNPROCESS = 0x0002,
    WINEVENT_INCONTEXT = 0x0004
}

来源:在Google上找到winuser.h。

答案 1 :(得分:0)

这会有点痛苦,但您可以尝试创建一个T4模板,在平台sdk C头文件中挖掘,解析值,并为您创建枚举。如果您这样做,那么如果您获得具有新值的平台SDK更新,它们将自动包含在您的枚举中(假设您再次重新生成T4输出)。