N
nfy
Unregistered / Unconfirmed
GUEST, unregistred user!
我想实现枚举某游戏的窗口(标题是Element Client),并可以一一隐藏窗口怎么实现
我自己写了一段代码,为什么只对一个窗口有效,当双开以上就不好使呢?窗口标题不一样的时候好使
CheckListBox1: TCheckListBox;
var
Form1: TForm1;
Nhwnd:HWND;
implementation
{$R *.dfm}
function EnumWinProc(Wnd : HWND; form1 : TForm1) : Boolean; Export; {$IFDEF Win32}StdCall;{$ENDIF}
var
WinText : Array[0..255] of Char;
begin
GetWindowText(Wnd, WinText, 255);
Result := True;
if (StrPas(WinText) = 'Element Client') then
Form1.CheckListBox1.Items.Add(StrPas(WinText));
end;
procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
EnumWindows(@EnumWinProc, LongInt(Self));
end;
procedure TForm1.CheckListBox1ClickCheck(Sender: TObject);
begin
if checklistbox1.Checked[checklistbox1.ItemIndex]=true then
begin
Nhwnd:=findwindow(NIL,pchar(Checklistbox1.Items[Checklistbox1.ItemIndex])); //转到选中窗口
ShowWindow(Nhwnd,Sw_Hide);
end else
begin
Nhwnd:=findwindow(NIL,pchar(Checklistbox1.Items[Checklistbox1.ItemIndex])); //转到选中窗口
ShowWindow(Nhwnd,sw_SHOW);
end;
end;
end.
我自己写了一段代码,为什么只对一个窗口有效,当双开以上就不好使呢?窗口标题不一样的时候好使
CheckListBox1: TCheckListBox;
var
Form1: TForm1;
Nhwnd:HWND;
implementation
{$R *.dfm}
function EnumWinProc(Wnd : HWND; form1 : TForm1) : Boolean; Export; {$IFDEF Win32}StdCall;{$ENDIF}
var
WinText : Array[0..255] of Char;
begin
GetWindowText(Wnd, WinText, 255);
Result := True;
if (StrPas(WinText) = 'Element Client') then
Form1.CheckListBox1.Items.Add(StrPas(WinText));
end;
procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
EnumWindows(@EnumWinProc, LongInt(Self));
end;
procedure TForm1.CheckListBox1ClickCheck(Sender: TObject);
begin
if checklistbox1.Checked[checklistbox1.ItemIndex]=true then
begin
Nhwnd:=findwindow(NIL,pchar(Checklistbox1.Items[Checklistbox1.ItemIndex])); //转到选中窗口
ShowWindow(Nhwnd,Sw_Hide);
end else
begin
Nhwnd:=findwindow(NIL,pchar(Checklistbox1.Items[Checklistbox1.ItemIndex])); //转到选中窗口
ShowWindow(Nhwnd,sw_SHOW);
end;
end;
end.