Script to open executables and snap to top left hand corner of desktop

不羁的心 提交于 2019-12-21 21:01:20

问题


I was just wonderin' in a .bat file, if there was a way to call an external .bat file, or even an *.exe and make it open so it 'snaps' to the top left hand corner of the screen ?

Cheers


回答1:


There is no direct way to position a Window from the Windows command prompt. You basically have the following options:

  • Use a GUI automation tool, e.g. AutoHotkey which lets you script window actions. AutoHotkey e.g. offers the WinMove command:

    Run, calc.exe
    WinWait, Calculator
    WinMove, 0, 0 ; Move the window found by WinWait to the upper-left corner of the screen.
    
  • Use PowerShell, e.g. with the WASP snapin (http://wasp.codeplex.com/).

  • Write a short program in C/C++/.NET that will position the active Window at position 0,0 of your main screen.

A very basic program in C#, that takes a window caption as parameter could look like that:

using System;
using System.Runtime.InteropServices;

class Program
{
    public const int SWP_NOSIZE = 0x0001;
    public const int SWP_NOZORDER = 0x0004;

    [DllImport("user32.dll", SetLastError = true)]
    private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);

    [DllImport("user32.dll", SetLastError = true)]
    static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

    static void Main(string[] args)
    {
        IntPtr handle = FindWindow(null, args[0]);
        SetWindowPos(handle, IntPtr.Zero, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
    }
}



回答2:


in cmd box type help start.

example: start /MAX "xxx.bat"




回答3:


Use the start command.




回答4:


It's a bit messy but I think it can be done.

You will need to install two programs:
AutoIt
Winsplit Revolution

Create an autoit script to:
1. open the program or batch file you want
2. Wait untill the program is open
3. Make the program the active window
4. Call a ctrl+alt+7, "Send("^!7")" (Winsplit Revolution shortcut to send program to top left corner)
5. End script

If i have time later I'll try to script it



来源:https://stackoverflow.com/questions/1872470/script-to-open-executables-and-snap-to-top-left-hand-corner-of-desktop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!