|
[DllImport("User32.dll", EntryPoint = "FindWindow")]
public static extern IntPtr FindWindow(string className, string windowName);
[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
private static extern IntPtr FindWindowEx(IntPtr hwndParent,IntPtr hwndChildAfter,string lpszClass,string lpszWindow);
// 本程序针对指定的另一程序窗体因此声名了如下变量
IntPtr Wnd = new IntPtr(0);// QQ主窗体
IntPtr sWnd = new IntPtr(0);// 消息盒子为“QQ”主窗体的子窗体
private void button1_Click(object sender, EventArgs e)
{
// 获得窗口句柄
Wnd = FindWindowEx((IntPtr)0, (IntPtr)0, null, "qq");// 窗体
sWnd = FindWindowEx(Wnd, (IntPtr)0, null, "消息盒子");
label4.Text = Wnd.ToString();//label4显示主窗体句柄
label4.ForeColor = Color.Red;//前景色为红色
label5.Text = sWnd.ToString();//label5显示子窗体句柄
}
以上代码子能获得主窗体句柄,子窗体句柄获取不到(显示为0)。该如何改?求代码,谢谢各位!
|
|