Embedding a program into the MDI gadget??

Just starting out? Need help? Post your questions and find answers here.
Hydrate
Enthusiast
Enthusiast
Posts: 436
Joined: Mon May 16, 2005 9:37 pm
Contact:

Embedding a program into the MDI gadget??

Post 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?
.::Image::.
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post 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
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Hydrate
Enthusiast
Enthusiast
Posts: 436
Joined: Mon May 16, 2005 9:37 pm
Contact:

Post 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??
.::Image::.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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. ;)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

You have the FindWindow_() parameters the wrong way round!

Use:

Code: Select all

FindWindow_(0,"C:\WINDOWS\System32\cmd.exe")
I may look like a mule, but I'm not a complete ass.
Hydrate
Enthusiast
Enthusiast
Posts: 436
Joined: Mon May 16, 2005 9:37 pm
Contact:

Post by Hydrate »

Thank you very much, sorted now, lol. I wonder why it worked with the parameters the wrong way round for notepad...
.::Image::.
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

because notepad's classname IS 'Notepad', its window title (the 2nd one) can be anything, like 'Untitled - Notepad'
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Post Reply