WM-Message-Definitionen vom .NET Framework holen
Frank Dzaebel, erstellt am: 29.10.2005, zuletzt geändert: 29.10.2005
Kategorie: Interop, .NET-Version: 1.1
Windows-Meldungen (etwa WM_CLOSE) werden unter .NET des öfteren benötigt, um besondere Verhaltensweisen in Programmen zu erreichen. Deswegen bietet es sich an, einen enum dafür anzulegen.
Anstatt diese WM_* Konstanten aus dem Plattform-SDK zu holen (NG-Posting), kann man auch .NET "beauftragen", indem man private Konstanten "anzapft". So kann man sich leicht eine schon recht ausführliche CS-Datei erzeugen. Achtung, nicht jede Message ist auch unter jedem Betriebssystem erlaubt. Der Hashtable ist übrigens notwendig, da die Konstanten in den einzelnen Assemblies teilweise doppelt definiert sind.
Hier noch ein paar andere teilweise vollständigeren Listen:
- Win32-Message-enum (VS2005-PlatformSDK)
die Robert Jordan durch das Scannen des PlatformSDK/Include/ von VS.NET 2005 mittels Perl erstellt hat.
Dadurch lässt sich eine Liste der vom Framework 1.1 nicht genutzten WM-Messages ableiten
Hier die Erstellung über .NET:
static string NL = Environment.NewLine;
Hashtable wmHash = new Hashtable();
private void SaveAllConstantFields(Type type, string className, string startsWith)
{
Assembly a = type.Assembly;
Type methods = a.GetType(type.Namespace.ToString()+"."+className);
FieldInfo[] flds = methods.GetFields(BindingFlags.Public |
BindingFlags.NonPublic | BindingFlags.Static);
foreach (FieldInfo fi in flds)
if (wmHash[fi.Name]==null)
wmHash.Add(fi.Name, fi.GetValue(methods));
}
private void Form1_Load(object sender, System.EventArgs e)
{
SaveAllConstantFields(typeof(Microsoft.Win32.SystemEvents),
"NativeMethods", "WM_");
SaveAllConstantFields(typeof(System.Windows.Forms.Control),
"NativeMethods", "WM_");
ShowHash();
}
private void ShowHash()
{
string preText= @"
// .NET-Framework 1.1- ""WM_"" constants
// Frank Dzaebel, http://Dzaebel.NET/WM_Msg_NET.htm
namespace WM
{
public class WM
{" + NL;
textBox1.AppendText(preText);
foreach (string key in wmHash.Keys)
{
if (key.StartsWith("WM_"))
textBox1.AppendText(" public static int "+key +
"=" + wmHash[key].ToString() +";" +NL);
}
textBox1.AppendText(" }"+NL+"}");
}
Dies ergibt dann folgendes (hier auch für .NET 2.0):
// .NET-Framework 1.1- "WM_" constants
// Frank Dzaebel, http://Dzaebel.NET/WM_Msg_NET.htm
namespace WM
{
public class WM
{
public static int WM_DEVMODECHANGE=27;
public static int WM_ENDSESSION=22;
public static int WM_USERCHANGED=84;
public static int WM_MENUSELECT=287;
public static int WM_SYSCHAR=262;
public static int WM_DEADCHAR=259;
public static int WM_VSCROLL=277;
public static int WM_SYSCOMMAND=274;
public static int WM_MOVING=534;
public static int WM_SYSKEYUP=261;
public static int WM_PAINTICON=38;
public static int WM_ENABLE=10;
public static int WM_LBUTTONDOWN=513;
public static int WM_AFXLAST=895;
public static int WM_NOTIFY=78;
public static int WM_SETHOTKEY=50;
public static int WM_CANCELMODE=31;
public static int WM_ENTERMENULOOP=529;
public static int WM_PENWINLAST=911;
public static int WM_NCHITTEST=132;
public static int WM_MOUSEHOVER=673;
public static int WM_ACTIVATEAPP=28;
public static int WM_COMPACTING=65;
public static int WM_IME_COMPOSITIONFULL=644;
public static int WM_GETTEXTLENGTH=14;
public static int WM_COMPAREITEM=57;
public static int WM_CAPTURECHANGED=533;
public static int WM_IME_ENDCOMPOSITION=270;
public static int WM_NCXBUTTONUP=172;
public static int WM_MBUTTONDOWN=519;
public static int WM_NCLBUTTONUP=162;
public static int WM_NOTIFYFORMAT=85;
public static int WM_PALETTEISCHANGING=784;
public static int WM_HANDHELDLAST=863;
public static int WM_ERASEBKGND=20;
public static int WM_EXITSIZEMOVE=562;
public static int WM_RENDERFORMAT=773;
public static int WM_WINDOWPOSCHANGED=71;
public static int WM_UPDATEUISTATE=296;
public static int WM_SETCURSOR=32;
public static int WM_PALETTECHANGED=785;
public static int WM_NCLBUTTONDBLCLK=163;
public static int WM_SYSCOLORCHANGE=21;
public static int WM_MOUSEWHEEL=522;
public static int WM_VSCROLLCLIPBOARD=778;
public static int WM_MDITILE=550;
public static int WM_NCCALCSIZE=131;
public static int WM_DRAWITEM=43;
public static int WM_CREATE=1;
public static int WM_MDICASCADE=551;
public static int WM_CTLCOLORLISTBOX=308;
public static int WM_CTLCOLOREDIT=307;
public static int WM_NCMBUTTONDOWN=167;
public static int WM_MBUTTONUP=520;
public static int WM_RBUTTONUP=517;
public static int WM_XBUTTONUP=524;
public static int WM_MDIGETACTIVE=553;
public static int WM_ENTERSIZEMOVE=561;
public static int WM_HANDHELDFIRST=856;
public static int WM_CTLCOLORBTN=309;
public static int WM_SPOOLERSTATUS=42;
public static int WM_PARENTNOTIFY=528;
public static int WM_MDIRESTORE=547;
public static int WM_KEYFIRST=256;
public static int WM_WININICHANGE=26;
public static int WM_MDINEXT=548;
public static int WM_THEMECHANGED=794;
public static int WM_INPUTLANGCHANGEREQUEST=80;
public static int WM_MDIMAXIMIZE=549;
public static int WM_RBUTTONDBLCLK=518;
public static int WM_COMMAND=273;
public static int WM_CTLCOLOR=25;
public static int WM_CUT=768;
public static int WM_XBUTTONDOWN=523;
public static int WM_NCRBUTTONUP=165;
public static int WM_CONTEXTMENU=123;
public static int WM_PASTE=770;
public static int WM_IME_KEYLAST=271;
public static int WM_IME_SELECT=645;
public static int WM_KEYLAST=264;
public static int WM_NEXTDLGCTL=40;
public static int WM_DEVICECHANGE=537;
public static int WM_SETREDRAW=11;
public static int WM_NCXBUTTONDBLCLK=173;
public static int WM_IME_COMPOSITION=271;
public static int WM_KILLTIMER=1026;
public static int WM_MOUSEMOVE=512;
public static int WM_MOUSELAST=522;
public static int WM_POWER=72;
public static int WM_PRINTCLIENT=792;
public static int WM_NCCREATE=129;
public static int WM_IME_CHAR=646;
public static int WM_HELP=83;
public static int WM_VKEYTOITEM=46;
public static int WM_NCRBUTTONDBLCLK=166;
public static int WM_DESTROY=2;
public static int WM_ACTIVATE=6;
public static int WM_SETTEXT=12;
public static int WM_PAINT=15;
public static int WM_CLOSE=16;
public static int WM_NCRBUTTONDOWN=164;
public static int WM_HSCROLL=276;
public static int WM_ASKCBFORMATNAME=780;
public static int WM_STYLECHANGED=125;
public static int WM_NCDESTROY=130;
public static int WM_LBUTTONUP=514;
public static int WM_IME_CONTROL=643;
public static int WM_IME_STARTCOMPOSITION=269;
public static int WM_CANCELJOURNAL=75;
public static int WM_COPY=769;
public static int WM_INITMENU=278;
public static int WM_CHANGECBCHAIN=781;
public static int WM_SYSKEYDOWN=260;
public static int WM_MOUSEACTIVATE=33;
public static int WM_LBUTTONDBLCLK=515;
public static int WM_APP=32768;
public static int WM_NCMOUSEMOVE=160;
public static int WM_INPUTLANGCHANGE=81;
public static int WM_HSCROLLCLIPBOARD=782;
public static int WM_COMMNOTIFY=68;
public static int WM_MENUCHAR=288;
public static int WM_MDISETMENU=560;
public static int WM_GETICON=127;
public static int WM_NULL=0;
public static int WM_GETTEXT=13;
public static int WM_MOUSELEAVE=675;
public static int WM_NCPAINT=133;
public static int WM_MDIACTIVATE=546;
public static int WM_PRINT=791;
public static int WM_QUERYNEWPALETTE=783;
public static int WM_SYSDEADCHAR=263;
public static int WM_USER=1024;
public static int WM_QUERYUISTATE=297;
public static int WM_CHARTOITEM=47;
public static int WM_CTLCOLORSCROLLBAR=311;
public static int WM_POWERBROADCAST=536;
public static int WM_FONTCHANGE=29;
public static int WM_MDIDESTROY=545;
public static int WM_HOTKEY=786;
public static int WM_DRAWCLIPBOARD=776;
public static int WM_COPYDATA=74;
public static int WM_CTLCOLORSTATIC=312;
public static int WM_KEYDOWN=256;
public static int WM_MOUSEFIRST=512;
public static int WM_CTLCOLORMSGBOX=306;
public static int WM_SIZE=5;
public static int WM_IME_NOTIFY=642;
public static int WM_NCMBUTTONDBLCLK=169;
public static int WM_GETHOTKEY=51;
public static int WM_MOVE=3;
public static int WM_DESTROYCLIPBOARD=775;
public static int WM_MEASUREITEM=44;
public static int WM_NCXBUTTONDOWN=171;
public static int WM_UNDO=772;
public static int WM_MDICREATE=544;
public static int WM_RENDERALLFORMATS=774;
public static int WM_CLEAR=771;
public static int WM_DELETEITEM=45;
public static int WM_NCACTIVATE=134;
public static int WM_ENTERIDLE=289;
public static int WM_WINDOWPOSCHANGING=70;
public static int WM_EXITMENULOOP=530;
public static int WM_MDIREFRESHMENU=564;
public static int WM_DISPLAYCHANGE=126;
public static int WM_IME_SETCONTEXT=641;
public static int WM_QUIT=18;
public static int WM_MBUTTONDBLCLK=521;
public static int WM_MDIICONARRANGE=552;
public static int WM_XBUTTONDBLCLK=525;
public static int WM_GETOBJECT=61;
public static int WM_QUERYDRAGICON=55;
public static int WM_SHOWWINDOW=24;
public static int WM_SETICON=128;
public static int WM_SIZING=532;
public static int WM_TCARD=82;
public static int WM_KILLFOCUS=8;
public static int WM_STYLECHANGING=124;
public static int WM_TIMECHANGE=30;
public static int WM_ICONERASEBKGND=39;
public static int WM_INITMENUPOPUP=279;
public static int WM_QUEUESYNC=35;
public static int WM_CTLCOLORDLG=310;
public static int WM_GETFONT=49;
public static int WM_DROPFILES=563;
public static int WM_IME_KEYDOWN=656;
public static int WM_PAINTCLIPBOARD=777;
public static int WM_AFXFIRST=864;
public static int WM_GETDLGCODE=135;
public static int WM_IME_KEYUP=657;
public static int WM_PENWINFIRST=896;
public static int WM_CHAR=258;
public static int WM_CREATETIMER=1025;
public static int WM_NEXTMENU=531;
public static int WM_SETTINGCHANGE=26;
public static int WM_SETFOCUS=7;
public static int WM_TIMER=275;
public static int WM_KEYUP=257;
public static int WM_INITDIALOG=272;
public static int WM_CHILDACTIVATE=34;
public static int WM_NCLBUTTONDOWN=161;
public static int WM_QUERYENDSESSION=17;
public static int WM_QUERYOPEN=19;
public static int WM_CHANGEUISTATE=295;
public static int WM_GETMINMAXINFO=36;
public static int WM_SIZECLIPBOARD=779;
public static int WM_RBUTTONDOWN=516;
public static int WM_SETFONT=48;
public static int WM_NCMBUTTONUP=168;
public static int WM_REFLECT=8192;
public static int WM_CHOOSEFONT_GETLOGFONT=1025;
}
}