PDA

Click to See Complete Forum and Search --> : Opening a child form from an office application [RESOLVED]


Vhati
Jun 29th, 2005, 10:00 AM
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

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!

RobDog888
Jun 29th, 2005, 11:15 AM
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.

Vhati
Jun 29th, 2005, 11:17 AM
How do i find the width and height of the Visio window?

RobDog888
Jun 29th, 2005, 01:41 PM
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.

Vhati
Jun 29th, 2005, 05:09 PM
Well i figured it out, if anyone is interested, here was the solution i came up with



'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!