-
This has been sitting here all day (different post though) with no answer, so perhaps a guru can answer?
I have a MDI application that will be launching another application (a helper wizard that I wrote).
Is there any way where I can get app # 2 to be a MDI child of app # 1 (MDI app)?
-
I think this was discussed a few days ago, I believe the solution was to get the handle of the window opened, then use the SetParent API to make it like a child form...:D
-
For example, I just did notepad, but you can use your own form, just supply caption name.
Code:
Option Explicit
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Command1_Click()
SetParent FindWindow(vbNullString, "Untitled - Notepad"), hWnd
End Sub
-
What a team, me and you, Lethal :D
-
Yep, we chew up the questions and spit them out..(Spit)...:D
-
-
:confused:
Ok - I got it to work pulling the outside app into the MDI form - here is the new problem I am having though:
If the new Child exe/window is still open when the MDI form is unloaded, the Child exe continues running in the background.
I have tried using different API calls (CloseWindow, DestroyWindow, etc) but nothing seems to do it. Perhaps I am just calling them wrong or something?
Any help?
-
Nevermind
Nevermind;
I found an old post that Lethal had answered using the SendMessage API call...
I tried this too, but evidently was passing the wrong window handle.
Code:
Option Explicit
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, _
ByVal hWndNewParent As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_CLOSE = &H10
Public theID As Long
Private Sub MDIForm_Load()
Form1.Show
Shell "Wizard.exe", vbNormalFocus
theID = FindWindow(vbNullString, "Wizard")
SetParent theID, hwnd
End Sub
Private Sub MDIForm_Unload(Cancel As Integer)
Dim frm As Form
SendMessage theID, WM_CLOSE, 0, 0
For Each frm In Forms
Unload frm
Next
End Sub
:D