c#windows消息循环sendmessage实例
生活随笔
收集整理的這篇文章主要介紹了
c#windows消息循环sendmessage实例
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
[DllImport("User32.dll", EntryPoint = "SendMessage")]private static extern int SendMessage(IntPtr hWnd, // 信息發(fā)往的窗口的句柄 int Msg, // 消息ID int wParam, // 參數(shù)1 string lParam);[DllImport("User32.dll", EntryPoint = "SendMessage")]private static extern int SendMessage2(IntPtr hWnd, // 信息發(fā)往的窗口的句柄 int Msg, // 消息ID int wParam, // 參數(shù)1 IntPtr lParam);[DllImport("User32.dll", EntryPoint = "FindWindow")]private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);[DllImport("User32.dll", EntryPoint = "FindWindowEx")]private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName);
?
private void button4_Click(object sender, EventArgs e){IntPtr hwnd= FindWindow(null, "testForm");string info = "my info:ΑΒβδγζηθ";IntPtr pinfo= Marshal.StringToHGlobalAnsi(info);SendMessage2(hwnd, Form2.USERMESSAGEID, 12, pinfo);SendMessage(hwnd, Form2.USERMESSAGEID, 12, info);}?
public const int USERMESSAGEID =0x2021;protected override void WndProc(ref Message m){switch(m.Msg){case USERMESSAGEID:{int wparam= m.WParam.ToInt32();string str = Marshal.PtrToStringAnsi(m.LParam);break;}}base.WndProc(ref m);}?
[DllImport("User32.dll", EntryPoint = "SendMessage")]private static extern int SendMessage(IntPtr hWnd, // 信息發(fā)往的窗口的句柄 int Msg, // 消息ID int wParam, // 參數(shù)1 ref My_lParam lParam);?
IntPtr ptr = FindWindow(null, "主界面");SendMessage(ptr, MYMESSAGE, 1, ref m);//發(fā)送消息?
protected override void DefWndProc(ref Message m){try{switch (m.Msg){case MYMESSAGE:{My_lParam ml = new My_lParam();Type t = ml.GetType();ml = (My_lParam)m.GetLParam(t);break;}deafult :base.DefWndProc(ref m);}catch(){ }}總結
以上是生活随笔為你收集整理的c#windows消息循环sendmessage实例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 集合源码阅读:LinkedList
- 下一篇: mysql 8.0.19 winx64安