FindWindow获得不到自己想要窗体的句柄?

hei_an 2008-06-26 10:39:15
[DllImport("user32.dll")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("user32.dll")]
static extern IntPtr SetActiveWindow(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
////////////////////////////////////////////////////////////////////////////
IntPtr intptr = FindWindow(null, "QQ自由幻想(2.06测试版");

SetActiveWindow(intptr);

ShowWindow(intptr, SW_SHOWNOACTIVATE);
if (intptr == IntPtr.Zero)
{
tmrHM.Enabled = false;
tmrJN1.Enabled = false;
tmrJN3.Enabled = false;
tmrJN4.Enabled = false;
tmrJN5.Enabled = false;
tmrJN2.Enabled = false;

MessageBox.Show("当前窗口找不到自由幻想", "XX练级器");
return;
}
else
{
tmrHM.Enabled = false;
tmrJN1.Enabled = false;
tmrJN3.Enabled = false;
tmrJN4.Enabled = false;
tmrJN5.Enabled = false;
tmrJN2.Enabled = false;


}
将窗口标题改成像记事本这类窗口,运行没问题,这个窗口是一个游戏窗口,打开时当然有更新,登录之类,最后弹出来游戏窗口!用Sky++,能看到句柄 窗口标题,用FindWindow,返回值null!谢谢!
...全文
808 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
wlovew 2008-06-27
  • 打赏
  • 举报
回复
跟着学习。
s208ping 2008-06-27
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 BIGBIRDINWOODS 的回复:]
学习一下了,,,,
[/Quote]
noky 2008-06-27
  • 打赏
  • 举报
回复

"The FindWindow function retrieves a handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows. This function does not perform a case-sensitive search.

To search child windows, beginning with a specified child window, use the FindWindowEx function."
1.以上是MSDN中的解释。这个函数只能查找顶层窗体,不能查找子窗体。
2.检查一下你的窗体标题,看看你要查找的和原本的窗体标题是否相同。
3.检查一下窗体所在进程是否在运行!

BIGBIRDINWOODS 2008-06-27
  • 打赏
  • 举报
回复
学习一下了,,,,
skinfeature 2008-06-27
  • 打赏
  • 举报
回复
FindWindow这个函数不会查找子窗口的,确认下你要找的窗口是顶层窗口。如果你要找的是子窗口,用FindWindowEx。
家鸣 2008-06-27
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 hei_an 的回复:]
这个游戏,启动后先是调用一个LIVEUPDATE.EXE更新程序然后回到登录窗口,用了CE工具都找不到这个窗体,报窗体已关闭?进程也是不允许访问,何解呢?
[/Quote]
可能这个本身有防外挂功能,只能多试下其它的方法。 再用EnumWindows试试

public delegate bool EnumWindowsProcCallBack(int hwnd, int lParam);

[DllImport("user32.dll")]
private static extern int GetWindowText(int hWnd, StringBuilder title, int size);
[DllImport("user32.dll")]
private static extern bool IsWindowVisible(int hWnd);
[DllImport("user32.dll")]
public static extern int EnumWindows(EnumWindowsProcCallBack proc, int lParam);
[DllImport("user32.dll")]
public static extern int GetWindowThreadProcessId (int hwnd, ref int lpdwProcessId);
public void test()
{
EnumWindowsProcCallBack EnumWindowsProc = new EnumWindowsProcCallBack(myEnumWindowsProc);
EnumWindows(EnumWindowsProc, 0);
}
//call back function
public static bool myEnumWindowsProc(int hwnd, int lParam)
{ //下面这些可能有用的信息
int processId;
bool isVisible = IsWindowVisible(hWnd);
GetWindowThreadProcessId(hwnd, ref processId);//取进程ID
StringBuilder title = new StringBuilder(255);
GetWindowText(hWnd, title, 255);
//return false;//stop EnumWindows
return true;
}
贫僧又回来了 2008-06-27
  • 打赏
  • 举报
回复
参考下这帖子,不知道有用吗
http://topic.csdn.net/u/20080627/13/b3fe3241-264a-4be6-ba1e-b1ae96e7a587.html
hei_an 2008-06-27
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 dk385 的回复:]
如:

C# code
Process[] processList = Process.GetProcessesByName("EXCEL");
IntPtr MainWindowIntPtr = processList[0].MainWindowHandle;
[/Quote]

这个游戏,启动后先是调用一个LIVEUPDATE.EXE更新程序然后回到登录窗口,用了CE工具都找不到这个窗体,报窗体已关闭?进程也是不允许访问,何解呢?
家鸣 2008-06-26
  • 打赏
  • 举报
回复
如:

Process[] processList = Process.GetProcessesByName("EXCEL");
IntPtr MainWindowIntPtr = processList[0].MainWindowHandle;
家鸣 2008-06-26
  • 打赏
  • 举报
回复
如果还是不行的话,那么换一种思路,可以根据进程的名字取得进程主窗口。具体参考Process类.
hei_an 2008-06-26
  • 打赏
  • 举报
回复
是顶层窗口,Spy++上看到的..还有其它方法吗?
家鸣 2008-06-26
  • 打赏
  • 举报
回复
FindWindow这个函数不会查找子窗口的,确认下你要找的窗口是顶层窗口。如果你要找的是子窗口,用FindWindowEx。

[DllImport("user32.dll",EntryPoint="FindWindowEx")]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
hei_an 2008-06-26
  • 打赏
  • 举报
回复
补充一下,任务管理器里也看不到这个窗口???

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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