Form with console panel

Moderator: Rathinagiri

Post Reply
User avatar
hmgchang
Posts: 239
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia
Has thanked: 1 time
Been thanked: 4 times

Form with console panel

Post by hmgchang » Sun Jun 03, 2018 10:17 pm

Dear Friends,

Is it possible to have a form with console panel inside ?
DosInForm.JPG
Form with console panel inside
DosInForm.JPG (25.9 KiB) Viewed 269 times
TIA

best rgds,
Chang
Just Hmg It !

KDJ
Posts: 205
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland
Been thanked: 242 times

Post by KDJ » Tue Jun 05, 2018 8:21 pm

Chang, you can try in this way:

Code: Select all

#include "hmg.ch"

REQUEST HB_GT_WIN_DEFAULT

MEMVAR _HMG_SYSDATA

FUNCTION Main()

  DEFINE WINDOW MainForm;
    WIDTH  700;
    HEIGHT 500;
    MAIN;
    ON INIT  MainFormOnInit();
    ON PAINT RedrawWindow(GetConsoleWindow())

    DEFINE BUTTON WriteButton
      ROW     430
      COL     10
      WIDTH   130
      HEIGHT  25
      CAPTION "Write in console"
      ACTION  WriteInConsole()
    END BUTTON
  END WINDOW

  MainForm.CENTER
  MainForm.ACTIVATE

RETURN NIL

FUNCTION MainFormOnInit()
  LOCAL nHWndConsole := GetConsoleWindow()

  IF nHWndConsole != 0
    IF SetParent(nHWndConsole, MainForm.HANDLE) != 0
      SetMode(25, 80)
      SetWindowPos(nHWndConsole, 0, 10, 10, 0, 0, 0x15 /*SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOSIZE*/)
      RedrawWindow(nHWndConsole)
    ENDIF

    MainForm.WriteButton.SETFOCUS

    ? "0"
  ENDIF

RETURN NIL

FUNCTION WriteInConsole()
  STATIC n := 0

  IF GetConsoleWindow() != 0
    ? HB_Ntos(++n)
  ENDIF

RETURN NIL

#pragma BEGINDUMP
#include <windows.h>
#include "hbapi.h"
#include "SET_COMPILE_HMG_UNICODE.ch"
#include "HMG_UNICODE.h"

HB_FUNC( GETCONSOLEWINDOW )
{
  HMG_retnl((LONG_PTR) GetConsoleWindow());
}
#pragma ENDDUMP

User avatar
hmgchang
Posts: 239
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia
Has thanked: 1 time
Been thanked: 4 times

Post by hmgchang » Tue Jun 05, 2018 8:40 pm

Thanks KDJ,
it works but it seem that I cannot activate/type the console as usual ?
Anyway to work around ? or can we have it function like a DOS Shell ?

TIA

best rgds,
Chang
Just Hmg It !

KDJ
Posts: 205
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland
Been thanked: 242 times

Post by KDJ » Wed Jun 06, 2018 8:24 pm

Chang
I don't understand what console you need.
Do you mean command console (cmd)?

User avatar
hmgchang
Posts: 239
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia
Has thanked: 1 time
Been thanked: 4 times

Post by hmgchang » Wed Jun 06, 2018 9:32 pm

Thanks KDJ,
my mistake.. I hv to code something to to console to work with....

Thanks again Sir...

best rgds,
Chang
Just Hmg It !

Post Reply