Page 1 of 2

Console Cmd Window Create and SetFocus

Posted: Mon Nov 17, 2014 3:17 am
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 6272 times
and the zip project :
ReturnToDosWindow.zip
(3.17 KiB) Downloaded 326 times
TIA...

Best rgds,
Chang :)

PS : I love the preview feature... Thks alot... :D

Re: Console Cmd Window Create and SetFocus

Posted: Mon Nov 17, 2014 5:07 am
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

Re: Console Cmd Window Create and SetFocus

Posted: Wed Nov 19, 2014 12:59 am
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

Console Cmd Window Create and SetFocus

Posted: Mon Feb 23, 2015 10:58 pm
by Pablo César
probably this can help to your problem: viewtopic.php?f=45&t=4094&p=40041#p40041

Re: Console Cmd Window Create and SetFocus

Posted: Tue Feb 24, 2015 8:40 am
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." ????

Re: Console Cmd Window Create and SetFocus

Posted: Thu Feb 26, 2015 4:51 pm
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

Console Cmd Window Create and SetFocus

Posted: Thu Feb 26, 2015 4:56 pm
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... :?

Re: Console Cmd Window Create and SetFocus

Posted: Thu Feb 26, 2015 6:01 pm
by Javier Tovar
Sigue igual Pablo César!

Saludos

Re: Console Cmd Window Create and SetFocus

Posted: Thu Feb 26, 2015 7:10 pm
by andyglezl
A mi me da el mismo mensaje...
----------------------------------------
To me gives me the same message ...

Console Cmd Window Create and SetFocus

Posted: Fri Feb 27, 2015 1:09 pm
by Pablo César
Sorry to all for my mistake. I have posted in wrong place. :oops:

Now URLs it will be working...