Size batch windows and set in specific location

心已入冬 提交于 2019-12-02 14:26:32

问题


I have multiple batch files I run to monitor my network links. I have one of the sets of code below. I run a single batch file to open all the files at once. I then have to reposition them across the top of the screen so I can open internet explorer to display solar winds across the bottom portion of the screen. I want to add to the code I am using to set where each window will open. Thank you in advance for the help.

@echo off
TITLE = VoIP Link
mode 50,20

    setlocal enableextensions enabledelayedexpansion

    rem Get address from command line
    set "address=13.2.9.6"
    if not defined address set "address=127.0.0.1"

    rem Configure levels and colors 
    rem The format is initialValue:color in value descending format
    set "levels=9000:4F 178:E0 146:2F 0:E0"

    rem infinite loop
    for /l %%i in () do (
        rem retrieve information from ping command
        set "rtt=Timed Out"
        set "ttl=?"
        for /f "tokens=3,4 delims==^<" %%a in (
            'ping -n 1 "%address%" ^| find "TTL="'
        ) do for /f "tokens=1 delims=m" %%c in ("%%a") do (
            set /a "rtt=%%c"
            set "ttl=%%b"
        )

        rem retrieve color
        set "color="
        for %%z in (%levels%) do for /f "tokens=1,2 delims=:" %%a in ("%%z") do (
            if not defined color if !rtt! geq %%a set "color=%%b"
        )

        rem show information
        if defined color color !color!
        echo(!time! - %address% - rtt[!rtt!]

        rem save to log
        for /f "tokens=1-4 delims=.:-/ " %%a in ("!date!") do (
            >> "%%b-%%c-%%d_%%a_VOIP Link 1.txt" echo(!date! - !time! - %address% - rtt[!rtt!]
        )

        rem wait and repeat the process
        ping -n 3 localhost >nul 2>nul 
    )

回答1:


If you start each window like this

start "A Window Title" cmd /k <optional command>

Goto the Window's properties. Set size and colour, untick Let Windows Position.

When you start it the same way in the future it will remember it's size and color.




回答2:


There is no batch file command to do that. Nor is there any scripting (or .NET) command to do anything to a window that isn't the code's (or started by it). Programs shouldn't mess with others'.

I have a handfull of VB6 very basic programs to resize, move, ontop, and change titlebar (with source code - each is 6 lines or so) at https://skydrive.live.com/redir?resid=E2F0CE17A268A4FA!121

Only API calls can do this so you need a real programming language. It is against the philosophy to do this.

Now CMD remembers it's windows position based on titlebar. Make shortcuts that take advantage of that, see HKEY_CURRENT_USER\Console

I suggest you look at the CMD title thing.

Hers a VB6 prog to move a window.

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Const SWP_DRAWFRAME = &H20
Public Const SWP_FRAMECHANGED = &H20        '  The frame changed: send WM_NCCALCSIZE
Public Const SWP_HIDEWINDOW = &H80
Public Const SWP_NOACTIVATE = &H10
Public Const SWP_NOCOPYBITS = &H100
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOOWNERZORDER = &H200      '  Don't do owner Z ordering
Public Const SWP_NOREDRAW = &H8
Public Const SWP_NOREPOSITION = &H200
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOZORDER = &H4
Public Const SWP_SHOWWINDOW = &H40

Public Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long

Sub Main()
On Error Resume Next
HWND_TOPMOST = -1

CmdLine = Command()

A = Split(CmdLine, Chr(32), 2, 1)
B = Split(A(0), "x", 2, 1)

hwindows = FindWindow(vbNullString, A(1))
Ret = SetWindowPos(hwindows, HWND_NOTOPMOST, B(0), B(1), 0, 0, SWP_NOREPOSITION + SWP_NOSIZE)
If Ret = 0 Then MsgBox "Set Pos Error is " & Err.LastDllError
End Sub


来源:https://stackoverflow.com/questions/27248528/size-batch-windows-and-set-in-specific-location

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