//FindWindow 查找窗口
//FindWindowEx查找子窗口
//EnumWindows列举屏幕上的所有顶层窗口,如果回调函数成功则返回非零,失败则返回零
//GetWindowText返回窗口的标题

一、首先要先导入要使用到的win api

[DllImport("user32.dll")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("User32.dll")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern int EnumWindows(EnumWindowsProc hWnd, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern int GetWindowText(IntPtr hWnd, StringBuilder lpText, int nCount);
[DllImport("user32.dll")]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, StringBuilder lParam); private const int WM_GETTEXT = 0x00D;
private static string _url; //定义委托 delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam); static void Main(string[] args)
{
string url = GetWindowText(); Console.WriteLine(url);
Console.ReadKey(); } public static string GetWindowText()
{ IntPtr chrom = IntPtr.Zero;
EnumWindowsProc enwdproc = new EnumWindowsProc(FindChrom); if (EnumWindows(enwdproc, IntPtr.Zero) >= )
return _url;
else
return null;
} //回调函数
static bool FindChrom(IntPtr hWnd, IntPtr lParam)
{ var sb = new StringBuilder();
GetWindowText(hWnd, sb, sb.Capacity); if (sb.ToString() != String.Empty)
{
if (hWnd != IntPtr.Zero)
{
IntPtr tb = FindWindowEx(hWnd, new IntPtr(), "Chrome_OmniboxView", ""); //Chrome_OmniboxView是通过Spy++获得的 StringBuilder strbld = new StringBuilder();
SendMessage(tb, WM_GETTEXT, , strbld);
_url = strbld.ToString();
}
return false; }
//回调函数有返回值 return true; }

最新文章

  1. Nginx:Pitfalls and Common Mistakes
  2. android 开发环境
  3. MySQL压缩包安装
  4. UVa 10498 Happiness! (线性规划)
  5. 借助linq2db使用Linq访问MySQL
  6. HDU 5029 Relief grain 树链剖分打标记 线段树区间最大值
  7. sql执行计划
  8. table 西边框样式
  9. Javascript 中的变量
  10. ReactNative setNativeProps
  11. C++学习之路—多态性与虚函数(二)纯虚函数与抽象类
  12. Ubuntu16 Nginx的安装与基本配置
  13. C语言--第2次作业
  14. mybatis逆向工程(MyBatis Generator)
  15. Android Studio & HTTP Proxy
  16. Leetcode 283.移动零 By Python
  17. Sql server 使用drop database 语句,无法删除正在使用的数据库的解决办法
  18. JSON XSS
  19. POJ 1579 Function Run Fun 记忆化递归
  20. less的编译

热门文章

  1. root-me web server 20-30 writeup
  2. (译)Getting Started——1.3.2 Using Design Patterns(使用设计模式)
  3. 1.2.3 Task and Back Stack - 任务和回退堆
  4. mybatis慢查询配置
  5. Dump 分析法
  6. 【vijos】1629 八(容斥原理+dfs)
  7. Torch-RNN运行过程中的坑 [1](读取Lua非空table,size为0)
  8. DevExpress 控件使用技巧
  9. ChemDraw Pro移动原子有什么方法
  10. Gabor变换、Gabor滤波器