Hide / Show a Console?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Zimbo
Posts: 56
Joined: Mon Nov 05, 2012 1:28 pm
Location: Scotland
Contact:

Hide / Show a Console?

Post by Zimbo »

Hi all,

I hope it is ok if I pick your brains again?

I am writing a small utility program which I am using to "dump" the contents of a multi-dimensional array to screen (a bit like print_r() in PHP). The simplest way to do this is for me in this situation is to use a console screen.

My question: is it possible to hide the console screen until I am ready to display text on it? The screen shot below shows the program when it starts running.

1. On line 2 of the source code I all REQUEST HB_GT_WIN_DEFAULT - when the program starts, the console screen (I added a red box around it in the image) appears before the main window (the one with a "Show Array" button). * I WANT TO HIDE THIS CONSOLE *

2. When the "Show Array" button is clicked, it calls the function on line 54 (ShowArray). This is when I want to *SHOW THE CONSOLE *

Maybe I have missed something simple? I tried SET CONSOLE OFF and SET CONSOLE ON but that did not work.

Thanks!

Zim


Code: Select all

#include "hmg.ch"
REQUEST HB_GT_WIN_DEFAULT

FUNCTION Main()

/*
    Sample program for Chapter 11 - Advanced Data Types
    This sample creates a multi-dimensional array which contains several different data types.
    Users can add more elements and / or change values as the learn about arrays. When rthe click
    on the "Show Array" button, the entire contents of the array, including all nested arrays, will
    be displayed on a console screen showing the element number, data type and value in
    that element.
    
*/

LOCAL nlblRow  :=  16
LOCAL nlblCol  :=  16

// Create a memory variable that will be an array
LOCAL aBigArray1 := {  }

/*
    Add the first two elements using the AADD array function. These are both arrays and each contains 5 elements
*/
AADD(aBigArray1, {.T., "Smith", Nil, "Married", "Customer"} )
AADD(aBigArray1, {".F.", "Jones", Nil, DATE(),  "Employee"} )

/*
    Add the next two elements using the AADD array function. The first one is an array that also contains another array
    at element position 3. The second one is also an array that also contains another array but this time at element
    position 4
*/
AADD(aBigArray1, { "Paul", "Brown", {"Mary", "Bob", "Billy"}, "Married",   "Employee" } )
AADD(aBigArray1, { "Mike", "White", Nil,                      {16, 5, 22}, "Customer"} )
AADD(aBigArray1, "Customer" )

SET FONT TO "Arial", 10
SET DATE BRITISH
SET CONSOLE OFF

DEFINE WINDOW Win_1 ; 
    AT 0,0 ;
    WIDTH  704 ;
    HEIGHT 480 ;
    TITLE "Array Test Three" ;
    MAIN

    DEFINE BUTTON btn_01
        ROW nlblRow * 3
        COL nlblCol
        CAPTION "Show Array"
        AUTOSIZE .T.
        ONCLICK ShowArray(aBigArray1)
    END BUTTON


END WINDOW

CENTER WINDOW Win_1
ACTIVATE WINDOW Win_1
    
Return Nil    /* -- End of FUNCTION Main() -- */

FUNCTION ShowArray(aArray)

LOCAL nRow := 1
LOCAL nCol := 2
LOCAL cText := ""

SetMode(75, 100)
CLS

@ ++nRow, nCol SAY "Number of elements in this array: " + ALLTRIM(STR(LEN(aArray)))
++nRow

ShowElement(aArray, @nRow, nCol)

RETURN Nil  /* -- End of FUNCTION ShowArray() -- */

FUNCTION ShowElement(aArray, nRow, nCol)

LOCAL i := 0

