Results 1 to 5 of 5

Thread: Opening a child form from an office application [RESOLVED]

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2005
    Location
    Portland, OR
    Posts
    47

    Resolved 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:
    1. SetParent(frm.hWnd,oVisio.Window.WindowHandle32)
    2. 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!
    Last edited by Vhati; Jun 29th, 2005 at 05:09 PM. Reason: Resolution

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2005
    Location
    Portland, OR
    Posts
    47

    Re: Opening a child form from an office application

    How do i find the width and height of the Visio window?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2005
    Location
    Portland, OR
    Posts
    47

    Resolved 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:
    1. 'get the visio window rectangle
    2.     'get the visio window rectangle
    3.     Dim left As Long, top As Long, width As Long, height As Long
    4.     g_ovAppVisio.Window.GetWindowRect left, top, width, height
    5.    
    6.     'get the form rectangle
    7.     Dim frmTop As Integer, frmLeft As Integer, frmWidth As Integer, frmHeight As Integer
    8.     Call GetWindowRect(frm.hWnd, Rect)
    9.     'do some minor calculations
    10.     frmWidth = Rect.right - Rect.left
    11.     frmHeight = Rect.bottom - Rect.top
    12.     frmLeft = width / 2 - frmWidth / 2
    13.     frmTop = height / 2 - frmHeight / 2
    14.     'move the form to the center
    15.     ret = SetWindowPos(frm.hWnd, 0, frmLeft, frmTop, frmWidth, frmHeight, 0)
    16.     frm.Show
    Thanks for your suggestions!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width