掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
CreateProcessでウィンドウの位置と大きさを指定 (ID:36566)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
またまた失礼しました. CreateProcessで位置とサイズを指定しても無効なので,その部分のコードは不要でした. unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private 宣言 } public { Public 宣言 } end; var Form1: TForm1; implementation {$R *.dfm} function EnumTopWindow(hTopWnd: HWND; lp: LPARAM): BOOL; stdcall; var p: LPDWORD; processId: DWORD; begin result := true; GetWindowThreadProcessId(hTopWnd, @processId); p := LPDWORD(lp); if (processId = p^) and (GetWindow(hTopWnd,GW_OWNER) = 0) then begin p^ := hTopWnd; result := false; end; end; function ExecAndGetWindow(ExeAppStr:string):HWND; var SI:TStartupInfo; PI:TProcessInformation; ret,dw: DWORD; WaitCount:integer; begin result := 0; FillChar(SI,SizeOf(SI),#0); SI.cb := SizeOf(TStartupInfo); SI.dwFlags := STARTF_USESHOWWINDOW; SI.wShowWindow := SW_HIDE; if not CreateProcess(nil,PChar(ExeAppStr),nil,nil,false,0,nil,nil,SI,PI) then exit else begin repeat ret := WaitForInputIdle(PI.hProcess,50); Application.ProcessMessages; until ret <> WAIT_TIMEOUT; WaitCount := 0; repeat Sleep(100); if ret = 0 then begin dw := PI.dwProcessId; EnumWindows(@EnumTopWindow, LPARAM(@dw)); if dw <> PI.dwProcessId then result := dw; end; Inc(WaitCount); until IsWindow(dw) or (WaitCount > 5); CloseHandle(PI.hThread); CloseHandle(PI.hProcess); end; end; procedure TForm1.Button1Click(Sender: TObject); var hMainWnd : HWND; begin hMainWnd := ExecAndGetWindow('Notepad.exe'); MoveWindow(hMainWnd,0,0,400,500,True); ShowWindow(hMainWnd,SW_SHOW); end; end.
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.