C# 裡可以override 窗體的 WndProc ,但 WM_CLOSE 這些常量在哪裡有定義呢?還有那些結構體的定義在哪裡
C# 裡可以override 窗體的 WndProc ,但 WM_CLOSE 這些常量在哪裡有定義呢?還有那些結構體的定義在哪裡 --------------------编程问答-------------------- 需要你自己定义。 --------------------编程问答-------------------- 你可以从MSDN里找到相应的常量定义及结构定义,如果你安装了VC++那会更好,可以通过查找.H文件来找到定义。最简单的就是在IDE的文件查找里,输入常量名称,查找条件为.h来查找。 --------------------编程问答-------------------- 如在WinUser.h文件里有如下的定义片段:--------------------编程问答--------------------
#define WM_SETFOCUS 0x0007
#define WM_KILLFOCUS 0x0008
#define WM_ENABLE 0x000A
#define WM_SETREDRAW 0x000B
#define WM_SETTEXT 0x000C
#define WM_GETTEXT 0x000D
#define WM_GETTEXTLENGTH 0x000E
#define WM_PAINT 0x000F
#define WM_CLOSE 0x0010
#ifndef _WIN32_WCE
#define WM_QUERYENDSESSION 0x0011
#define WM_QUERYOPEN 0x0013
#define WM_ENDSESSION 0x0016
#endif
#define WM_QUIT 0x0012
#define WM_ERASEBKGND 0x0014
#define WM_SYSCOLORCHANGE 0x0015
#define WM_SHOWWINDOW 0x0018
Oh! My God!
但我在 WndProc 裡用 Debug.WriteLine(m.ToString()); 這樣把消息打印出來,也時輸出 WM_CLOSE 的字符串呢?我想在.net 內部應該是有定義的 --------------------编程问答-------------------- WinForm的窗体和MFC类似都采用了Windows的原有的常量及结构。你只需去MSDN查找就可以了。这不是.net才有的。 --------------------编程问答--------------------
我知道,我只是想確認一下,是不是 .net 裡沒有定義這些常量,是不是必須要手動加入 --------------------编程问答-------------------- 当然要手动的来加入。
你看到的那些常量的名字只不过是在.net内部把其使用Switch做了个处理。 --------------------编程问答--------------------
事实上.Net Framework在System.Windows.Forms中定义了windows的消息和结构体,在NativeMethods类中,但是由于其定义为"internal static class NativeMethods",因此无法在System.Windows.Forms外使用,如果你不想查看msdn,你可以通过反编译该程序集的方法,将其中的消息定义copy下来使用即可。如下是其中一部分:
public const int WH_GETMESSAGE = 3;
public const int WH_JOURNALPLAYBACK = 1;
public const int WH_MOUSE = 7;
public const int WHEEL_DELTA = 120;
public const int WINDING = 2;
public const int WM_ACTIVATE = 6;
public const int WM_ACTIVATEAPP = 0x1c;
public const int WM_AFXFIRST = 0x360;
public const int WM_AFXLAST = 0x37f;
public const int WM_APP = 0x8000;
public const int WM_ASKCBFORMATNAME = 780;
public const int WM_CANCELJOURNAL = 0x4b;
public const int WM_CANCELMODE = 0x1f;
public const int WM_CAPTURECHANGED = 0x215;
public const int WM_CHANGECBCHAIN = 0x30d;
public const int WM_CHANGEUISTATE = 0x127;
public const int WM_CHAR = 0x102;
public const int WM_CHARTOITEM = 0x2f;
public const int WM_CHILDACTIVATE = 0x22;
public const int WM_CHOOSEFONT_GETLOGFONT = 0x401;
public const int WM_CLEAR = 0x303;
public const int WM_CLOSE = 0x10;
public const int WM_COMMAND = 0x111;
public const int WM_COMMNOTIFY = 0x44;
public const int WM_COMPACTING = 0x41;
public const int WM_COMPAREITEM = 0x39;
public const int WM_CONTEXTMENU = 0x7b;
public const int WM_COPY = 0x301;
public const int WM_COPYDATA = 0x4a;
public const int WM_CREATE = 1;
public const int WM_CTLCOLOR = 0x19;
public const int WM_CTLCOLORBTN = 0x135;
public const int WM_CTLCOLORDLG = 310;
public const int WM_CTLCOLOREDIT = 0x133;
public const int WM_CTLCOLORLISTBOX = 0x134;
public const int WM_CTLCOLORMSGBOX = 0x132;
public const int WM_CTLCOLORSCROLLBAR = 0x137;
public const int WM_CTLCOLORSTATIC = 0x138;
public const int WM_CUT = 0x300;
public const int WM_DEADCHAR = 0x103;
public const int WM_DELETEITEM = 0x2d;
public const int WM_DESTROY = 2;
public const int WM_DESTROYCLIPBOARD = 0x307;
public const int WM_DEVICECHANGE = 0x219;
public const int WM_DEVMODECHANGE = 0x1b;
public const int WM_DISPLAYCHANGE = 0x7e;
public const int WM_DRAWCLIPBOARD = 0x308;
public const int WM_DRAWITEM = 0x2b;
--------------------编程问答-------------------- 当然,现在.net framework开源了,直接下源代码就可以复制了,不必要反编译了。 --------------------编程问答-------------------- 在NativeMethods类中,但是由于其定义为"internal static class NativeMethods"
暈了
补充:.NET技术 , C#