获取窗体句柄,最大化最小化窗体

//通过程序标题查到程序句柄
function TfmPrintSet2.FindWindowByTitle(WindowTitle: string): Hwnd;
var
NextHandle: Hwnd;
NextTitle: array[0..260] of char;
begin
// 获取第一个
NextHandle := GetWindow(Application.Handle, GW_HWNDFIRST);
while NextHandle > 0 do
begin
// 获取标题
GetWindowText(NextHandle, NextTitle, 255);
if Pos(WindowTitle, StrPas(NextTitle)) <> 0 then
begin
Result := NextHandle;
Exit;
end
else
// 获取下一个
NextHandle := GetWindow(NextHandle, GW_HWNDNEXT);
end;
Result := 0;
end;

//最大化窗体
procedure TfmPrintSet2.MaxExWindow(TitleName: string);
var
Indicador: Hwnd;
begin
// 获取window通过程序标题名字
Indicador := FindWindowByTitle(TitleName);
// if finded
if (Indicador <> 0) then
begin
// Minimize
ShowWindow(Indicador, SW_MINIMIZE);
ShowWindow(Indicador, SW_MAXIMIZE); //SW_MINIMIZE
end;
end;

猜你喜欢

转载自www.cnblogs.com/zyb2016/p/11243694.html
今日推荐