Embedding a program into the MDI gadget??
Embedding a program into the MDI gadget??
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?
-
- Addict
- Posts: 1027
- Joined: Sun May 15, 2005 5:15 am
- Location: Australia
- Contact:
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....
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
Demonio Ardente
Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
I managed to get that code to work fine for notepad, but the below always fails for the command prompt:
Any ideas why??
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
> the below always fails for the command prompt
Replace:
with:
And delete the While/Wend loop. It's a hack, but it works for now. 
Replace:
Code: Select all
hWndNotepad=FindWindow_("C:\WINDOWS\System32\cmd.exe",#Null)
Code: Select all
Delay(250) : hWndNotepad=GetForegroundWindow_()

I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
You have the FindWindow_() parameters the wrong way round!
Use:
Use:
Code: Select all
FindWindow_(0,"C:\WINDOWS\System32\cmd.exe")
I may look like a mule, but I'm not a complete ass.
-
- Addict
- Posts: 1027
- Joined: Sun May 15, 2005 5:15 am
- Location: Australia
- Contact: