Jan 31
I’ve been working with Visio lately and noticed that when my programs start it up, Visio was not coming up maximized. Since I wanted to be able to see my work full screen, I started looking for a way to force it to maximized mode. I quickly learned that there is no convenient ‘visio.Maximize’ method to use. Bummer. Other Office apps have a ‘.WindowState’ parameter that can be set to minimize, maxamize, restore, or hide the application window, but not Visio. Guess that would make it too easy
For Visio, you can use the ‘ShowWindow’ function from the user32.dll to do the work:
require 'Win32API'
##Possible cmd values:
# Hidden => 0
# Restored => 1
# Minimized => 2
# Maximized => 3
def ShowWindow(wndHandle, cmd)
wndShowWindow = Win32API.new("user32", "ShowWindow", ["p","i"], "i")
wndShowWindow.call(wndHandle, cmd)
end
‘wndHandle‘ is the infamous Window Handle used in the lower-level Windows APIs. At least Visio has a way to return the handle. So in your program:
...
visio = WIN32OLE.new('Visio.Application')
ShowWindow(visio.WindowHandle32, 3)
Pretty easy, eh?







February 1st, 2010 at 7:07 am
[...] Controlling Visio Windows with Ruby Feb 01 [...]