Sean Wenzel
Home Mouse Grid Password Manager Advanced Scripting Dictation Box HTML by voice Hippocampus




Resizing a window by voice

Using the supplied commands from Dragon NaturallySpeaking to resize a window can be limited. The documentation offers resizing solutions of maximize and minimize only. Not not exactly flexible.

Here is a script that will shrink or expand the active window by percentage.

Resizing a window by a specified percentage

I was somewhat disappointed in the limited window manipulation built-in commands that are included with Dragon NaturallySpeaking.

Here is Advanced Scripting that will allow you to quickly and easily resize a window larger or smaller by specified percentage.

Example usage:

  • expand window 50 percent
  • shrink window 50 percent
  • shrink win 50 percent

MyCommand Name: <shrinkexpand> <window> <1to100> percent
Description: Resize the active window by a specified percentage
Availability: Global
Command Type: Advanced Scripting

You will need to create the following lists:

<shrinkexpand>
<window>
<1to100>

Script:

Sub
' resize a window to x%
'
' 
2005 Sean Wenzel sean@wenzel.net http://sean.wenzel.net/
'
' Command name:  window <1to100> percent
'
' Released under the GNU General Public license
' http://www.gnu.org/licenses/gpl.html
'
' No warranty is implied or expressed.
'
Private Type POINTAPI
  x As Long  
  y As Long
End Type

Private Type RECT
  Left As Long
  Top As Long
  Right As Long
  Bottom As Long
End Type

Private Type WINDOWPLACEMENT
  Length As Long
  Flags As Long
  showCmd As Long
  MinPosition As POINTAPI
  MaxPosition As POINTAPI
  NormalPosition As RECT
End Type

Private Declare Function GetWindowPlacement Lib "user32" -
(ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long

Private Declare Function SetWindowPlacement Lib "user32" _
(ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long

Private Declare Function GetForegroundWindow& Lib "user32"


Sub Main
  Dim whnd As Long
  Dim WinPlace As WINDOWPLACEMENT

  ' fix up input
  x = ListVar3

  adjust = x
  ' adjust = 50

  ' get the handle for the top most window
  whnd = GetForegroundWindow()
  If whnd Then

    ' execute the API call to get where
    WinPlace.Length = Len(WinPlace)
    GetWindowPlacement whnd, WinPlace
			
    ' calculate width and height
    width = WinPlace.NormalPosition.Right - WinPlace.NormalPosition.Left
    height = WinPlace.NormalPosition.Bottom - WinPlace.NormalPosition.Top
			
    ' calculate the adjustment by percentage
    w_adjust = Int(width * adjust / 100)
    h_adjust = Int(height * adjust / 100)
		
    'MsgBox "Width " + width + " Width adjust: " + w_adjust
			
    Select Case ListVar1

      Case "shrink"
        ' adjust the width/height by the percentage
        WinPlace.NormalPosition.Right = _ WinPlace.NormalPosition.Right - w_adjust
        WinPlace.NormalPosition.Bottom = _ WinPlace.NormalPosition.Bottom - h_adjust

      Case "expand"
        ' adjust the width/height by the percentage
        WinPlace.NormalPosition.Right = _ WinPlace.NormalPosition.Right + w_adjust
        WinPlace.NormalPosition.Bottom = _ WinPlace.NormalPosition.Bottom + h_adjust

    End Select
			
    ' set the new window size/placement
    SetWindowPlacement whnd, WinPlace
			
  End If
			
End Sub
			
To avoid having to type the script in yourself copy and paste the following XML export into a file and imported through the Command Browser.