C#通过Win32 API操作IE浏览器 --- 获得IE的URL
来源:互联网 发布:vscode c 生成exe 编辑:程序博客网 时间:2024/05/02 04:57
Windows操作系统是一个消息驱动的操作系统,所以要想操作Windows操作系统中的任何控件,都可以用消息来进行。Windows操作系统开放了大量的API给用户,用户可以通过这些API从底层来操作Windows系统中的控件,并且是以消息的方式进行的,下面以C#通过Win32 API来操作IE浏览器 --- 获得IE的URL为例: 至于API消息函数的原型,可以在MSDN中查到,至于API消息函数的原型在C#中怎么用C#语言的元素表示出来,可以通过以下的例子看出来。
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices; //操作Win32API必须要引入的命名空间
namespace IEManipulation
{
public class IEManipulation
{
[DllImport("User32.dll")] //User32.dll是Windows操作系统的核心动态库之一
static extern int FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.dll")]
static extern int FindWindowEx(int hwndParent, int hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("User32.dll")]
static extern int GetWindowText(int hwnd, StringBuilder buf, int nMaxCount);
[DllImport("User32.dll")]
static extern int SendMessage(int hWnd, int Msg, int wParam, StringBuilder lParam);
const int WM_GETTEXT = 0x000D; //获得文本消息的16进制表示
/// <summary>
/// Get the URL of the current opened IE
/// </summary>
public static string GetURL()
{
int parent = FindWindow("IEFrame", null);
int child = FindWindowEx(parent, 0, "WorkerW", null);
child = FindWindowEx(child, 0, "ReBarWindow32", null);
child = FindWindowEx(child, 0, "ComboBoxEx32", null);
child = FindWindowEx(child, 0, "ComboBox", null);
child = FindWindowEx(child, 0, "Edit", null); //通过SPY++获得地址栏的层次结构,然后一层一层获得
StringBuilder buffer = new StringBuilder(1024);
//child表示要操作窗体的句柄号
//WM_GETTEXT表示一个消息,怎么样来驱动窗体
//1024表示要获得text的大小
//buffer表示获得text的值存放在内存缓存中
int num = SendMessage(child, WM_GETTEXT, 1024, buffer);
string URL = buffer.ToString();
return URL;
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices; //操作Win32API必须要引入的命名空间
namespace IEManipulation
{
public class IEManipulation
{
[DllImport("User32.dll")] //User32.dll是Windows操作系统的核心动态库之一
static extern int FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.dll")]
static extern int FindWindowEx(int hwndParent, int hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("User32.dll")]
static extern int GetWindowText(int hwnd, StringBuilder buf, int nMaxCount);
[DllImport("User32.dll")]
static extern int SendMessage(int hWnd, int Msg, int wParam, StringBuilder lParam);
const int WM_GETTEXT = 0x000D; //获得文本消息的16进制表示
/// <summary>
/// Get the URL of the current opened IE
/// </summary>
public static string GetURL()
{
int parent = FindWindow("IEFrame", null);
int child = FindWindowEx(parent, 0, "WorkerW", null);
child = FindWindowEx(child, 0, "ReBarWindow32", null);
child = FindWindowEx(child, 0, "ComboBoxEx32", null);
child = FindWindowEx(child, 0, "ComboBox", null);
child = FindWindowEx(child, 0, "Edit", null); //通过SPY++获得地址栏的层次结构,然后一层一层获得
StringBuilder buffer = new StringBuilder(1024);
//child表示要操作窗体的句柄号
//WM_GETTEXT表示一个消息,怎么样来驱动窗体
//1024表示要获得text的大小
//buffer表示获得text的值存放在内存缓存中
int num = SendMessage(child, WM_GETTEXT, 1024, buffer);
string URL = buffer.ToString();
return URL;
}
}
}
- C#通过Win32 API操作IE浏览器 --- 获得IE的URL
- C#通过Win32 API操作IE浏览器 --- 获得IE的URL
- python+win32+ie浏览器操作
- C#操作IE浏览器
- 通过指定Shell Embedding/IEFrame类窗口的句柄获得浏览器(IE)对象
- c# 控制IE浏览器
- c# 控制IE浏览器
- C#控制IE浏览器
- 用Visual C#打造个性化的IE浏览器IE
- C#获取当前IE地址栏的url
- C#获取当前IE的URL
- vb操作ie浏览器
- vba操作IE浏览器
- C# 获取IE浏览器的HTML内容
- 通过QAxWidget调用IE浏览器
- C#操作IE收藏夹
- C#操作IE浏览器 解决:COM 组件的调用返回了错误 HRESULT E_FAIL
- C#操作Win32 API
- 在Linux下安装和使用MySQL
- 绘制平行线
- 我对【纹理颜色混合】与【ALPHA混合】的理解
- 经典对白,超然人生
- 上传文件 JSP+java
- C#通过Win32 API操作IE浏览器 --- 获得IE的URL
- DataGrid数据导出excel文件,有时出现乱码解决方法。
- java日期函数2
- 北京拟严控“双外生”进京 近九成青年表示反对
- 高效能人士的9种性格(转载)
- 关于字符串逆序的问题
- 开放封闭原则--OCP
- 进制转换(一)
- 炎龙骑士团-黄金城之迷剧情