FOR i := 1 TO LEN(aArray)

    IF VALTYPE(aArray[i]) == "U"
            @ ++nRow, nCol SAY "-> Element " + ALLTRIM(STR(i)) + " - * NIL *"
        ELSEIF VALTYPE(aArray[i]) == "B"
            @ ++nRow, nCol SAY "-> Element " + ALLTRIM(STR(i)) + " - * CODE BLOCK *"
        ELSEIF VALTYPE(aArray[i]) == "C"
            @ ++nRow, nCol SAY "-> Element " + ALLTRIM(STR(i)) + " - 'CHARACTER' - value: " + aArray[i]
        ELSEIF VALTYPE(aArray[i]) == "N"
            @ ++nRow, nCol SAY "-> Element " + ALLTRIM(STR(i)) + " - 'NUMERIC' - value: " + STR(aArray[i])
        ELSEIF VALTYPE(aArray[i]) == "L"
            @ ++nRow, nCol SAY "-> Element " + ALLTRIM(STR(i)) + " - 'LOGICAL' - value: " + IIF(aArray[i], "True", "False")
        ELSEIF VALTYPE(aArray[i]) == "D"
            @ ++nRow, nCol SAY "-> Element " + ALLTRIM(STR(i)) + " - 'DATE'  - value: " + DTOC(aArray[i])
        ELSE
            @ ++nRow, nCol SAY "-> Element " + ALLTRIM(STR(i)) + " - 'ARRAY' "
            ShowElement(aArray[i], @nRow, nCol + 5)
    ENDIF
    
NEXT i

Return Nil  /* -- End of FUNCTION ShowElement() -- */

/* -- End of file -- */
Attachments
Console.jpg
Console.jpg (105.29 KiB) Viewed 5504 times
Zimbo
Posts: 56
Joined: Mon Nov 05, 2012 1:28 pm
Location: Scotland
Contact:

Re: Hide / Show a Console?

Post by Zimbo »

This is how it looks with the code after I clicked "Show Array", by the way!

Attachments
Dumped.jpg
Dumped.jpg (114.23 KiB) Viewed 5500 times
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Hide / Show a Console?

Post by Rathinagiri »

Why don't you use a GRID for this?
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
KDJ
Posts: 243
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland

Re: Hide / Show a Console?

Post by KDJ »

Zimbo

To show/hide a console window you can use ShowWindow() and HideWindow() functions.

Code: Select all

#include "hmg.ch"
REQUEST HB_GT_WIN_DEFAULT

FUNCTION Main()

/*
    Sample program for Chapter 11 - Advanced Data Types
    This sample creates a multi-dimensional array which contains several different data types.
    Users can add more elements and / or change values as the learn about arrays. When rthe click
    on the "Show Array" button, the entire contents of the array, including all nested arrays, will
    be displayed on a console screen showing the element number, data type and value in
    that element.
   
*/

LOCAL nlblRow  :=  16
LOCAL nlblCol  :=  16

// Create a memory variable that will be an array
LOCAL aBigArray1 := {  }


LOCAL nHConsole := GetForegroundWindow()

IF (nHConsole != 0)
  IF (GetClassName(nHConsole) == 'ConsoleWindowClass')
    HideWindow(nHConsole)
  ELSE
    nHConsole := 0
  ENDIF
ENDIF


/*
    Add the first two elements using the AADD array function. These are both arrays and each contains 5 elements
*/
AADD(aBigArray1, {.T., "Smith", Nil, "Married", "Customer"} )
AADD(aBigArray1, {".F.", "Jones", Nil, DATE(),  "Employee"} )

/*
    Add the next two elements using the AADD array function. The first one is an array that also contains another array
    at element position 3. The second one is also an array that also contains another array but this time at element
    position 4
*/
AADD(aBigArray1, { "Paul", "Brown", {"Mary", "Bob", "Billy"}, "Married",   "Employee" } )
AADD(aBigArray1, { "Mike", "White", Nil,                      {16, 5, 22}, "Customer"} )
AADD(aBigArray1, "Customer" )

SET FONT TO "Arial", 10
SET DATE BRITISH
//SET CONSOLE OFF

DEFINE WINDOW Win_1 ;
    AT 0,0 ;
    WIDTH  704 ;
    HEIGHT 480 ;
    TITLE "Array Test Three" ;
    MAIN

    DEFINE BUTTON btn_01
        ROW nlblRow * 3
        COL nlblCol
        CAPTION "Show Array"
        AUTOSIZE .T.
        ONCLICK (ShowWindow(nHConsole), ShowArray(aBigArray1))
    END BUTTON
END WINDOW

CENTER WINDOW Win_1
ACTIVATE WINDOW Win_1
   
Return Nil    /* -- End of FUNCTION Main() -- */

FUNCTION ShowArray(aArray)

LOCAL nRow := 1
LOCAL nCol := 2
LOCAL cText := ""

SetMode(75, 100)
CLS

@ ++nRow, nCol SAY "Number of elements in this array: " + ALLTRIM(STR(LEN(aArray)))
++nRow

