用delphi实现判断当前窗体活动窗体是不是QQ登录窗体怎么写?

shijiheima 2009-11-16 07:07:22
大家帮忙 看下吧!!!
...全文
139 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
babys 2009-11-17
  • 打赏
  • 举报
回复
if pos('qq2009',LowerCase(szCaption))>0 then这句就是关键了哈。一定要记住在能区分窗体的时候尽量把字符串取长点儿,当前窗口就用ACTIVEWINDOW就可以了。
procedure TForm1.Button1Click(Sender: TObject);
var
buffer:array[0..255] of Char;
begin
getwindowtext(GetActiveWindow(),buffer,256);
showmessage(strpas(buffer));
end;
fenshm 2009-11-17
  • 打赏
  • 举报
回复
up
gdgzcbm 2009-11-17
  • 打赏
  • 举报
回复
学习
shijiheima 2009-11-16
  • 打赏
  • 举报
回复
还有没有别的写法的 !!我再参考参考!!!!
sunnauq 2009-11-16
  • 打赏
  • 举报
回复
学习
gyk120 2009-11-16
  • 打赏
  • 举报
回复
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,shellapi, StdCtrls,Tlhelp32;

function EnumWindowsProc(hwnd:HWND;lParam:DWORD):boolean; stdcall;
var
szCaption: array[0..256] of Char;
c,h:integer;
begin
GetWindowText(hwnd,szCaption,127);
if length(szCaption)>0 then
begin
if trim(szCaption)<>'' then
if pos('qq2009',LowerCase(szCaption))>0 then
showmessage(inttostr(HWND));
{GetWindowThreadProcessId(HWND,@c); //这里是窗体名枚举 想判断某个窗体在这里写就成

if c=FindProcessID('calc.exe') then
showmessage(inttostr(HWND));

{if pos('QQ2009',szCaption) >0 then
begin
showmessage(szCaption);
h:=FindWindow(nil,szCaption);
showmessage(inttostr(h));
end;}
end;
result:=TRUE;
end;



function FindProcessID(s:string):integer;
var
found,find:boolean;
FSnapshotHandle:tHANDLE;
lppe:TProcessEntry32;
begin
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //CreateToolhelp32Snapshot函数得到进程快照
Find:=False;
lppe.dwSize := Sizeof(lppe); //初始化
found := Process32First(FSnapshotHandle, lppe); //Process32First 得到一个系统快照里第一个进程的信息
while found do
begin
if LowerCase(ExtractFileName(lppe.szExeFile))=LowerCase(s) then
begin
Result:=lppe.th32ProcessID; //找到进程返回ID
find:=true;
CloseHandle(FSnapshotHandle);
exit;
end;
found := Process32Next(FSnapshotHandle, lppe);
end;
CloseHandle(FSnapshotHandle);
if find=False then
Result:=0; //找不到进程返回0
end;


procedure TForm1.Button2Click(Sender: TObject);
begin
EnumWindows(@EnumWindowsProc,0);
end;
hjkto 2009-11-16
  • 打赏
  • 举报
回复
查找文本标题“QQ2009”

查找类名“TXGuiFoundation”
vhandle:=findwindow('TXGuiFoundation',pchar('QQ2009'));

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