delphi 使用WindowsAPI回调函数EnumWindowsProc获取系统窗口列表
2013-02-28 21:25
531 查看
本文地址转载请保留:/article/1515623.html
先上源码。再解释
主要使用的windowsAPI回调含函数EnumWindows。本文列举了系统的窗口。并将标题输出到了memo中
{----------------------------------------------------------------------------- 作者:sushengmiyan 2013.02.28 备注:仅供学习交流使用 博客:http://blog.csdn.net/sushengmiyan 功能:枚举系统窗口 -----------------------------------------------------------------------------} unit GetWinProcMainForm; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) mmo: TMemo; btn1: TButton; procedure btn1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; function EnumWindowsProc(hwnd: HWND; lParam: LPARAM): Boolean ;stdcall; implementation {$R *.dfm} procedure TForm1.btn1Click(Sender: TObject); begin // EnumWindows 专用的回调函数的格式: // function EnumWindowsProc( // hwnd: HWND; {找到的窗口句柄} // lParam: LPARAM {EnumWindows 传给的参数; 因为它是指针, 可传入, 但一般用作传出数据} // ): Boolean; stdcall; {函数返回 False 时, 调用它的 EnumWindows 将停止遍历并返回 False} Form1.mmo.Clear; EnumWindows(@EnumWindowsProc ,0); end; function EnumWindowsProc(hwnd: HWND; lParam: LPARAM): Boolean ;stdcall; var WindowText : string ; // 窗体标题 begin if ( IsWindowVisible(hwnd) or IsIconic(hwnd) ) and ( (GetWindowLong(hwnd, GWL_HWNDPARENT) = 0) or (GetWindowLong(hwnd, GWL_HWNDPARENT) = Longint(GetDesktopWindow)) )and ( GetWindowLong(hwnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW = 0 ) then {-----标题文字------} begin SetLength(WindowText, GetWindowTextLength(hwnd)+2); Getwindowtext(hwnd, Pchar(WindowText), GetWindowTextLength(hwnd)+2); WindowText := string( Pchar(WindowText)); Form1.mmo.Lines.Add(WindowText); end; Result := True; end; // EnumWindows 的功能是遍历所有顶层窗口 // function EnumWindows( // lpEnumFunc: TFNWndEnumProc; {回调函数指针} // lParam: LPARAM {给回调函数的参数, 它对应回调函数的第二个参数} // ): BOOL; stdcall; //成功与否, 其实是返回了回调函数的返回值 end.
先上源码。再解释
主要使用的windowsAPI回调含函数EnumWindows。本文列举了系统的窗口。并将标题输出到了memo中
相关文章推荐
- windows下使用WinPcap获取网卡列表
- C/C++获取Windows系统CPU和内存及硬盘使用情况
- C:\Windows\system32\MSVCR100.dll 没有被指定在 Windows 上运行,或者它包含错误。请尝试使用原始安装媒体重新安装程序,或联系您的系统管理员或软件供应商以获取支持。【解决办法】
- SWT获取windows系统窗口颜色
- proc文件系统中cpu,内存,网络数据使用情况获取(附检测网速源码)
- python windows下通过SSH获取linux系统cpu、内存、网络使用情况
- MFC获取系统的进程及列表控件使用
- Delphi使用Windows API 创建最基本的窗口程序Hello,Windows演示
- python使用wmi模块获取windows下的系统信息 监控系统
- 几个获取Windows系统信息的Delphi程序
- 几个获取Windows系统信息的Delphi程序
- MFC获取系统的进程及列表控件使用
- Pyqt 获取windows系统中已安装软件列表
- C/C++获取Windows系统CPU和内存及硬盘使用情况
- windows下如何获取系统音量(使用mixer api)
- 几个获取Windows系统信息的Delphi程序
- 使用API获取Windows系统的文件关联图标
- windows 下在一个进程中使用createprocess创建一个窗口进程,并获取这个窗口的HWND句柄
- [笔记]使用API函数 GetACP 获取Windows系统当前代码页
- C# 系统应用之获取Windows最近使用记录