CBA下注APPCBA下注APP

官方视频
在Wince/WM实现进程间通信
来源:CBA下注APP    发布时间:2021-10-09 00:33:02
本文摘要:做到WM上的进程间通信,用于WindowMessage构建两个进程间的通信,感觉MessageWindow不好用,所以就用别的方法构建接管WindowsMessage。

CBA下注

CBA下注APP

做到WM上的进程间通信,用于WindowMessage构建两个进程间的通信,感觉MessageWindow不好用,所以就用别的方法构建接管WindowsMessage。再行来PCB一下必须用于的功能,命名为Cls_Message:viewplaincopytoclipboardprint?usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Runtime.InteropServices;usingMicrosoft.WindowsCE.Forms;usingSystem.Windows.Forms;classCls_Message{privatestructCOPYDATASTRUCT{publicintdwData;publicintcbData;publicIntPtrlpData;}//-------------------------------------------------------------------------------privateconstintWM_COPYDATA=0x004A;privateconstintGWL_WNDPROC=-4;privateconstintLMEM_FIXED=0x0000;privateconstintLMEM_ZEROINIT=0x0040;privateconstintLPTR=(LMEM_FIXED|LMEM_ZEROINIT);privateIntPtroldWndProc=IntPtr.Zero;privateWndProcDelegatenewWndProc;privateIntPtrformHandle;//-------------------------------------------------------------------------------delegateIntPtrWndProcDelegate(IntPtrhWnd,uintmsg,IntPtrwParam,IntPtrlParam);[DllImport(coredll.dll)]staticexternIntPtrCallWindowProc(IntPtrlpPrevWndFunc,IntPtrhWnd,uintMsg,IntPtrwParam,IntPtrlParam);[DllImport(coredll.dll,EntryPoint=GetWindowLong)]privatestaticexternIntPtrGetWindowLong(IntPtrhWnd,intnIndex);[DllImport(coredll.dll)]staticexternintSetWindowLong(IntPtrhWnd,intnIndex,IntPtrnewWndProc);[DllImport(coredll.dll,EntryPoint=FindWindow)]publicstaticexternIntPtrFindWindow(stringlpClassName,stringlpWindowName);[DllImport(coredll.dll)]privatestaticexternintSendMessageW(IntPtrhWnd,intMsg,IntPtrwParam,IntPtrlParam);[DllImport(coredll.dll)]privatestaticexternIntPtrLocalAlloc(intflag,intsize);[DllImport(coredll.dll)]privatestaticexternIntPtrLocalFree(IntPtrp);///summary///初始化消息类////summary///paramname=handle拒绝接受消息的窗体的句柄/parampublicCls_Message(IntPtrformHandle){this.formHandle=formHandle;newWndProc=newWndProcDelegate(WndProc);oldWndProc=GetWindowLong(formHandle,GWL_WNDPROC);intsuccess=SetWindowLong(formHandle,GWL_WNDPROC,Marshal.GetFunctionPointerForDelegate(newWndProc));}///summary///消息处置////summaryprivateIntPtrWndProc(IntPtrhWnd,uintmsg,IntPtrwParam,IntPtrlParam){if(msg==WM_COPYDATA){COPYDATASTRUCTst=(COPYDATASTRUCT)Marshal.PtrToStructure(lParam,typeof(COPYDATASTRUCT));stringstr=Marshal.PtrToStringUni(st.lpData);MessageBox.Show(str);}returnCallWindowProc(oldWndProc,this.formHandle,msg,wParam,lParam);}staticprivateIntPtrAllocHGlobal(intcb){IntPtrhMemory=newIntPtr();hMemory=LocalAlloc(LPTR,cb);returnhMemory;}staticprivatevoidFreeHGlobal(IntPtrhMemory){if(hMemory!=IntPtr.Zero)LocalFree(hMemory);}///summary///发送到消息////summary///paramname=formTitle目标窗体的名称/param///paramname=message消息内容/paramstaticpublicvoidSendMessage(StringformTitle,Stringmessage){IntPtrhWndDest=FindWindow(null,formTitle);COPYDATASTRUCToCDS=newCOPYDATASTRUCT();oCDS.cbData=(message.Length+1)*2;oCDS.lpData=LocalAlloc(LPTR,oCDS.cbData);Marshal.Copy(message.ToCharArray(),0,oCDS.lpData,message.Length);oCDS.dwData=1;IntPtrlParam=AllocHGlobal(oCDS.cbData);Marshal.StructureToPtr(oCDS,lParam,false);SendMessageW(hWndDest,WM_COPYDATA,IntPtr.Zero,lParam);LocalFree(oCDS.lpData);FreeHGlobal(lParam);}}usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Runtime.InteropServices;usingMicrosoft.WindowsCE.Forms;usingSystem.Windows.Forms;classCls_Message{privatestructCOPYDATASTRUCT{publicintdwData;publicintcbData;publicIntPtrlpData;}//-------------------------------------------------------------------------------privateconstintWM_COPYDATA=0x004A;privateconstintGWL_WNDPROC=-4;privateconstintLMEM_FIXED=0x0000;privateconstintLMEM_ZEROINIT=0x0040;privateconstintLPTR=(LMEM_FIXED|LMEM_ZEROINIT);privateIntPtroldWndProc=IntPtr.Zero;privateWndProcDelegatenewWndProc;privateIntPtrformHandle;//-------------------------------------------------------------------------------delegateIntPtrWndProcDelegate(IntPtrhWnd,uintmsg,IntPtrwParam,IntPtrlParam);[DllImport(coredll.dll)]staticexternIntPtrCallWindowProc(IntPtrlpPrevWndFunc,IntPtrhWnd,uintMsg,IntPtrwParam,IntPtrlParam);[DllImport(coredll.dll,EntryPoint=GetWindowLong)]privatestaticexternIntPtrGetWindowLong(IntPtrhWnd,intnIndex);[DllImport(coredll.dll)]staticexternintSetWindowLong(IntPtrhWnd,intnIndex,IntPtrnewWndProc);[DllImport(coredll.dll,EntryPoint=FindWindow)]publicstaticexternIntPtrFindWindow(stringlpClassName,stringlpWindowName);[DllImport(coredll.dll)]privatestaticexternintSendMessageW(IntPtrhWnd,intMsg,IntPtrwParam,IntPtrlParam);[DllImport(coredll.dll)]privatestaticexternIntPtrLocalAlloc(intflag,intsize);[DllImport(coredll.dll)]privatestaticexternIntPtrLocalFree(IntPtrp);///summary///初始化消息类////summary///paramname=handle拒绝接受消息的窗体的句柄/parampublicCls_Message(IntPtrformHandle){this.formHandle=formHandle;newWndProc=newWndProcDelegate(WndProc);oldWndProc=GetWindowLong(formHandle,GWL_WNDPROC);intsuccess=SetWindowLong(formHandle,GWL_WNDPROC,Marshal.GetFunctionPointerForDelegate(newWndProc));}///summary///消息处置////summaryprivateIntPtrWndProc(IntPtrhWnd,uintmsg,IntPtrwParam,IntPtrlParam){if(msg==WM_COPYDATA){COPYDATASTRUCTst=(COPYDATASTRUCT)Marshal.PtrToStructure(lParam,typeof(COPYDATASTRUCT));stringstr=Marshal.PtrToStringUni(st.lpData);MessageBox.Show(str);}returnCallWindowProc(oldWndProc,this.formHandle,msg,wParam,lParam);}staticprivateIntPtrAllocHGlobal(intcb){IntPtrhMemory=newIntPtr();hMemory=LocalAlloc(LPTR,cb);returnhMemory;}staticprivatevoidFreeHGlobal(IntPtrhMemory){if(hMemory!=IntPtr.Zero)LocalFree(hMemory);}///summary///发送到消息////summary///paramname=formTitle目标窗体的名称/param///paramname=message消息内容/paramstaticpublicvoidSendMessage(StringformTitle,Stringmessage){IntPtrhWndDest=FindWindow(null,formTitle);COPYDATASTRUCToCDS=newCOPYDATASTRUCT();oCDS.cbData=(message.Length+1)*2;oCDS.lpData=LocalAlloc(LPTR,oCDS.cbData);Marshal.Copy(message.ToCharArray(),0,oCDS.lpData,message.Length);oCDS.dwData=1;IntPtrlParam=AllocHGlobal(oCDS.cbData);Marshal.StructureToPtr(oCDS,lParam,false);SendMessageW(hWndDest,WM_COPYDATA,IntPtr.Zero,lParam);LocalFree(oCDS.lpData);FreeHGlobal(lParam);}}接下来张贴出有调用代码,构建自发性自收,如果要发给别的进程,只必须把SendMessage的第一个参数改回目标窗体的名称才可(当然目标窗体也必需提到了Cls_Message构建缴信息处理):viewplaincopytoclipboardprint?Cls_MessageclsMessage;//初始化publicForm1(){InitializeComponent();}privatevoidForm1_Load(objectsender,EventArgse){clsMessage=newCls_Message(this.Handle);//使本窗体需要接管WindowMessage}privatevoidbutton1_Click(objectsender,EventArgse){Cls_Message.。

CBA下注APP


本文关键词:CBA下注,CBA下注APP

本文来源:CBA下注-www.kmbrcw.com

上一新闻:区块链,一把打开文化产业未来发展之门的钥匙

下一新闻:基因疗法狂人将DNA注射到体内抗衰老|CBA下注

推荐阅读

企业要闻

企业动态

门窗百科

太阳能着色 互补系统 易护理 保温 环保节能
预约报名 免费测量 免费设计 免费报价 免费安装 终身维护
版权所有©2011-2020 天津市CBA下注股份有限公司
津ICP备83792898号-8
联系地址: 天津市天津市天津区天标大楼55号
联系电话:0896-486084724
联系邮箱:663395747@qq.com
传真号码:098-312822393