findwindow function winuwin7 findwindowser h

番茄系统家园 · 2021-08-29 01:16:23

findwindow function  winuwin7 findwindowser h

MFC端利用()函数打开WPF生成的exe文件同时将自己当前的窗口句柄作为命令行参数传递过去。代码如下

#(()this-());//这里利用将窗口句柄转化一次之后再使用()将句柄转化为(%s

,());ShellExecuteA(this-GetSafeHwnd(),open,exePathPalmServer.exe,hwnd.c_str(),NULL,1);

WPF端将获得的命令行参数解析出C端的窗口句柄然后将自己的窗口句柄发送给C端

//App.xmlApplicationx:ClassPalmServer.Appxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:localclr-namespace:PalmServerStartupApplication_Startup//定义程序入口Application.Resources/Application.Resources/Application//App.xml.cspublicpartialclassApp:Application{[System.Runtime.InteropServices.DllImport(user32.dll)]privatestaticexternintSendMessage(IntPtrhwnd,uintwMsg,IntPtrwParam,intlParam);//SendCprogramtheC#mainwindowHWNDprivateconstuintWM_PS_HWND9034;//TellclienttheHWNDofthiswindow//程序入口privatevoidApplication_Startup(objectsender,StartupEventArgse){MainWindowwndnewMainWindow();wnd.Show();if(e.Args.Length1){intaConvert.ToInt32(e.Args[0]);//将包含C的窗口句柄的string转化为intIntPtrproxyHandleByShellExec(IntPtr)a;//MFC中的HWND类型等同于WPF中的IntPtr类型Console.WriteLine(proxyHandleByShellExec.ToString());//输出看看句柄的数字是什么if(proxyHandleByShellExec!(IntPtr)0){varmainWindowHandlenewSystem.Windows.Interop.WindowInteropHelper(wnd).Handle;//C#获得窗口句柄Console.WriteLine(mainWindowHandle.ToString());SendMessage(proxyHandleByShellExec,WM_PS_HWND,mainWindowHandle,0);//将MainWindow的窗口句柄发送给C端}}elseConsole.WriteLine(e.Args.Length.ToString());}}}

MFC定义消息处理函数接收消息即可。

//Dlg.h//PalmServerHWNDclassCDlgPalmProbe:publicCDialogEx{private:HWNDhProbeServerBySendMessage;afx_msgLRESULTOnPalmServerHWND(WPARAMwParam,LPARAMlParam);//消息处理函数}//Dlg.cpp//PalmServerHWND#defineWM_PS_HWND9034//定义消息BEGIN_MESSAGE_MAP(CDlgPalmProbe,CDialogEx)ON_MESSAGE(WM_PS_HWND,CDlgPalmProbe::OnPalmServerHWND)//绑定消息和消息处理函数END_MESSAGE_MAP()//ReceivethePalmProbeHWNDfromC#programLRESULTCDlgPalmProbe::OnPalmServerHWND(WPARAMwParam,LPARAMlParam){hProbeServerBySendMessage(HWND)wParam;longa(WPARAM)hProbeServerBySendMessage;_cprintf(C#HWND:%ld

,a);return0;}

#总结除了这种方法我也试过利用文本中介写入句柄再去读取的方法。但是读写方法可能会受制于权限所以不推荐这种方法。读写注册表倒是一个相对好一点的办法但是我没试过。总之相较于读写这种直接通过消息处理的方法还是更方便快捷而且经过测试确实也能解决上述的问题值得大家去试一试的。有什么问题或想法欢迎在评论提出我看到会及时回复的谢谢

毫无疑问,当需要找窗口句柄时,首先想到的自然是FindWindow(),这个函数能够在系统中帮我们找到所需窗口的句柄。该函数的参数有两个,第一个是所找窗口的类名,第二个是所找窗口的名字。一般来说,第一个参数可以填...

展开全文

相关阅读

  • windows 11 首次更新
  • findwindow function winuser h
  • findwindow function winuwin7 findwindowser h
  • 免责声明: 凡标注转载/编译字样内容并非本站原创,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。如果你觉得本文好,欢迎推荐给朋友阅读;本文链接: https://m.nndssk.com/post/52117.html
    猜你喜欢
    最新应用
    热门应用