Opening a child form from an office application [RESOLVED]
Hello. I have a routine for opening child forms from Visio. This is how I'm doing it:
frm is my form, and oVisio is my visio application
VB Code:
SetParent(frm.hWnd,oVisio.Window.WindowHandle32)
frm.Show
the problem is, if the visio window isn't maximized, the form doesn't appear in the center, but appears where the center would be IF it was maximized. my StartUpPosition is set to 1, which is center owner. What do i need to do to make it center to the current size of the application?
Thank you!
Re: Opening a child form from an office application
You could use the SetWindowPos API to position the child window where ever you want. Your forms startup position doesnt
matter, its the child windows positioning thats causing the issue. When Visio is started the child window is already positioned. Then
when you change the parenting it just adds the child windows handle to be a child window of your form.
Re: Opening a child form from an office application
How do i find the width and height of the Visio window?
Re: Opening a child form from an office application
Oh, I just relaized that your setting a vb form as a child window of Visio and not the other way around.
You can get the window props probably from the oVisio.Window object. If not then you could use some APIs to get it - GetWindowPlacement, etc.
Re: Opening a child form from an office application
Well i figured it out, if anyone is interested, here was the solution i came up with
VB Code:
'get the visio window rectangle
'get the visio window rectangle
Dim left As Long, top As Long, width As Long, height As Long
g_ovAppVisio.Window.GetWindowRect left, top, width, height
'get the form rectangle
Dim frmTop As Integer, frmLeft As Integer, frmWidth As Integer, frmHeight As Integer
Call GetWindowRect(frm.hWnd, Rect)
'do some minor calculations
frmWidth = Rect.right - Rect.left
frmHeight = Rect.bottom - Rect.top
frmLeft = width / 2 - frmWidth / 2
frmTop = height / 2 - frmHeight / 2
'move the form to the center
ret = SetWindowPos(frm.hWnd, 0, frmLeft, frmTop, frmWidth, frmHeight, 0)
frm.Show
Thanks for your suggestions!