Page 1 of 1

Embedding Console as a Gadget into a Window?

Posted: Thu Feb 22, 2007 11:21 am
by merihevonen
I was trying to do a Linux Terminal the other day, but now I'm thinking of making a "ConsoleGadget" that would embed a Console into your Window..

My Linux Terminal code is here (It's still very buggy and lacks many features.. you can contribute to it if you want):

Code: Select all

; Application: MiniShell [prerelease v0.001] by merihevonen
; Description: Simple Linux Terminal written in PureBasic

; Enumerations
Enumeration
 #MainWindow
EndEnumeration

Enumeration
 #ExecuteButton
 #InputGadget
 #ShellGadget
EndEnumeration

; Application
OpenWindow(#MainWindow, 0, 0, 480, 320, "MiniShell", #PB_Window_ScreenCentered|#PB_Window_SizeGadget)
CreateGadgetList(WindowID(#MainWindow))
 ButtonGadget(#ExecuteButton, WindowWidth(#MainWindow)-105, 5, 100, 25, "Execute")
 StringGadget(#InputGadget, 5, 5, WindowWidth(#MainWindow)-115, 25, "")
 EditorGadget(#ShellGadget, 5, 35, WindowWidth(#MainWindow)-10, WindowHeight(#MainWindow)-40, #PB_Editor_ReadOnly)
SetGadgetText(#ShellGadget, "[MiniShell]: ")

; Loop
Quit=0
Repeat
 Select WaitWindowEvent()
  Case #PB_Event_CloseWindow
   Quit=1
  Case #PB_Event_Gadget
   Select EventGadget()
    Case #ExecuteButton
     Command$=GetGadgetText(#InputGadget)
     If FindString(Command$, " ", 0)<>0
      CommandPos=FindString(Command$, " ", 0)-1
      ACommand$=Trim(Left(Command$, CommandPos))
      BCommand$=Trim(Mid(Command$, CommandPos+2, Len(Command$)-CommandPos))
     Else
      ACommand$=Command$
      BCommand$=""
     EndIf
     SetGadgetText(#ShellGadget, GetGadgetText(#ShellGadget)+Command$+#LF$)
     If ACommand$<>""
      hCmd=RunProgram(ACommand$, BCommand$, "", #PB_Program_Read|#PB_Program_Open)
      While ProgramRunning(hCmd)
        ProgramOutput$+ReadProgramString(hCmd)+#LF$
      Wend
      SetGadgetText(#ShellGadget, GetGadgetText(#ShellGadget)+ProgramOutput$)
      ProgramOutput$=""
      SetGadgetText(#ShellGadget, GetGadgetText(#ShellGadget)+"[MiniShell]: ")
     EndIf
   EndSelect
 EndSelect
Until Quit
I guess that these "Embedded Consoles" aren't used much in the Windows world, but in the Linux world they are quite popular to appear in the most usual applications:
Image

Posted: Sat Feb 24, 2007 11:58 am
by merihevonen
Nobody has interest to this?
I guess I'm just un-lucky :(

Posted: Sat Feb 24, 2007 12:44 pm
by PB
For Windows 2000 and XP, you could try this (needs cleaning up). The original
code was by Sparkie, I think. Not my code at all, anyway. :)

Code: Select all

; Originally used to capture Notepad.
RunProgram("cmd.exe")
Sleep_(500)
hWndNotepad=GetForegroundWindow_()
hwndMain=OpenWindow(1,200,200,640,480,"Capture",#PB_Window_SystemMenu|#WS_CLIPCHILDREN)
If hwndMain=0 : End : EndIf
CreateGadgetList(hwndMain)
hContainer=ContainerGadget(1,3,3,636,470,#PB_Container_Single)
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)
notepadwindowproc = GetWindowLong_(hwndnotepad, #GWL_WNDPROC)
SetParent_(hWndNotepad,hcontainer)
SetWindowPos_(hWndNotepad, 0, 0, 0, 640, 480, 0)
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow