如何调用FindWindow API获取主窗体
来源:互联网 发布:淘宝代理加盟的骗局 编辑:程序博客网 时间:2024/05/19 13:06
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace HtmlShow
{
/**/
/// <summary>
/// This class is to find the given window's child window accroding to the given child window's name.
/// The useage: FindWindow fw = new FindWindow(wndHandle, "ChildwndClassName"); IntPtr ip = fw.FoundHandle;
/// I adapt the code from Paul DiLascia,who is the MSDN Magazine's writer.
/// The original class is named CFindWnd which is written in C++, and you could get it on Internet.
/// www.pinvoke.net is a great website.It includes almost all the API fuctoin to be used in C#.
/// </summary>
class FindWindow
{
[DllImport("user32")]
[return: MarshalAs(UnmanagedType.Bool)]
//IMPORTANT : LPARAM must be a pointer (InterPtr) in VS2005, otherwise an exception will be thrown
private static extern bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr i);
//the callback function for the EnumChildWindows
private delegate bool EnumWindowProc(IntPtr hWnd, IntPtr parameter);
//if found return the handle , otherwise return IntPtr.Zero
[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
private string m_classname; // class name to look for
private IntPtr m_hWnd; // HWND if found
public IntPtr FoundHandle
{
get { return m_hWnd; }
}
// ctor does the work--just instantiate and go
public FindWindow(IntPtr hwndParent, string classname)
{
m_hWnd = IntPtr.Zero;
m_classname = classname;
FindChildClassHwnd(hwndParent, IntPtr.Zero);
}
//EnumChildWindows是API函数,能够遍历主窗口下所有子窗口。不过它的遍历过程是通过
//第二个参数即回调函数与程序员交互的。EnumChildWindows每找到一个窗口。就调用回调
//函数。回调函数如果返回false。遍历就会结束。
/**/
/// <summary>
/// Find the child window, if found m_classname will be assigned
/// </summary>
/// <param name="hwndParent">parent's handle</param>
/// <param name="lParam">the application value, nonuse</param>
/// <returns>found or not found</returns>
//The C++ code is that lParam is the instance of FindWindow class , if found assign the instance's m_hWnd
private bool FindChildClassHwnd(IntPtr hwndParent, IntPtr lParam)
{
EnumWindowProc childProc = new EnumWindowProc(FindChildClassHwnd);
IntPtr hwnd = FindWindowEx(hwndParent, IntPtr.Zero, this.m_classname, string.Empty);
if (hwnd != IntPtr.Zero)
{
this.m_hWnd = hwnd; // found: save it
return false; // stop enumerating
}
EnumChildWindows(hwndParent, childProc, IntPtr.Zero); // recurse redo FindChildClassHwnd
return true;// keep looking
}
}
}
//this.Handle是要查找窗口的父窗口,因为我使用的是webBrowser控件
FindWindow fw = new FindWindow(this.Handle, "Internet Explorer_Server");
hIE = fw.FoundHandle;
阅读全文
0 0
- 如何调用FindWindow API获取主窗体
- 如何查找窗体,获取窗体的句柄,Hwnd FindWindow函数
- 在C#中使用API函数FINDWINDOW查找窗体
- FindWindow,Win32 API函数
- 如何声明 findwindow 函数。
- findwindow(api)的具体用法
- c# api Showwindow/FindWindow/PostMessage
- MFC Findwindow找不到Autoit的窗体
- c# FindWindow 的用法,c#重写api,FindWindow
- 调用API 查找到窗体 并关闭
- FindWindow使用技巧;解决FindWindow的lpClassName获取不到句柄
- 如何在Windows窗体中调用系统调色板对话框,并获取用户所选择的颜色?
- 通过api获取句柄控制其他窗体
- 通过api获取句柄控制其他窗体
- 通过api获取句柄控制其他窗体
- 通过api获取句柄控制其他窗体
- findwindow
- findwindow
- vue.js原生组件化开发(一)——组件开发基础
- 477. Total Hamming Distance
- 一、几个概念
- iOS
- composer 的常见使用
- 如何调用FindWindow API获取主窗体
- 不同版本(2.3-3.1)web.xml文件的schema头部声明
- iOS开发-平台使用TestFlight进行Beta测试
- 网络&加密刷题笔记-2
- java中 Process的使用
- SpringMVC:ajax请求处理
- MongoDB 生态
- Eclipse 修改项目名称
- 关于MAVEN子父工程上传SVN以及从SVN检出过程简介