电竞竞猜平台-在Wince/WM实现进程间通信

发布时间:2021-03-17    来源:电竞下注网站 nbsp;   浏览:2643次
本文摘要:保证WM上的进程间通信,用以WindowMessage搭建2个过程间的通讯,觉得MessageWindow不太好用,因此 就用其他方式搭建对接WindowsMessage。

保证WM上的进程间通信,用以WindowMessage搭建2个过程间的通讯,觉得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));string str=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.。

电竞下注网站


本文关键词:电竞竞猜投注,电竞下注网站,电竞竞猜平台

本文来源:电竞竞猜投注-www.tdzbp.com