博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
查找当前所有顶级窗口
阅读量:4343 次
发布时间:2019-06-07

本文共 2766 字,大约阅读时间需要 9 分钟。

有时常需要查找当前有哪些窗口打开着,所以先用一种方法写下来:

效果:

2011060621151094.gif

//工程文件program Project1;uses  Forms,  Unit1 in 'Unit1.pas' {Form1};{$R *.res}begin  Application.Initialize;  Application.MainFormOnTaskbar := True;  Application.CreateForm(TForm1, Form1);  Application.Run;end.// 单元文件unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, StdCtrls, ExtCtrls;type  TForm1 = class(TForm)    Button1: TButton;    ListBox1: TListBox;    Label1: TLabel;    Button2: TButton;    procedure Button1Click(Sender: TObject);    procedure Button2Click(Sender: TObject);    procedure FormCreate(Sender: TObject);    procedure FormDestroy(Sender: TObject);    procedure ListBox1Click(Sender: TObject);  private    { Private declarations }  public    { Public declarations }  end;  function EnumWindowsProc(hwnd: HWND; lparam: Integer): Boolean ; stdcall;var  Form1: TForm1;  slist: TStringList;implementation{$R *.dfm}procedure TForm1.Button2Click(Sender: TObject);begin  ListBox1.Clear;end;procedure TForm1.FormCreate(Sender: TObject);begin  slist := TStringList.Create;end;procedure TForm1.FormDestroy(Sender: TObject);begin  slist.Free;end;procedure TForm1.ListBox1Click(Sender: TObject);begin  SetWindowText(Handle,ListBox1.Items[ListBox1.ItemIndex]);end;function EnumWindowsProc(hwnd: HWND; lparam: Integer):Boolean;var  buf: array[Byte] of char;  swnd: string;begin  GetWindowText(hwnd, buf, sizeof(buf)); //取得窗口标题  swnd := Inttostr(hwnd);  slist.Add('窗口句柄:'+swnd +'---'+'标题:'+ buf);  Result := True;    //重要end;procedure TForm1.Button1Click(Sender: TObject);begin  EnumWindows(@EnumWindowsProc, 0);  ListBox1.Items.Assign(slist);end;end.//窗体代码object Form1: TForm1  Left = 0  Top = 0  BorderIcons = [biSystemMenu, biMinimize]  Caption = 'Form1'  ClientHeight = 295  ClientWidth = 448  Color = clBtnFace  Font.Charset = DEFAULT_CHARSET  Font.Color = clWindowText  Font.Height = -11  Font.Name = 'Tahoma'  Font.Style = []  OldCreateOrder = False  Position = poScreenCenter  OnCreate = FormCreate  OnDestroy = FormDestroy  PixelsPerInch = 96  TextHeight = 13  object Label1: TLabel    Left = 8    Top = 8    Width = 121    Height = 18    AutoSize = False    Caption = #24403#21069#30340#39030#23618#31383#21475#26377#65306  end  object Button1: TButton    Left = 352    Top = 48    Width = 75    Height = 41    Caption = #26597#25214    TabOrder = 0    OnClick = Button1Click  end  object ListBox1: TListBox    Left = 8    Top = 32    Width = 298    Height = 257    ItemHeight = 13    TabOrder = 1    OnClick = ListBox1Click  end  object Button2: TButton    Left = 352    Top = 184    Width = 75    Height = 41    Caption = #28165#31354    TabOrder = 2    OnClick = Button2Click  endend

转载于:https://www.cnblogs.com/boltwolf/archive/2011/06/06/2073881.html

你可能感兴趣的文章
搜索框键盘抬起事件2
查看>>
阿里百川SDK初始化失败 错误码是203
查看>>
透析Java本质-谁创建了对象,this是什么
查看>>
BFS和DFS的java实现
查看>>
关于jquery中prev()和next()的用法
查看>>
一、 kettle开发、上线常见问题以及防错规范步骤
查看>>
eclipse没有server选项
查看>>
CRC码计算及校验原理的最通俗诠释
查看>>
使用Gitbook来编写你的Api文档
查看>>
jquery扩展 $.fn
查看>>
Markdown指南
查看>>
influxDB的安装和简单使用
查看>>
JPA框架学习
查看>>
JPA、JTA、XA相关索引
查看>>
机器分配
查看>>
php opcode缓存
查看>>
springcloud之Feign、ribbon设置超时时间和重试机制的总结
查看>>
观看杨老师(杨旭)Asp.Net Core MVC入门教程记录
查看>>
UIDynamic(物理仿真)
查看>>
Windows下安装Redis
查看>>