2015-01-15 27 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

相关问题