gpt4 book ai didi

delphi - 如何指定外部控制台程序的窗口位置?

转载 作者:行者123 更新时间:2023-12-03 14:38:08 26 4
gpt4 key购买 nike

在我的 Win32 VCL 应用程序中,我使用 ShellExecute 来启动许多较小的 Delphi 控制台应用程序。有没有办法控制这些控制台窗口的位置?我想以屏幕为中心启动它们。

最佳答案

您可以使用CreateProcess并在其 STARTUPINFO 中指定窗口大小和位置结构参数。在下面的示例函数中,您可以指定控制台窗口的大小,然后根据指定的大小以当前桌面为中心。该函数返回进程句柄,如果成功,则返回0:

function RunConsoleApplication(const ACommandLine: string; AWidth,
AHeight: Integer): THandle;
var
CommandLine: string;
StartupInfo: TStartupInfo;
ProcessInformation: TProcessInformation;
begin
Result := 0;
FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
FillChar(ProcessInformation, SizeOf(TProcessInformation), 0);
StartupInfo.cb := SizeOf(TStartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_USEPOSITION or
STARTF_USESIZE;
StartupInfo.wShowWindow := SW_SHOWNORMAL;
StartupInfo.dwXSize := AWidth;
StartupInfo.dwYSize := AHeight;
StartupInfo.dwX := (Screen.DesktopWidth - StartupInfo.dwXSize) div 2;
StartupInfo.dwY := (Screen.DesktopHeight - StartupInfo.dwYSize) div 2;
CommandLine := ACommandLine;
UniqueString(CommandLine);
if CreateProcess(nil, PChar(CommandLine), nil, nil, False,
NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInformation)
then
Result := ProcessInformation.hProcess;
end;

关于delphi - 如何指定外部控制台程序的窗口位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12138836/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com