|
-
Feb 9th, 2012, 10:10 AM
#1
Thread Starter
Fanatic Member
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?
-
Feb 9th, 2012, 07:22 PM
#2
Re: Interop and Modal Forms
Can you pass the Handle of the .NET form?
-
Feb 9th, 2012, 07:32 PM
#3
Thread Starter
Fanatic Member
Re: Interop and Modal Forms
-
Feb 9th, 2012, 07:52 PM
#4
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.
-
Feb 9th, 2012, 07:55 PM
#5
Thread Starter
Fanatic Member
Re: Interop and Modal Forms
Ok, on the com side, how do I pass the handle to the .Show method?
-
Feb 9th, 2012, 07:58 PM
#6
Re: Interop and Modal Forms
No idea. Never done any COM development.
-
Mar 18th, 2013, 02:44 AM
#7
Registered User
Re: Interop and Modal Forms
I'm also facing the same issue. Can you please help me , how you reslove the issue.
-
Mar 18th, 2013, 05:22 AM
#8
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.
-
Mar 18th, 2013, 10:19 AM
#9
Re: Interop and Modal Forms
Based on the description provided by the OP I would expect it to be done like this:-
vbnet Code:
_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 ?
-
Mar 21st, 2013, 04:16 AM
#10
Registered User
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
-
Mar 21st, 2013, 06:59 AM
#11
Re: Interop and Modal Forms
 Originally Posted by manish.amq
Im using VB6
Well you should make your own thread in the VB6 section. VB6 may have its own set of nuances.
-
Mar 21st, 2013, 07:56 AM
#12
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|