ShowElement(aArray, @nRow, nCol)

RETURN Nil  /* -- End of FUNCTION ShowArray() -- */

FUNCTION ShowElement(aArray, nRow, nCol)

LOCAL i := 0

FOR i := 1 TO LEN(aArray)

    IF VALTYPE(aArray[i]) == "U"
            @ ++nRow, nCol SAY "-> Element " + ALLTRIM(STR(i)) + " - * NIL *"
        ELSEIF VALTYPE(aArray[i]) == "B"
            @ ++nRow, nCol SAY "-> Element " + ALLTRIM(STR(i)) + " - * CODE BLOCK *"
        ELSEIF VALTYPE(aArray[i]) == "C"
            @ ++nRow, nCol SAY "-> Element " + ALLTRIM(STR(i)) + " - 'CHARACTER' - value: " + aArray[i]
        ELSEIF VALTYPE(aArray[i]) == "N"
            @ ++nRow, nCol SAY "-> Element " + ALLTRIM(STR(i)) + " - 'NUMERIC' - value: " + STR(aArray[i])
        ELSEIF VALTYPE(aArray[i]) == "L"
            @ ++nRow, nCol SAY "-> Element " + ALLTRIM(STR(i)) + " - 'LOGICAL' - value: " + IIF(aArray[i], "True", "False")
        ELSEIF VALTYPE(aArray[i]) == "D"
            @ ++nRow, nCol SAY "-> Element " + ALLTRIM(STR(i)) + " - 'DATE'  - value: " + DTOC(aArray[i])
        ELSE
            @ ++nRow, nCol SAY "-> Element " + ALLTRIM(STR(i)) + " - 'ARRAY' "
            ShowElement(aArray[i], @nRow, nCol + 5)
    ENDIF
   
NEXT i

Return Nil  /* -- End of FUNCTION ShowElement() -- */

/* -- End of file -- */
Zimbo
Posts: 56
Joined: Mon Nov 05, 2012 1:28 pm
Location: Scotland
Contact:

Re: Hide / Show a Console?

Post by Zimbo »

Brilliant, KDJ. That works perfectly for the purpose I intended!

Rathinagiri, I have avoided GRID on this occasion as the program is part of my guide and I am trying to keep it as simple as possible at this stage. I do intend to cover GRID but at a much later on in the guide!

Zim
chrisjx2002
Posts: 190
Joined: Wed Jan 06, 2010 5:39 pm

Re: Hide / Show a Console?

Post by chrisjx2002 »

Very interesting example!

How to close the console window and go back to the main window?
User avatar
serge_girard
Posts: 3166
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Hide / Show a Console?

Post by serge_girard »

Zimbo:

ON RELEASE Form_xxx.Show


Serge
There's nothing you can do that can't be done...
chrisjx2002
Posts: 190
Joined: Wed Jan 06, 2010 5:39 pm

Re: Hide / Show a Console?

Post by chrisjx2002 »

I try ON KEY ESCAPE ACTION Win_1.show but it does not work in console mode
KDJ
Posts: 243
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland

Re: Hide / Show a Console?

Post by KDJ »

chrisjx2002 wrote: How to close the console window and go back to the main window?
Example:

Code: Select all

#include "hmg.ch"
REQUEST HB_GT_WIN_DEFAULT

STATIC nHConsole

FUNCTION Main()

/*
    Sample program for Chapter 11 - Advanced Data Types
    This sample creates a multi-dimensional array which contains several different data types.
    Users can add more elements and / or change values as the learn about arrays. When rthe click
    on the "Show Array" button, the entire contents of the array, including all nested arrays, will
    be displayed on a console screen showing the element number, data type and value in
    that element.
   
*/

LOCAL nlblRow  :=  16
LOCAL nlblCol  :=  16

// Create a memory variable that will be an array
LOCAL aBigArray1 := {  }


nHConsole := GetForegroundWindow()

IF (nHConsole != 0)
  IF (GetClassName(nHConsole) == "ConsoleWindowClass")
    HideWindow(nHConsole)
  ELSE
    nHConsole := 0
  ENDIF
ENDIF

IF (nHConsole == 0)
  MsgBox("Console window not found!")
  QUIT
ENDIF

/*
    Add the first two elements using the AADD array function. These are both arrays and each contains 5 elements
*/
AADD(aBigArray1, {.T., "Smith", Nil, "Married", "Customer"} )
AADD(aBigArray1, {".F.", "Jones", Nil, DATE(),  "Employee"} )

