【问题标题】:Size batch windows and set in specific location大小批处理窗口并设置在特定位置
【发布时间】:2014-12-02 11:40:25
【问题描述】:

我运行多个批处理文件来监控我的网络链接。我有下面的一组代码。我运行一个批处理文件来一次打开所有文件。然后我必须将它们重新定位在屏幕顶部,以便我可以打开 Internet Explorer 以在屏幕底部显示太阳风。我想添加到我用来设置每个窗口打开位置的代码中。提前感谢您的帮助。

@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 
    )

【问题讨论】:

标签: windows batch-file ping window-resize


【解决方案1】:

如果你像这样启动每个窗口

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

转到窗口的属性。设置大小和颜色,取消勾选Let Windows Position

当你以后以同样的方式启动它时,它会记住它的大小和颜色。

【讨论】:

    【解决方案2】:

    没有批处理文件命令可以做到这一点。也没有任何脚本(或 .NET)命令可以对不是代码(或由它启动)的窗口执行任何操作。程序不应该与其他人混淆。

    我在https://skydrive.live.com/redir?resid=E2F0CE17A268A4FA!121 有一些 VB6 非常基本的程序来调整大小、移动、置顶和更改标题栏(带有源代码 - 每个大约 6 行)

    只有 API 调用可以做到这一点,因此您需要一种真正的编程语言。这样做是违反哲学的。

    现在 CMD 会根据标题栏记住它的窗口位置。制作利用这一点的快捷方式,请参阅HKEY_CURRENT_USER\Console

    我建议你看看 CMD 标题的东西。

    她有一个 VB6 程序来移动窗口。

    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
    

    【讨论】:

    • @carpetsmoker 那么如何让文件记住它的重要位置?我无法在工作中访问您的 Skydrive 链接
    • 我没有vb6。我们正在运行已锁定的库存 Windows 7 企业映像。
    • 你有VB.NET,它安装在所有计算机上。请参阅如何使用 notepad/vb.net 编译器进行翻译。 social.msdn.microsoft.com/Forums/en-US/…
    【解决方案3】:

    要设置批处理窗口的大小并设置在特定位置,一旦命令提示符窗口打开,右键单击标题栏,选择属性,进入布局选项卡,取消选中“让系统定位窗口”,然后选择窗口大小和根据您想要的窗口位置。您还可以从“属性”的其他选项卡中选择其他属性(字体、字体大小、颜色等)。从那时起它将以该设置格式打开。

    【讨论】:

      猜你喜欢
      • 2014-12-03
      • 2016-03-18
      • 1970-01-01
      • 1970-01-01
      • 2021-11-19
      • 2013-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多