[郁闷的问题]C#的窗口句柄,传入C++的dll问题

pisces007 2006-06-16 08:39:49
现在面临的问题是把C#中的窗口句柄传入到C++写的dll中,
应该如何解决?
谢谢
...全文
429 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
pisces007 2006-06-16
  • 打赏
  • 举报
回复
wxdl1981(沉默之狼)
因为调用的dll需要一个窗口句柄。
hdt(倦怠)
这个,WPF是Windows的新一代用户界面框架。。。。
kssys()
那么如何得到这个窗口中的某个控件的句柄呢?
kssys 2006-06-16
  • 打赏
  • 举报
回复
不知道wfp是啥,以下是C#,根据窗口名称查找句柄:

[DllImport("user32.dll")]
private static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
private static extern IntPtr GetWindow(IntPtr hWnd, int wCmd);
[DllImport("user32.dll")]
private static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int cch);

private const int WM_SETTEXT = 0xC;
private const int GW_CHILD = 5;
private const int GW_HWNDFIRST = 0;
private const int GW_HWNDNEXT = 2;

public static IntPtr GetHandByCaption(string FindCaption)
{
  //获取桌面句柄
  IntPtr hWnd = GetWindow(GetDesktopWindow(), GW_CHILD);
  hWnd=GetWindow(hWnd,GW_HWNDFIRST);

  //循环对比窗体标题
  while(hWnd.ToInt32()!=0)
  {
    StringBuilder strCaption = new StringBuilder(256);

    GetWindowText(hWnd, strCaption, 256);
    if (strCaption.ToString().IndexOf(FindCaption) != -1)
      return hWnd;

    hWnd = GetWindow(hWnd, GW_HWNDNEXT);
  }

  return IntPtr.Zero;
}
真相重于对错 2006-06-16
  • 打赏
  • 举报
回复
wpf ???
wxdl1981 2006-06-16
  • 打赏
  • 举报
回复
奇怪的做法.
pisces007 2006-06-16
  • 打赏
  • 举报
回复
我的窗体是WPF的,类似于ASP.NET的窗体,
他没有Handle这个属性。。。。
真相重于对错 2006-06-16
  • 打赏
  • 举报
回复
form.Handle

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