/*
    Add the next two elements using the AADD array function. The first one is an array that also contains another array
    at element position 3. The second one is also an array that also contains another array but this time at element
    position 4
*/
AADD(aBigArray1, { "Paul", "Brown", {"Mary", "Bob", "Billy"}, "Married",   "Employee" } )
AADD(aBigArray1, { "Mike", "White", Nil,                      {16, 5, 22}, "Customer"} )
AADD(aBigArray1, "Customer" )

SET FONT TO "Arial", 10
SET DATE BRITISH
//SET CONSOLE OFF

DEFINE WINDOW Win_1 ;
    AT 0,0 ;
    WIDTH  704 ;
    HEIGHT 480 ;
    TITLE "Array Test Three" ;
    MAIN

    DEFINE BUTTON btn_01
        ROW nlblRow * 3
        COL nlblCol
        WIDTH 120
        CAPTION "Show Array"
        ONCLICK ShowArray(aBigArray1)
    END BUTTON

    DEFINE BUTTON btn_02
        ROW nlblRow * 5
        COL nlblCol
        WIDTH 120
        CAPTION "Show/hide console"
        ONCLICK ShowHideConsole()
    END BUTTON
END WINDOW

IF (nHConsole == 0)
  Win_1.btn_02.ENABLED := .F.
ENDIF

CENTER WINDOW Win_1
ACTIVATE WINDOW Win_1
   
Return Nil    /* -- End of FUNCTION Main() -- */

FUNCTION ShowHideConsole()

  IF IsWindowVisible(nHConsole)
    HideWindow(nHConsole)
  ELSE
    ShowWindow(nHConsole)
  ENDIF

  Win_1.SETFOCUS

RETURN NIL

FUNCTION ShowArray(aArray)

LOCAL nRow := 1
LOCAL nCol := 2
LOCAL cText := ""

IF ! IsWindowVisible(nHConsole)
  ShowWindow(nHConsole)
ENDIF

SetMode(75, 100)
CLS

@ ++nRow, nCol SAY "Number of elements in this array: " + ALLTRIM(STR(LEN(aArray)))
++nRow

ShowElement(aArray, @nRow, nCol)

RETURN Nil  /* -- End of FUNCTION ShowArray() -- */

FUNCTION ShowElement(aArray, nRow, nCol)

LOCAL i := 0

FOR i := 1 TO LEN(aArray)

    IF VALTYPE(aArray[i]) == "U"
            @ ++nRow, nCol SAY "-> Element " + ALLTRIM(STR(i)) + " - * NIL *"
        ELSEIF VALTYPE(aArray[i]) == "B"
            @ ++nRow, nCol SAY "-> Element " + ALLTRIM(STR(i)) + " - * CODE BLOCK *"
        ELSEIF VALTYPE(aArray[i]) == "C"
            @ ++nRow, nCol SAY "-> Element " + ALLTRIM(STR(i)) + " - 'CHARACTER' - value: " + aArray[i]
        ELSEIF VALTYPE(aArray[i]) == "N"
            @ ++nRow, nCol SAY "-> Element " + ALLTRIM(STR(i)) + " - 'NUMERIC' - value: " + STR(aArray[i])
        ELSEIF VALTYPE(aArray[i]) == "L"
            @ ++nRow, nCol SAY "-> Element " + ALLTRIM(STR(i)) + " - 'LOGICAL' - value: " + IIF(aArray[i], "True", "False")
        ELSEIF VALTYPE(aArray[i]) == "D"
            @ ++nRow, nCol SAY "-> Element " + ALLTRIM(STR(i)) + " - 'DATE'  - value: " + DTOC(aArray[i])
        ELSE
            @ ++nRow, nCol SAY "-> Element " + ALLTRIM(STR(i)) + " - 'ARRAY' "
            ShowElement(aArray[i], @nRow, nCol + 5)
    ENDIF
   
NEXT i

Return Nil  /* -- End of FUNCTION ShowElement() -- */

/* -- End of file -- */
chrisjx2002
Posts: 190
Joined: Wed Jan 06, 2010 5:39 pm

Re: Hide / Show a Console?

Post by chrisjx2002 »

Thanks for this example.

When I close the console window(click on the X), it closes the main window too. How to prevent that?
Post Reply