Author Topic: A CONSOLE + GUI novelty from LONG ago ...  (Read 579 times)

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 786
    • View Profile
A CONSOLE + GUI novelty from LONG ago ...
« on: August 21, 2020, 10:52:42 PM »
I wrote this a long time ago ... someone might find a practical use for this technique.

Anyway, compile this as a console app, not a GUI app then run it.

It compiles and runs with Mingw, Clang, MSVC, LccWin32, and Pelles

Code: [Select]
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
'  I don't know how useful this is but it does demonstrate how it
'  is possible to startup in CONSOLE mode and conditionally switch
'  GUI mode.  Released to the public domain by Kevin Diggins.
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
'  Please compile this as a CONSOLE app, to see the full benefit.
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

SUB main()       ' main MUST be spelled using lower case
  LOCAL Tmp$
  INPUT "Do you wanna do the gui? ", Tmp$
  IF UCASE$(MID$(Tmp$,1,1)) = "Y" THEN
    WinMain(0,0,0,0)   ' Yes ... Call WINMAIN() from main() ... crazy, huh?
  ELSE
    END
  END IF
END SUB

'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

GUI "BCX GUI-Console"


SUB FormLoad
  CONST   ID_Button1 =  101
  GLOBAL Form1 AS HWND
  GLOBAL Button1 AS HWND

  Form1 = BCX_FORM("Con_Gui", 0, 0, 165, 120)
  Button1 = BCX_BUTTON ("Print message to Console Window", Form1, ID_Button1, 10, 42, 140, 14)

  CENTER (Form1)
  SHOW (Form1)
END SUB



BEGIN EVENTS
  SELECT CASE Msg
    ' *****************
    CASE WM_COMMAND
    ' *****************
    IF CBCTL = ID_Button1 THEN
      PRINT "This is supposed to print to our console"
    END IF
    ' *****************
    CASE WM_CLOSE
    ' *****************
    LOCAL id
    id = MessageBox(        _
    hWnd,              _
    "Are you sure?",   _
    "Quit Program!",   _
    MB_YESNO OR MB_ICONQUESTION )
    IF id = IDYES THEN DestroyWindow (hWnd)
    EXIT FUNCTION
    ' *****************
    CASE WM_DESTROY
    ' *****************
    PostQuitMessage(0)
    EXIT FUNCTION
  END SELECT
END EVENTS


« Last Edit: August 28, 2020, 10:55:17 AM by MrBcx »

Robert

  • Hero Member
  • *****
  • Posts: 601
    • View Profile
Re: A CONSOLE + GUI novelty from LONG ago ...
« Reply #1 on: August 28, 2020, 02:53:40 AM »
I wrote this a long time ago ... someone might find a practical use for this technique.

Anyway, compile this as a console app, not a GUI app then run it.

It compiles and runs with Mingw, Clang, MSVC, LccWin32, and Pelles

Code: [Select]
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
'  I don't know how useful this is but it does demonstrate how it
'  is possible to startup in CONSOLE mode and conditionally switch
'  GUI mode.  Released to the public domain by Kevin Diggins.
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
'       Please compile this as a CONSOLE app, to see the full benefit.
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

SUB main()       ' main MUST be spelled using lower case
  LOCAL Tmp$
  INPUT "Do you wanna do the gui? ", Tmp$
  IF UCASE$(MID$(Tmp$,1,1)) = "Y" THEN
    WinMain(0,0,0,0)   ' Yes ... Call WINMAIN() from main() ... crazy, huh?
  ELSE
    END
  END IF
END SUB

'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

GUI "BCX GUI-Console"


SUB FormLoad
  CONST   ID_Button1 =  101
  GLOBAL Form1 AS HWND
  GLOBAL Button1 AS HWND

  Form1 = BCX_FORM("Con_Gui", 0, 0, 165, 120)
  Button1 = BCX_BUTTON ("Print message to Console Window", Form1, ID_Button1, 10, 42, 140, 14)

  CENTER (Form1)
  SHOW (Form1)
END SUB



BEGIN EVENTS
  SELECT CASE Msg
    ' *****************
    CASE WM_COMMAND
    ' *****************
    IF CBCTL = ID_Button1 THEN
      PRINT "This is supposed to print to our console"
    END IF
    ' *****************
    CASE WM_CLOSE
    ' *****************
    LOCAL id
    id = MessageBox(        _
    hWnd,              _
    "Are you sure?",   _
    "Quit Program!",   _
    MB_YESNO OR MB_ICONQUESTION )
    IF id = IDYES THEN DestroyWindow (hWnd)
    EXIT FUNCTION
    ' *****************
    CASE WM_DESTROY
    ' *****************
    PostQuitMessage(0)
    EXIT FUNCTION
  END SELECT
END EVENTS



Hi MrBCX:

I missed this when you posted it.

It seems vaguely familiar.

Maybe the same era before we knew about HIDE and SHOW and were hacking console apps with something from some malware coders toolbox so the console wouldn't show when running.

Anyway, the above is a nifty gadget. Thanks.

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 786
    • View Profile
Re: A CONSOLE + GUI novelty from LONG ago ...
« Reply #2 on: August 28, 2020, 05:26:59 PM »
Quote
Robert wrote:
Maybe the same era before we knew about HIDE and SHOW and were hacking console apps
with something from some malware coders toolbox so the console wouldn't show when running.

Nah ... it was more likely that I once read that we should never call Winmain directly, so of course
I had to do it, just so that I could see the virtual explosion for myself.  No explosion, no fireworks,
no loud bangs ... just an unsatisfying fizzle and a muffled thump.