1

I am using SetWinEventHook and WinEventProc to capture window messages

In WinEventProc there is a parameter "DWORD event" with a number that represnt the event

I would like to convert this number to a name

Is there a c# function to do that?

My code is based on the answer from here Setting up Hook on Windows messages

Community
  • 1
  • 1
Natan Rubinstein
  • 665
  • 1
  • 9
  • 27

2 Answers2

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
}

source : winuser.h found on Google.

JohnTube
  • 1,782
  • 27
  • 46
0

It would be a bit painful, but you could try and create a T4 template to go digging around in the platform sdk C header files, parse out the values, and create the enum for you. If you do it this way, then if you get a platform SDK update with new values they would automtically get included into your enum (assuming you regenerate the T4 output again).

user957902
  • 3,010
  • 14
  • 18