最近在用C#,其中的Panel控件异常好用,灵活使用的话,在C#中做同样漂亮的界面要比VC花的时间少很多。我喜欢在VC的类里定义自定义消息,在C#中颇费一番工夫。总结如下: ?????? 。在VC中定义消息: ?? ?? #define WM_TEST WM_USER + 101
。在C#中定义消息: ????????????? public const int WM_TEST =0x0400+101;? //一定是int型才能与windows消息代码匹配
。要发送消息只能调用windows的API函数SnedMessage或PostMessage,其原型如下:
??????????????? [DllImport("User32.dll",EntryPoint="SendMessage")] ??????????????????????? private static extern int SendMessage( ???????????????????????? IntPtr hWnd,// handle to destination window ???????????????????????? uint Msg,// message ???????????????????????? uint wParam,// first message parameter ???????????????????????? uint lParam // second message parameter ????????????????????? );? ????????????????? [DllImport("User32.dll",EntryPoint="PostMessage")] ?????????????????????? private static extern int PostMessage( ????????????????????????????? IntPtr hWnd,// handle to destination window ????????????????????????????? uint Msg,// message ????????????????????????????? uint wParam,// first message parameter ??????????????????????????????uint lParam // second message parameter ???????????????????????? );?
。在Form中可以重载DefWinproc函数来接收消息:
??????????? protected override void DefWndProc ( ref System.Windows.Forms.Message m ) ?????????? { ?????????? switch(m.Msg) ???????????? { ???????? case Message.WM_TEST: ??????????????????????? break; ???????? default: ??????????? base.DefWndProc(ref m);//调用基类函数 ??????????? break; ?????????? } ?????????? }?
? (编辑:北几岛)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|