Resizing docked windows

W

Wes

I am programmatically opening a stencil in a shapes window in a visio drawing
control at run time. This shapes window's state is visWSDockedBottom. That
works fine, but unfortunately everytime I open the stencil window at run
time, it obscures half of the drawing section of the visio component.

Is there any way that I can programmatically resize or make the shapes
window shrink to fit the stencil it contains at run time?

I can get a handle to the shapes window in code, but trying to use the
SetWindowRect method has no effect. I would really appreciate if someone
could help me out on this one, as it is something that has been bugging me
for months.

Thanks in advance
 
J

JuneTheSecond

I've tested SetWindowRect method, but it did not work normally.
Maybe it's a bag or a not-expected-usage.
Dim mywin As Visio.Window
Dim nLeft As Long, nTop As Long, nWidth As Long, nHeight As Long
Set mywin = ActiveWindow.Windows.ItemFromID(1669)
mywin.Visible = True
mywin.GetWindowRect nLeft, nTop, nWidth, nHeight
Debug.Print nLeft, nTop, nWidth, nHeight
nWidth = 100
Debug.Print mywin.Caption
mywin.SetWindowRect nLeft, nTop, nWidth, nHeight
Debug.Print nLeft, nTop, nWidth, nHeight
 
J

JuneTheSecond

WindowState property might be useful, for example;
Sub WinMaximize()
Dim mywin As Visio.Window
Set mywin = ActiveWindow.Windows.ItemEx("stencil name")
mywin.WindowState = visWSMaximized + visWSDockedLeft
End Sub
Sub WinMinimize()
Dim mywin As Visio.Window
Set mywin = ActiveWindow.Windows.ItemEx("stencil name")
mywin.WindowState = visWSMinimized
End Sub
Before you execute macro, please, make visio remember the minimized window
size by dragging the stencil window with your mouth.
 
J

JuneTheSecond

And,
Set mywin = ActiveWindow.Windows.ItemFromID(1669)
might be better than
Set mywin = ActiveWindow.Windows.ItemEx("stencil name")
 
J

JuneTheSecond

For Drawing Control the code might be ......
Private Sub Command1_Click()
Dim mywin As Visio.Window
Set mywin = DrawingControl1.Window.Windows.ItemFromID(1669)
mywin.WindowState = visWSMaximized + visWSDockedLeft
End Sub
Private Sub Command2_Click()
Dim mywin As Visio.Window
Set mywin = DrawingControl1.Window.Windows.ItemFromID(1669)
mywin.WindowState = visWSMinimized
End Sub
 
W

Wes

Thank you very much for all the replies so far. However I'm afraid I still
have the same problem. I have had no problem changing the window state of a
child window spawned by the visio drawing control. For example my code starts
up and open's the visio shapes window and sets the WindowState to the
following

Visio.VisWindowStates.visWSDockedBottom

I'm coding this in C#, I should mention.

That works fine, but the window size is too high. I have to manually with
the mouse (at runtime) resize the window.

I have also tried

..WindowState = (int)Visio.VisWindowStates.visWSDockedBottom +
(int)Visio.VisWindowStates.visWSMaximized;

which has the exact same affect as

..WindowState = (int)Visio.VisWindowStates.visWSDockedBottom

Anyway I really appreciate your time so far. If you or anyone else can offer
further suggestions, please do.
 
J

JuneTheSecond

My results are...
1. To define width using SetWindowRect method, you need to float stencil
window.
2. The nHeight value obtained by GetWindowRect is too small to set with
SetWindowRect method.
This code is for left docked stencil window, but might still help you for
the reference.
Sub ChangeWidth()
Dim mywin As Visio.Window
Dim nLeft As Long, nTop As Long, nWidth As Long, nHeight As Long
Set mywin = ActiveWindow.Windows.ItemFromID(1669)
mywin.WindowState = visWSFloating
mywin.GetWindowRect nLeft, nTop, nWidth, nHeight
nWidth = 100
mywin.SetWindowRect nLeft, nTop, nWidth, nHeight * 10
mywin.WindowState = visWSDockedLeft
End Sub
 
J

JuneTheSecond

The nHeight value obtained by GetWindowRect is too small ....
It is not always true, but sometimes it happens and causes error.
 
J

JuneTheSecond

Next code is for changing height and place at the bottom.

Sub TestHeight()
ChangeHeight 100
End Sub

Sub ChangeHeight(NewHeight As Long)
Dim mywin As Visio.Window
Dim nLeft As Long, nTop As Long, nWidth As Long, nHeight As Long

Set mywin = ActiveWindow.Windows.ItemFromID(1669)
mywin.GetWindowRect nLeft, nTop, nWidth, nHeight
mywin.WindowState = visWSFloating
Debug.Print nLeft, nTop, nWidth, nHeight
nHeight = NewHeight
mywin.SetWindowRect nLeft, nTop, nWidth, nHeight
mywin.WindowState = visWSDockedBottom
End Sub
 
W

Wes

That's it!!, thank you very much it works.

You have no idea how much scouring the web I've done trying to find a
sollution to this. You are brilliant. Thank you.

Wes :-D
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top