Console Cmd Window Create and SetFocus

Moderator: Rathinagiri

User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Console Cmd Window Create and SetFocus

Post by hmgchang »

Dear Masters,

On a mixed console Gui program,
how can i :
1. create a new Cmd Window ?
2. set focus to the Cmd Window ?

pls look at the ssw :

Code: Select all

#include <hmg.ch>
REQUEST HB_GT_WIN_DEFAULT  && GT_WIN OR GT_GUI this make a console text mode

Function Main

        Load Window Main
        Main.Center
        Main.Activate

Return

FUNCTION Main_OnInit()
  cString := " I need two helps : " + HB_EOL() + ;
             " 1. Create a New Cmd Window " + HB_EOL() + ;
             " 2. Set the Cmd Window Focus " + HB_EOL() +  HB_EOL() + ;
             "TIA." + HB_EOL() + ;
             "Best rgds, " + HB_EOL() + ;
             "Chang..."
  Main.Edit_1.Value := cString           
  RETURN NIL

FUNCTION btnNewwinWindow_Action()
  IF IsWindowDefined( NewWinWindow)
    MsgInfo( "NewWinWindow Defined !")
  ELSE
    LOAD Window NewWinWindow
    NewWinWindow.Activate
  ENDIF
  
  RETURN NIL
  
FUNCTION btnNewWinWindowSetFocus_Action()  
  IF IsWindowDefined( NewWinWindow)
    NewWinWindow.SetFocus
  ELSE
    MsgInfo( "NewWinWindow NOT defined !")
  ENDIF
  RETURN NIL
  
FUNCTION btnNewCmdWindow_Action()
  MsgInfo( "Pls Help me to define NEW Cmd Window !")
  RETURN NIL
  
FUNCTION btnCmdSetFocus_Action()  
  MsgInfo( "Pls help me to make the Cmd Window Focus !")
  RETURN NIL
  
CmdWindow.JPG
CmdWindow.JPG (32.52 KiB) Viewed 6072 times
and the zip project :
ReturnToDosWindow.zip
(3.17 KiB) Downloaded 315 times
TIA...

Best rgds,
Chang :)

PS : I love the preview feature... Thks alot... :D
Just Hmg It !
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: Console Cmd Window Create and SetFocus

Post by bpd2000 »

Once you have handle of any window, you can go further
Find example to get handle of console window

Code: Select all

/*
 bpd2000
 Get Handle of Console Window
*/

REQUEST HB_GT_WIN_DEFAULT

Function Main
SETMODE(25,80)

l := GETCONSOLEWINDOWHANDLE()

? "GETCONSOLEWINDOWHANDLE() = " + ALLTRIM(STR(L))
? GETWINDOWTHREADPROCESSID(l)
? "GETWNDTASK() " +  ALLTRIM(STR(GETWNDTASK(l)))

Wait "Press any key to quit"

RETURN NIL


#pragma BEGINDUMP
#define WINVER 0x0600 // for Vista
#define _WIN32_WINNT 0x0600 // for Vista

#include "windows.h"
#include "hbapi.h"

HB_FUNC( GETCONSOLEWINDOWHANDLE )
{
HWND hwnd;
AllocConsole();
hwnd = FindWindowA("ConsoleWindowClass",NULL);
hb_retnl( (LONG) hwnd );
}

HB_FUNC( GETWINDOWTHREADPROCESSID ) // hWnd --> nThread
{
   #ifndef _WIN64
      hb_retnl( GetWindowThreadProcessId( ( HWND ) hb_parnl( 1 ), NULL ) );
   #else   
      hb_retnll( GetWindowThreadProcessId( ( HWND ) hb_parnll( 1 ), NULL ) );
   #endif
}   	

HB_FUNC( GETWNDTASK )
{
	 #ifndef _WIN64
      hb_retnl( ( LONG ) GetWindowTask( ( HWND ) hb_parnl( 1 ) ) );
   #else   
      hb_retnll( ( LONGLONG ) GetWindowTask( ( HWND ) hb_parnll( 1 ) ) );
   #endif
}

#pragma ENDDUMP
BPD
Convert Dream into Reality through HMG
User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Re: Console Cmd Window Create and SetFocus

Post by hmgchang »

Thank you Sir for the info,
i tried google but all the infos are so low level...
yet i still dont get it how to use or related to hmg...

Could You please show how to do it from HMG ?

TIA


best rgds,
Chang
Just Hmg It !
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Console Cmd Window Create and SetFocus

Post by Pablo César »

probably this can help to your problem: viewtopic.php?f=45&t=4094&p=40041#p40041
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: Console Cmd Window Create and SetFocus

Post by bpd2000 »

Pablo César wrote:probably this can help to your problem: viewtopic.php?f=45&t=4094&p=40041#p40041
When I visit above link, I receive message like "You are not authorised to read this forum." ????
BPD
Convert Dream into Reality through HMG
Javier Tovar
Posts: 1275
Joined: Tue Sep 03, 2013 4:22 am
Location: Tecámac, México

Re: Console Cmd Window Create and SetFocus

Post by Javier Tovar »

bpd2000 wrote:
Pablo César wrote:probably this can help to your problem: viewtopic.php?f=45&t=4094&p=40041#p40041
When I visit above link, I receive message like "You are not authorised to read this forum." ????
+1
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Console Cmd Window Create and SetFocus

Post by Pablo César »

bpd2000 wrote:
Pablo César wrote:probably this can help to your problem: viewtopic.php?f=45&t=4094&p=40041#p40041
When I visit above link, I receive message like "You are not authorised to read this forum." ????
Please try this one:

viewtopic.php?p=40041#p40041

I do not know what is happing with these URLs... :?
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
Javier Tovar
Posts: 1275
Joined: Tue Sep 03, 2013 4:22 am
Location: Tecámac, México

Re: Console Cmd Window Create and SetFocus

Post by Javier Tovar »

Sigue igual Pablo César!

Saludos
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: Console Cmd Window Create and SetFocus

Post by andyglezl »

A mi me da el mismo mensaje...
----------------------------------------
To me gives me the same message ...
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Console Cmd Window Create and SetFocus

Post by Pablo César »

Sorry to all for my mistake. I have posted in wrong place. :oops:

Now URLs it will be working...
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
Post Reply