有什么办法可以查出,一样的窗口,有几个...

fedex2 2003-08-20 12:28:58
有什么办法,可以查出一样的窗口打开了几个.

比如,我打开了3个QQ,那有什么办法可以用DELPHI查出,打开了几个QQ窗口.
...全文
47 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiadrun 2003-08-20
  • 打赏
  • 举报
回复
权举进程
sy_315 2003-08-20
  • 打赏
  • 举报
回复
不是说窗口的问题
规化为有几个一样的application的问题
我这里写出一个当前运行实例的枚举,这个方法很多地方可都非常有用:
program Project1;

uses
Forms,
Unit2 in 'Unit2.pas';

{$R *.res}

begin
if hprevinst <> 0 then
begin
activatepreviousinstance;
halt;
end;
Application.Initialize;
//Application.CreateForm(TForm1, Form1);
Application.Run;
end.


unit unit2;

interface

uses
winprocs,wintypes,sysutils,windows;

type
phwnd = ^hwnd;

function enumapps(wnd: hwnd; targetwindow : phwnd): bool;export;
{*
* activatepreviousinstance作用是发现已经有此实例存在时将此实例设为系统的焦点
*}
procedure activatepreviousinstance;//定义一个过程

implementation

function enumapps(wnd: hwnd; targetwindow : phwnd): bool;
var
classname : array[0..30] of char;

begin
result := true; // = -6 const GWW_HINSTANCE =-6;
if getwindowword(wnd,-6) = hprevinst then begin
getclassname(wnd,classname,30);
if stricomp(classname,'tapplication')=0 then begin
targetwindow^ := wnd;
result := false;
end;
end;
end;

procedure activatepreviousinstance;
var
previnstwnd : hwnd;
begin
previnstwnd := 0;
enumwindows(@enumapps,longint(@previnstwnd));
if previnstwnd <> 0 then
showwindow(previnstwnd,sw_restore)
else
//showmessage('sss');
bringwindowtotop(previnstwnd);

end;
end.

1,183

社区成员

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

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