1

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

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

我想将此号码转换为姓名

是否有 ac# 功能可以做到这一点?

我的代码基于此处的答案 在 Windows 消息上设置挂钩

4

2 回答 2

2
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
}

来源:在谷歌上找到的 winuser.h。

于 2014-03-05T13:25:05.953 回答
0

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

于 2013-04-10T14:34:20.150 回答