델파이로 외부 응용 프로그램을 최소화하십시오
문제
델파이 애플리케이션에서 제어 할 수없는 외부 응용 프로그램을 최소화 할 수있는 방법이 있습니까?
예를 들어, Notepad.exe는 최소화하려는 응용 프로그램을 제외하고는 하나의 인스턴스 만 있습니다.
해결책
당신이 사용할 수있는 Findwindow 응용 프로그램 핸들을 찾으려면 쇼 와디 그것을 최소화합니다.
var
Indicador :Integer;
begin
// Find the window by Classname
Indicador := FindWindow(PChar('notepad'), nil);
// if finded
if (Indicador <> 0) then begin
// Minimize
ShowWindow(Indicador,SW_MINIMIZE);
end;
end;
다른 팁
저는 델파이 전문가가 아니지만 Win32 API를 호출 할 수 있다면 FindWindow 및 Showwindow를 사용하여 앱에 속하지 않더라도 창을 최소화 할 수 있습니다.
감사합니다. 결국 수정 된 버전을 사용했습니다. 네 프탈리 코드, 나는 다른 사람이 향후 같은 문제가있는 경우 아래에 포함시켰다.
FindWindow(PChar('notepad'), nil);
항상 0을 반환하고 있었으므로 내가 찾은 이유를 찾는 동안 이 기능 그것은 HWND를 발견하고 치료를 받았습니다.
function FindWindowByTitle(WindowTitle: string): Hwnd;
var
NextHandle: Hwnd;
NextTitle: array[0..260] of char;
begin
// Get the first window
NextHandle := GetWindow(Application.Handle, GW_HWNDFIRST);
while NextHandle > 0 do
begin
// retrieve its text
GetWindowText(NextHandle, NextTitle, 255);
if Pos(WindowTitle, StrPas(NextTitle)) <> 0 then
begin
Result := NextHandle;
Exit;
end
else
// Get the next window
NextHandle := GetWindow(NextHandle, GW_HWNDNEXT);
end;
Result := 0;
end;
procedure hideExWindow()
var Indicador:Hwnd;
begin
// Find the window by Classname
Indicador := FindWindowByTitle('MyApp');
// if finded
if (Indicador <> 0) then
begin
// Minimize
ShowWindow(Indicador,SW_HIDE); //SW_MINIMIZE
end;
end;
FindWindow (PCHAR ( 'Notepad'), NIL)는 제목별로 창을 찾으려면 FindWindow (NIL, PCHAR ( 'Notepad')) 여야합니다.
제휴하지 않습니다 StackOverflow