type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
HandleList: TStringList;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
//현재 떠 있는 모든 프로그램의 핸들값 잡기.
function EnumWindowsProc(Wnd: HWND; StrList: TStringList): BOOL; stdcall;
var
caption: Array [0..128] of Char;
begin
Result := True;
if {skip invisible windows}
IsWindowVisible(Wnd) and
{only process truly top-level windows. GetWindowLong must be used, not GetParent}
((GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) or
(HWND(GetWindowLong(Wnd, GWL_HWNDPARENT)) = GetDesktopWindow)) and
{skip WS_EX_TOOLWINDOW windows}
((GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW) = 0) then
begin
SendMessage(Wnd, WM_GETTEXT, Sizeof(caption), integer(@caption));
StrList.AddObject(caption, TObject(Wnd));
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
HandleList := TStringList.Create;
EnumWindows(@EnumWindowsProc, Integer(HandleList));
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
HandleList.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
Wnd: HWND;
begin
for i := 0 to HandleList.Count-1 do
begin
Wnd := HWND(HandleList.Objects[i]);
// 이 프로그램이 아니고 minimized(iconic)가 아니면...
if (Wnd <> 0) and (Wnd <> Application.Handle) then
if not IsIconic(Wnd) then
begin
ShowWindow(Wnd, SW_HIDE);
ShowWindow(Wnd, SW_MINIMIZE);
end;
end;
end;
답변 감사합니다만
게임(스타..)이 실행중일 경우
그냥 윈도우상의 프로그램만 Minimize시키고
제가 만든 프로그램을 띄우면 Max로 띄웠는데도
작게 나타나더라구요 그런데 윈도우키와 'M'을 누르면
모든 프로그램이 Minimize되고 회상도도 제대로 나왔습니다.
그래서 지금 그 방법을 찾고 있는데 잘 안되네요..
지금 함 코딩 간단히 해보니까 되네요..
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
HandleList: TStringList;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
//현재 떠 있는 모든 프로그램의 핸들값 잡기.
function EnumWindowsProc(Wnd: HWND; StrList: TStringList): BOOL; stdcall;
var
caption: Array [0..128] of Char;
begin
Result := True;
if {skip invisible windows}
IsWindowVisible(Wnd) and
{only process truly top-level windows. GetWindowLong must be used, not GetParent}
((GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) or
(HWND(GetWindowLong(Wnd, GWL_HWNDPARENT)) = GetDesktopWindow)) and
{skip WS_EX_TOOLWINDOW windows}
((GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW) = 0) then
begin
SendMessage(Wnd, WM_GETTEXT, Sizeof(caption), integer(@caption));
StrList.AddObject(caption, TObject(Wnd));
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
HandleList := TStringList.Create;
EnumWindows(@EnumWindowsProc, Integer(HandleList));
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
HandleList.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
Wnd: HWND;
begin
for i := 0 to HandleList.Count-1 do
begin
Wnd := HWND(HandleList.Objects[i]);
// 이 프로그램이 아니고 minimized(iconic)가 아니면...
if (Wnd <> 0) and (Wnd <> Application.Handle) then
if not IsIconic(Wnd) then
begin
ShowWindow(Wnd, SW_HIDE);
ShowWindow(Wnd, SW_MINIMIZE);
end;
end;
end;
end.