Page 1 of 1

Embedding a program into the MDI gadget??

Posted: Tue Nov 21, 2006 8:32 am
by Hydrate
I remember seeing this before, but i must be wording it wrong as i cant find what im looking for using the search feature. How can i get a program like the command prompt, and load it up into my MDI gadget?

Posted: Tue Nov 21, 2006 8:50 am
by lexvictory
well, it never used to work everytime in pb3.94 (using notepad as the captured window)....
but it seems to work good in pb4.01...

this is the code that was in that topic, but i was playing with it, and i dont comment my code.....and i seem to have commened out the mdigadget stuff and put notepad into a containergadget....

still has a few bugs, but here it is anyway....

Code: Select all

RunProgram("notepad.exe") 
hWndNotepad=FindWindow_("Notepad",#Null) 
While hWndNotepad=0 
  Delay(100) 
  hWndNotepad=FindWindow_("Notepad",#Null) 
Wend 

hwndMain=OpenWindow(1,0,0,640,480,"Containt Notepad",#PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#WS_CLIPCHILDREN) 
If hwndMain=0 
  End 
EndIf 
CreateGadgetList(hwndMain) 
hContainer=ContainerGadget(1,3,3,636,470,#PB_Container_Single)
;CreateMenu(0, WindowID())
;MenuTitle("Menu index 0")
;      MenuTitle("MDI windows menu")
;        MenuItem(0, "self created item")
;        MenuItem(1, "self created item")
        
 ;     mdithing = MDIGadget(0, 0, 0, 0, 0, 1, 2, #PB_MDI_AutoSize)
  
; --> Add #WS_CLIPCHILDREN to the ContainerGadget 
;SetWindowLong_(hContainer, #GWL_STYLE, GetWindowLong_(hContainer, #GWL_STYLE) | #WS_CLIPCHILDREN) 
; --> Add #WS_CHILD to Notepad 
ShowTitlebar(hwndnotepad, #False)
SetWindowPos_(hWndNotepad, 0, 0, 0, 640, 480, 0)
SetWindowLong_(hWndNotepad, #GWL_STYLE, GetWindowLong_(hWndNotepad, #GWL_STYLE)| #WS_CHILD  !#WS_POPUP) 
SetWindowLong_(hwndnotepad, #GWL_EXSTYLE, GetWindowLong_(hwndnotepad, #GWL_EXSTYLE) ! #WS_EX_APPWINDOW)
;SetMenu_(hwndmain, GetMenu_(hwndnotepad))
;SetMenu_(hwndnotepad, 0)
notepadwindowproc = GetWindowLong_(hwndnotepad, #GWL_WNDPROC)


;SetWindowLong_(hwndnotepad, #GWL_EXSTYLE, GetWindowLong_(hwndnotepad, #GWL_EXSTYLE) | #WS_EX_MDICHILD)
; --> Set the ContainerGadget as the parent 
; --> Remove WS_POPUP style, Now Notepad's menu available,and works better! 
SetParent_(hWndNotepad,hcontainer) 
; --> Position Notepad 
SetWindowPos_(hWndNotepad, 0, 0, 0, 640, 480, 0)
;SendMessage_(hwndnotepad, #WM_PAINT, null, null) 

Repeat 
  event=WaitWindowEvent()

Until event=#PB_Event_CloseWindow

Posted: Tue Nov 21, 2006 12:31 pm
by Hydrate
I managed to get that code to work fine for notepad, but the below always fails for the command prompt:

Code: Select all

RunProgram("cmd.exe")
hWndNotepad=FindWindow_("C:\WINDOWS\System32\cmd.exe",#Null)
While hWndNotepad=0
  Delay(100)
  hWndNotepad=FindWindow_("C:\WINDOWS\system32\cmd.exe",#Null)
Wend

hwndMain=OpenWindow(1,0,0,320,240,"Containt Notepad",#PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#WS_CLIPCHILDREN)
If hwndMain=0
  End
EndIf
CreateGadgetList(hwndMain)
hContainer=ContainerGadget(1,3,3,316,230,#PB_Container_Single)
;CreateMenu(0, WindowID())
;MenuTitle("Menu index 0")
;      MenuTitle("MDI windows menu")
;        MenuItem(0, "self created item")
;        MenuItem(1, "self created item")
       
 ;     mdithing = MDIGadget(0, 0, 0, 0, 0, 1, 2, #PB_MDI_AutoSize)
 
; --> Add #WS_CLIPCHILDREN to the ContainerGadget
;SetWindowLong_(hContainer, #GWL_STYLE, GetWindowLong_(hContainer, #GWL_STYLE) | #WS_CLIPCHILDREN)
; --> Add #WS_CHILD to Notepad
ShowTitlebar(hwndnotepad, #False)
SetWindowPos_(hWndNotepad, 0, 0, 0, 300, 230, 0)
SetWindowLong_(hWndNotepad, #GWL_STYLE, GetWindowLong_(hWndNotepad, #GWL_STYLE)| #WS_CHILD  !#WS_POPUP)
SetWindowLong_(hwndnotepad, #GWL_EXSTYLE, GetWindowLong_(hwndnotepad, #GWL_EXSTYLE) ! #WS_EX_APPWINDOW)
;SetMenu_(hwndmain, GetMenu_(hwndnotepad))
;SetMenu_(hwndnotepad, 0)
notepadwindowproc = GetWindowLong_(hwndnotepad, #GWL_WNDPROC)


;SetWindowLong_(hwndnotepad, #GWL_EXSTYLE, GetWindowLong_(hwndnotepad, #GWL_EXSTYLE) | #WS_EX_MDICHILD)
; --> Set the ContainerGadget as the parent
; --> Remove WS_POPUP style, Now Notepad's menu available,and works better!
SetParent_(hWndNotepad,hcontainer)
; --> Position Notepad
SetWindowPos_(hWndNotepad, 0, 0, 0, 640, 480, 0)
;SendMessage_(hwndnotepad, #WM_PAINT, null, null)

Repeat
  event=WaitWindowEvent()

Until event=#PB_Event_CloseWindow 
Any ideas why??

Posted: Tue Nov 21, 2006 1:00 pm
by PB
> the below always fails for the command prompt

Replace:

Code: Select all

hWndNotepad=FindWindow_("C:\WINDOWS\System32\cmd.exe",#Null)
with:

Code: Select all

Delay(250) : hWndNotepad=GetForegroundWindow_()
And delete the While/Wend loop. It's a hack, but it works for now. ;)

Posted: Tue Nov 21, 2006 1:20 pm
by srod
You have the FindWindow_() parameters the wrong way round!

Use:

Code: Select all

FindWindow_(0,"C:\WINDOWS\System32\cmd.exe")

Posted: Tue Nov 21, 2006 2:41 pm
by Hydrate
Thank you very much, sorted now, lol. I wonder why it worked with the parameters the wrong way round for notepad...

Posted: Tue Nov 21, 2006 2:46 pm
by lexvictory
because notepad's classname IS 'Notepad', its window title (the 2nd one) can be anything, like 'Untitled - Notepad'