Anchor windows are new to me, looks like it has a lot of uses. I am trying the following code from the sdk.
Private Sub UserForm_Resize()
txtForm.Width = txtForm.Parent.Width - 10
txtForm.Height = txtForm.Parent.Height - 10
End Sub
Then add the following code to the document project:
Visual Basic for Applications
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const WS_CHILD = &H40000000
Private Const WS_VISIBLE = &H10000000
Public Sub AddWindow_Example()
Dim vsoWindow As Visio.Window
Dim frmNewWindow As UserForm
Dim lngFormHandle As Long
'Add a new Anchor Bar window docked to the bottom of the Visio drawing window
Set vsoWindow = ActiveWindow.Windows.Add("My New Window", visWSVisible + visWSDockedBottom, visAnchorBarAddon, , , 300, 210)
'Create a new windows form
Set frmNewWindow = New frmMain
'Get the 32-bit handle of the new window.
lngFormHandle = FindWindow(vbNullString, "My New Window")
SetWindowLong lngFormHandle, GWL_STYLE, WS_CHILD Or WS_VISIBLE
SetParent lngFormHandle, vsoWindow.WindowHandle32
End Sub
The window does get added but the user form is not in the window. Anyone have any ideas as to why it is not there.
Just looking for a sample so i can start playing with the Anchor Windows concept
Thanks in advance
Mike
Hi Mike
Don't know if you've seen this already, but, it does go thru an example.
http://msdn.microsoft.com/en-us/library/aa140261(office.10).aspx
I couldn't see right away what was wrong, but you can play with this sample.
There are a bunch of mini web pages in the zip directory that the VBA code needs. It displays these web pages in a docked browser window that belongs to the Visio drawing window.
When you drop shapes, they are "sponsored" (gag) and a related banner-ad shows in the docked window.
Your code seems ok, but you are missing a jiggle of the window to make it update, the size of the parent is increased and decreased by a pixel forcing the update. All this is covered in the excellent book, Visio 2003 Developer's Survival Pack by Graham Wideman.
Call this after your SetParent.
Public Sub JiggleWindow(hwnd As Long)
' This function causes Windows to refresh the onscreen display according
' to changes we've made to style bits and parent
Dim l As Long
Dim t As Long
Dim W As Long
Dim H As Long
Dim flags As Long
Dim HR As Long
Dim ARect As RECT
If hwnd <> 0 Then
HR = GetWindowRect(hwnd, ARect)
If HR <> 0 Then
l = ARect.Left
t = ARect.Top
W = ARect.Right - ARect.Left
H = ARect.Bottom - ARect.Top
flags = SWP_NOCOPYBITS Or SWP_NOMOVE Or SWP_NOZORDER
HR = SetWindowPos(hwnd, 0, l, t, W, H + 1, flags)
HR = SetWindowPos(hwnd, 0, l, t, W, H, flags)
End If
End If
End Sub
Hi Andy,
I'm using Visio 2007 and my window is just fine without the jiggle. I'm aware of Graham's jiggle procedure, but I didn't see a need for it, because everything is working just fine.
Are you using Visio 2003?
Quote from: AndyW on March 26, 2009, 08:25:03 AM
Your code seems ok, but you are missing a jiggle of the window to make it update, the size of the parent is increased and decreased by a pixel forcing the update. All this is covered in the excellent book, Visio 2003 Developer's Survival Pack by Graham Wideman.
Andy,
Thanks. If you are refering to the Visio Guys code, his works fine on 2007 on my machine also. If you are referring to the code I posted it is a complete copy of the code from the SKK. Since VISIO guys worked I did bother to look any further at the stuff I sent.
Thanks a lot for taking the time to respond.
Yes I'm using 2003.
Hi, work on that today,
mmulvenna what is wrong in visio help file is that it is not writen that you should enter "My New Window" in the userform.caption field.
even thet you have to move the window or even to resize it to get it updated.
Ziorg77