|
-
Jul 4th, 2015, 03:13 PM
#1
Thread Starter
Registered User
How to pass a c# window(form) handle to a VB6 project or form?
We have an application where we launch a VB modal dialog from a c# form on a button click. Even though the VB dialog is a modal window we are able to go back to C# dialog on click and then the application hangs.
Looks like the VB6 form does not have a parent and hence the issue. So we decided to pass the form handle from c# to VB and make our c# dialog as a parent to the VB dialog. Any help or a sample code would be really appreciated.
Once we click search on our c# dialog, we call this:
gPMSearch.Search();
Private Sub Class_Initialize()
'Load the search form
Set Form = New frmMain
Load Form
End Sub
The form is loaded as below:
Me.Show vbModal
-
Jul 5th, 2015, 11:37 PM
#2
Re: How to pass a c# window(form) handle to a VB6 project or form?
 Originally Posted by guru.july
Looks like the VB6 form does not have a parent and hence the issue.
Actually, ...
 Originally Posted by Bonnie West
... all top-level Forms in a VB6 process are owned by the unseen ThunderMain window.
Note that Parent Windows and Owner Windows do not mean the same thing!
In order for your VB6 Form to be modal to your C# Form, you'll need to change the owner window of the VB6 Form from ThunderMain to your C# Form. You will also want to disable and re-enable the C# Form when the VB6 Form loads and unloads. Here's an example of doing it from the VB6 side:
Code:
Private Enum Consts
[C# Form hWnd] = &H12345678
End Enum
Private Const GWL_HWNDPARENT As Long = (-8&)
Private Declare Function EnableWindow Lib "user32.dll" (ByVal hWnd As Long, ByVal bEnable As Long) As Long
Private Declare Function SetWindowLongW Lib "user32.dll" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Sub Form_Load()
SetWindowLongW hWnd, GWL_HWNDPARENT, [C# Form hWnd]
EnableWindow [C# Form hWnd], False
End Sub
Private Sub Form_Unload(Cancel As Integer)
EnableWindow [C# Form hWnd], -True
End Sub
To fully replicate the behavior of modal windows, you'll have to perform one final step. When your C# Form closes, you should also close its owned VB6 Form. This can be accomplished by sending the WM_CLOSE message to the VB6 Form.
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
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
|