I am using the following code to occupy windows from external processes. It works well but the menu bars of the windows are missing.
Code: Select all
; Begin-----------------------------------------------------------------
; Directives----------------------------------------------------------
EnableExplicit
; Enumeration---------------------------------------------------------
Enumeration
#MainWin
#MDI
EndEnumeration
; Variables-----------------------------------------------------------
Global Notepad.i, hNotepad.i
Global Calc.i, hCalc.i
; Function MyWindowCallback-------------------------------------------
Procedure WinCallback(hWin, uMsg, wParam, lParam)
; Variables-------------------------------------------------------
Protected Result.i
Result = #PB_ProcessPureBasicEvents
Select uMsg
Case #WM_PAINT
UpdateWindow_(hNotepad)
UpdateWindow_(hCalc)
EndSelect
ProcedureReturn Result
EndProcedure
; Function CaptureWindowAsChild---------------------------------------
Procedure CaptureWindowAsChild(Program.i)
; Variables-------------------------------------------------------
Protected hWindow.i
Protected Quit.b = #False
Protected PID.i
Protected PIDProgram.i
Protected hProgramWin.i
PIDProgram = ProgramID(Program)
Repeat
hWindow = FindWindow_(0, 0)
While hWindow <> 0 And Quit = #False
GetWindowThreadProcessId_(hWindow, @PID)
If PID = PIDProgram And GetParent_(hWindow) = 0 And
IsWindowVisible_(hWindow)
hProgramWin = hWindow
Quit = #True
EndIf
hWindow = GetWindow_(hWindow, #GW_HWNDNEXT)
Wend
Until hProgramWin
SetWindowLong_(hProgramWin, #GWL_STYLE,
GetWindowLong_(hProgramWin, #GWL_STYLE) | #WS_CHILD)
SetParent_(hProgramWin, GadgetID(#MDI))
UpdateWindow_(hProgramWin)
ProcedureReturn hProgramWin
EndProcedure
; Function Init-------------------------------------------------------
Procedure.b Init()
If OpenWindow(#MainWin, 10, 10, 1024, 768, "SetParent",
#PB_Window_SizeGadget | #PB_Window_SystemMenu)
SetWindowCallback(@WinCallback())
MDIGadget(#MDI, 0, 0, 0, 0, 0, 0, #PB_MDI_AutoSize)
Notepad = RunProgram("notepad.exe", "", "", #PB_Program_Open)
hNotePad = CaptureWindowAsChild(Notepad)
Calc = RunProgram("calc.exe", "", "", #PB_Program_Open)
hCalc = CaptureWindowAsChild(Calc)
ProcedureReturn #True
EndIf
EndProcedure
; Sub Main------------------------------------------------------------
Procedure Main()
; Variables-------------------------------------------------------
Protected Quit.b = #False
Protected Event.i
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
Quit = #True
EndSelect
Until Quit
EndProcedure
; Sub Done------------------------------------------------------------
Procedure Done()
If IsProgram(Notepad)
KillProgram(Notepad)
CloseProgram(Notepad)
EndIf
If IsProgram(Calc)
KillProgram(Calc)
CloseProgram(Calc)
EndIf
If IsWindow(#MainWin)
CloseWindow(#MainWin)
EndIf
EndProcedure
; Main----------------------------------------------------------------
If Init()
Main()
Done()
EndIf
; End-------------------------------------------------------------------

Where is my mistake?
Thanks for hints and tips.
Cheers
Stefan