Set The Window Position of an application via command line

前端 未结 8 1183
轮回少年
轮回少年 2020-11-27 14:39

I have an application which start in 0x0 position of my desktop. I want to open it in center of my desktop. I do not want to open it and use a move command to move it into c

相关标签:
8条回答
  • 2020-11-27 15:20

    If you are happy to run a batch file along with a couple of tiny helper programs, a complete solution is posted here:
    How can a batch file run a program and set the position and size of the window? - Stack Overflow (asked: May 1, 2012)

    0 讨论(0)
  • 2020-11-27 15:21

    This probably should be a comment under the cmdow.exe answer, but here is a simple batch file I wrote to allow for fairly sophisticated and simple control over all windows that you can see in the taskbar.

    First step is to run cmdow /t to display a list of those windows. Look at what the image name is in the column Image, then command line:

    mycmdowscript.cmd imagename
    

    Here are the contents of the batch file:

    :: mycmdowscript.cmd
    
    @echo off
    SETLOCAL ENABLEDELAYEDEXPANSION
    
    SET IMAGE=%1
    SET ACTION=/%2
    SET REST=1
    SET PARAMS=
    
    :: GET ANY ADDITIONAL PARAMS AND STORE THEM IN A VARIABLE
    
    FOR %%I in (%*) DO (
       IF !REST! geq 3 (
          SET PARAMS=!PARAMS! %%I
       )
       SET /A REST+=1
    )
    
    FOR /F "USEBACKQ tokens=1,8" %%I IN (`CMDOW /t`) DO (
         IF %IMAGE%==%%J (
    
         :: you now have access to the handle in %%I
         cmdow %%I %ACTION% !PARAMS!
    
         )
    )
    
    ENDLOCAL
    @echo on
    
    EXIT /b
    

    example usage

    :: will set notepad to 500 500
    
    mycmdowscript.cmd notepad siz 500 500
    

    You could probably rewrite this to allow for multiple actions on a single command, but I haven't tried yet.

    For this to work, cmdow.exe must be located in your path. Beware that when you download this, your AV program might yell at you. This tool has (I guess) in the past been used by malware authors to manipulate windows. It is not harmful by itself.

    0 讨论(0)
提交回复
热议问题