2015-01-15 62 views
3

我目前正在嘗試製作一個強制Chrome窗口在我的第二臺顯示器上打開的應用程序,但我無法找到使用參數進行操作,現在我想知道是否可以使用Delphi強制它在第二個屏幕或特定像素上打開?這僅僅是一個適用於我自己和我的個人電腦的應用程序,所以我可以將代碼放在特定的案例中。讓Chrome在第二臺顯示器上打開?

我目前使用這段代碼,啓動應用程序

procedure TForm1.BtnClick(Sender: TObject); 
begin 
ExecProcess(ChromePath,'',False); 
end; 

function ExecProcess(ProgramName, WorkDir: string; Wait: boolean): integer; 
var 
    StartInfo: TStartupInfo; 
    ProcInfo: TProcessInformation; 
    CreateOK: boolean; 
    ExitCode: integer; 
    dwExitCode: DWORD; 
begin 
    ExitCode := -1; 

    FillChar(StartInfo, SizeOf(TStartupInfo), #0); 
    FillChar(ProcInfo, SizeOf(TProcessInformation), #0); 
    StartInfo.cb := SizeOf(TStartupInfo); 

    if WorkDir <> '' then 
    begin 
    CreateOK := CreateProcess(nil, Addr(ProgramName[1]), nil, Addr(WorkDir[1]), 
     false, CREATE_NEW_PROCESS_GROUP + NORMAL_PRIORITY_CLASS, nil, nil, 
     StartInfo, ProcInfo); 
    end 
    else 
    begin 
    CreateOK := CreateProcess(nil, Addr(ProgramName[1]), nil, nil, false, 
     CREATE_NEW_PROCESS_GROUP + NORMAL_PRIORITY_CLASS, nil, Addr(WorkDir[1]), 
     StartInfo, ProcInfo); 
    end; 

    { check to see if successful } 

    if CreateOK then 
    begin 
    // may or may not be needed. Usually wait for child processes 
    if Wait then 
    begin 
     WaitForSingleObject(ProcInfo.hProcess, INFINITE); 
     GetExitCodeProcess(ProcInfo.hProcess, dwExitCode); 
     ExitCode := dwExitCode; 
    end; 
    end 
    else 
    begin 
    ShowMessage('Unable to run ' + ProgramName); 
    end; 

    CloseHandle(ProcInfo.hProcess); 
    CloseHandle(ProcInfo.hThread); 

    Result := ExitCode; 

end; 

我可以以某種方式在StartInfo.wShowWindow也許使用的東西?

+0

德爾福不一定是工具,我用了點。你有沒有考慮編寫JavaScript來打開一個新窗口並將其移動到你想要的位置? –

+0

您可以嘗試['ShellExecuteEx'](http://msdn.microsoft.com/en-us/library/windows/desktop/bb762154%28v=vs.85%29.aspx)指定['SHELLEXECUTEINFO '](http://msdn.microsoft.com/en-us/library/windows/desktop/bb759784%28v=vs.85%29.aspx)。 – kobik

回答

8

Chrome允許您通過--window-position和--window-size在命令行上傳遞位置和大小,我相信。詳情請查閱this page

例子:

:: Left screen is 1024x768 
"C:\chrome.exe" "https://www.example.com/?a=0&b=1" --window-position=0,0 --window-size=1024,768 --user-data-dir="C:\my-chrome1" 

:: Right screen is 1280x720 
:: Now chrome.exe we need to open in the second screen then we do it as below: 
:: we might want to use --kiosk but combination of --kiosk and --window-position wont work so in that case we can use --app 


"C:\chrome.exe" --app="https://www.example.com/?a=0&b=1" --window-position=1025,0 --window-size=1280,720 --user-data-dir="C:\my-chrome2" 
+0

是賴特。您只需將Chrome窗口的初始位置設置在第二臺顯示器上即可。欲瞭解更多信息如何可以做你自己的Delphi應用程序表單檢查這篇文章http://stackoverflow.com/questions/206400/start-program-on-a-second-monitor – SilverWarior

+0

謝謝@Nat,這工作完美!我到處尋找,但卻找不到任何關於這個的東西,這麼簡單但卻很難。 – user3464658

相關問題