Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
659 views
in Technique[技术] by (71.8m points)

vbscript - How can I maximize, restore, or minimize a window with a vb script?

I need to be able to make separte .vbs files that will (when triggered with a keyboard short-cut) will make the active window maximized, minimized, or restored.

How can I do this without downloading and installing (not allowed here) a separate package.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

VBScript and Windows Script Host don't provide intrinsic functions for maximizing/minimizing/restoring a window. Without any third-party tools, your only option is to use SendKeys to simulate keyboard the shortcuts of the corresponding commands in a window's system menu.

  • To maximixe the active window, you can simulate the Alt+SpaceBar, x shortcut:

    Set oShell = CreateObject("WScript.Shell")
    oShell.SendKeys "% x"
    
  • To minimize the active window, use Alt+SpaceBar, n:

    Set oShell = CreateObject("WScript.Shell")
    oShell.SendKeys "% n"
    
  • To restore the active window, use Alt+SpaceBar, r:

    Set oShell = CreateObject("WScript.Shell")
    oShell.SendKeys "% r"
    

(Note that this code won't work in non-English Windows versions, where the names of the Maximize/Minimize/Restore commands are localized and therefore have other shortcuts.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...