Results 1 to 12 of 12

Thread: Interop and Modal Forms

  1. #1

    Thread Starter
    Fanatic Member clarkgriswald's Avatar
    Join Date
    Feb 2000
    Location
    USA
    Posts
    799

    Interop and Modal Forms

    I have a .NET application that calls a method in a COM component to show a dialog. Unfortunately, you can't pass the .NET form to the COM component to set the owner form without a type mismatch:

    _ComForm.Show vbModal, _DotNetForm

    So, what that means is the form is displayed without a parent form. The problem is, if the user launches the COM form and then while the dialog is shown, clicks to another application and then returns to my application, the COM form is now behind the .NET owner form and most users won't know how to find that window. Is there any way around this?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Interop and Modal Forms

    Can you pass the Handle of the .NET form?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member clarkgriswald's Avatar
    Join Date
    Feb 2000
    Location
    USA
    Posts
    799

    Re: Interop and Modal Forms

    I would think so, yes.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Interop and Modal Forms

    Then that's what you should do. The Handle property of a Form is type IntPtr, which you can use as is if approriate or else call ToInt32 to get an Integer.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Fanatic Member clarkgriswald's Avatar
    Join Date
    Feb 2000
    Location
    USA
    Posts
    799

    Re: Interop and Modal Forms

    Ok, on the com side, how do I pass the handle to the .Show method?

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Interop and Modal Forms

    No idea. Never done any COM development.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    Registered User
    Join Date
    Mar 2013
    Posts
    2

    Re: Interop and Modal Forms

    I'm also facing the same issue. Can you please help me , how you reslove the issue.

  8. #8
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Interop and Modal Forms

    Maybe use the SetWindowLong API to set the dialog's parent (owner) ?

    Syntax is something like,...
    SetWindowLong dialogForm.handle, GWL_HWNDPARENT, myForm.handle
    Last edited by Edgemeal; Mar 18th, 2013 at 05:31 AM.

  9. #9
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Interop and Modal Forms

    Based on the description provided by the OP I would expect it to be done like this:-
    vbnet Code:
    1. _ComForm.Show vbModal, _DotNetForm.Handle.ToInt32

    I'm assuming the COM method would take a 32 bit integer for the window handle assuming a 32 bit OS.

    @Op

    Could you provide the signature for that COM method ?
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  10. #10
    Registered User
    Join Date
    Mar 2013
    Posts
    2

    Re: Interop and Modal Forms

    Im using VB6

    Me.Show vbModal

    oldOwner = SetOwner(Oconverstion.hWnd, Me.hWnd)

    These are API im using to set the owner

    Private Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" _
    (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
    Const GWL_HWNDPARENT = (-8)

    Public Function SetOwner(ByVal HwndtoUse, ByVal HwndofOwner) As Long
    SetOwner = SetWindowLong(HwndtoUse, GWL_HWNDPARENT, HwndofOwner)
    End Function

  11. #11
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Interop and Modal Forms

    Quote Originally Posted by manish.amq View Post
    Im using VB6
    Well you should make your own thread in the VB6 section. VB6 may have its own set of nuances.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  12. #12
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Interop and Modal Forms

    Using SetWindowLong with GWL_HWNDPARENT is the correct approach. However you should also use EnableWindow to disable the parent window and call it again to enable it when the modal form is closed.

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