SetFocus question.

SetFocus question.

Postby HunterEC » Mon Sep 12, 2016 8:50 am

Guys:

I'm calling a program from another. The called program executes this command:
Code: Select all  Expand view
        ACTIVATE DIALOG oDlg ON PAINT SetFocus( FindWindow( 0, cCaller ) )
 


This other command:
Code: Select all  Expand view
MsgInfo( "Find Window: " + STR( FindWindow( 0, cCaller ), 12 ) )


Displays the window handle (numeric).

But control does not return to the caller program (first one). Any clues ?
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Re: SetFocus question.

Postby karinha » Mon Sep 12, 2016 12:49 pm

Code: Select all  Expand view

   ACTIVATE DIALOG oDlg ON INIT SetFocus( FindWindow( 0, cCaller ) )
 


Regards.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7237
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: SetFocus question.

Postby HunterEC » Mon Sep 12, 2016 9:32 pm

Karinha:

Thank you for the response but does not work. Any clues ?
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Re: SetFocus question.

Postby Gale FORd » Mon Sep 12, 2016 10:33 pm

What Windows version are you using?
You might try a combination of
Code: Select all  Expand view

nCaller := FindWindow( 0, cCaller )
ACTIVATE DIALOG oDlg ON INIT ( SysRefresh(), SetFocus( nCaller ), SetForeGroundWindow( nCaller ) )
 
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Re: SetFocus question.

Postby HunterEC » Tue Sep 13, 2016 5:16 am

Gale:

Thank you for your response but it did not worked. I'm using Windows 10 Pro x86 & x64.

I think Cristobal, Rao, Uwe or Antonio or any other great people here at the forum (which I'm missing the names) can help us out.
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Re: SetFocus question.

Postby Antonio Linares » Tue Sep 13, 2016 7:34 am

Gustavo,

Please provide a small and self contained example to test here, thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41319
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: SetFocus question.

Postby HunterEC » Tue Sep 13, 2016 10:45 pm

Antonio:

Caller Program (Harbour console program)
Code: Select all  Expand view
                 cOldCap := GetConsoleTitle()
                  cCommand := "EXTCMD.EXE " + "IMAGE IMAGES\" + ALLTRIM(Img_filenm) + ".JPG" + " " + ["] + Img_name + ["] + " " + ["] + cOldCap + ["]
                  cCaption := ALLTRIM( Img_name ) + "
- Software (C) Ver. 1.0"
                  RUN ( "
&cCommand" )


EXTCMD.EXE (used to avoid caller program to be tied to called one until it closes. This way caller program can continue without called one being closed)
Code: Select all  Expand view
#include "Common.ch"


PROCEDURE Main ( cCommand, cArg1, cArg2, cArg3, cArg4 )
   MEMVAR cCmd, cParms

   PRIVATE cCmd, cParms := ""

   DEFAULT cCommand TO ""
   DEFAULT cArg1    TO ""
   DEFAULT cArg2    TO ""
   DEFAULT cArg3    TO ""
   DEFAULT cArg4    TO ""

   cCmd  := cCommand

   IF VALTYPE( cArg1 ) == "C" .AND. VALTYPE( cArg2 ) == "C" .AND. ;
      VALTYPE( cArg3 ) == "C"

      cParms := ["] + cArg1 + ["] + " " + ["] + cArg2 + ["] + " " + ["] + cArg3 + ["]
   ELSE
      cParms := cArg1
   ENDIF

   IF VALTYPE( cCmd ) == "C"
      IF cParms != NIL .AND. LEFT( cParms, 1 ) != CHR( 34 )
         cParms := CHR( 34 ) + cParms
      ENDIF
      IF cParms != NIL .AND. RIGHT( cParms, 1 ) != CHR( 34 )
         cParms := cParms + CHR( 34 )
      ENDIF

      DEFAULT cParms TO ""

      RUN START /I /B &cCmd &cParms
   ENDIF
RETURN
// EOP: Main



Called program (image.exe):
Code: Select all  Expand view
#define NO_OF_COLS   INT( GetSysMetrics( 0 ) / 7.933884297520661157 )
#define NO_OF_ROWS   INT( GetSysMetrics( 1 ) / 15.18987341772151898 )

// #define NO_OF_COLS   242
// #define NO_OF_ROWS   77


#include "Common.ch"
#include "Fivewin.ch"
#include "Image.ch"


//----------------------------------------------------------------------------//

function Main ( cFile, cImgName, cCaller )
   LOCAL oDlg, oSay1, oImage, nCaller

   DEFINE DIALOG oDlg ;
      TITLE ALLTRIM( cImgName ) + " - Software (C) Ver. 1.0"
   oDlg:nTop    := GetSysMetrics( 1 ) - 250 - 65
   oDlg:nLeft   := GetSysMetrics( 0 ) - 377 - 10
   oDlg:nBottom := GetSysMetrics( 1 ) - 65
   oDlg:nRight  := GetSysMetrics( 0 ) - 10

   @ 00,00 SAY oSay1 VAR cImgName OF oDlg CENTERED PIXEL SIZE 145,10;
          COLOR nRGB(255,255,255), nRGB(0,0,255)
   @ 10,00 IMAGE oImage SIZE 150, 140 OF oDlg SCROLL PIXEL // ADJUST

   @ 10,155 BUTTON "&Imprimir" SIZE 30,10 OF oDlg PIXEL ACTION PrintImage( oImage )

   @ 55,155 BUTTON "&Terminar" SIZE 30,10 OF oDlg PIXEL ACTION oDlg:End()

   @ 110,155 CHECKBOX oImage:lStretch PROMPT "&Agrandar" SIZE 75, 10 OF oDlg ;
             PIXEL ON CHANGE ( oImage:ScrollAdjust(), oImage:Refresh() )

   IF OpenFile ( @oImage, @cFile )
         nCaller := FindWindow( 0, cCaller )
         ACTIVATE DIALOG oDlg ON INIT ( SysRefresh(), SetFocus( nCaller ), SetForeGroundWindow( nCaller ) )
//         ACTIVATE DIALOG oDlg ON INIT SetFocus( FindWindow( 0, cCaller ) )
   ENDIF
return nil
// EOF: Main

//----------------------------------------------------------------------------//

FUNCTION OpenFile (oImage, cFile)
   LOCAL lPass

   IF ! (lPass := FILE(cFile))
      MsgInfo("Esta Imagen No Existe: " + cFile)
   ELSE
      oImage:LoadBmp(cFile)
   ENDIF
RETURN (lPass)
* EOF: OpenFile


FUNCTION PrintImage( oImage )

   LOCAL oPrn

   PRINT oPrn NAME "Image Printing" PREVIEW
      PAGE
         oPrn:SayImage( 0, 0, oImage )
      ENDPAGE
   ENDPRINT

RETURN NIL
* EOF: PrintImage

//----------------------------------------------------------------------------//
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Re: SetFocus question.

Postby Antonio Linares » Wed Sep 14, 2016 8:02 am

Gustavo,

Try to use SetForeGroundWindow( hWnd ) instead of SetFocus( hWnd )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41319
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: SetFocus question.

Postby HunterEC » Mon Sep 19, 2016 6:44 pm

Antonio:

Thank you for your response but it didn't worked, it stayed in the called program. Any ideas ?
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Re: SetFocus question.

Postby Antonio Linares » Tue Sep 20, 2016 9:37 am

Gustavo,

The initial caller app is a console app (text mode), right ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41319
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: SetFocus question.

Postby HunterEC » Wed Oct 12, 2016 2:13 am

Yes, console app.
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Re: SetFocus question.

Postby Antonio Linares » Wed Oct 12, 2016 10:03 am

It seems to be the function to use:

GetConsoleWindow function

Retrieves the window handle used by the console associated with the calling process.


https://msdn.microsoft.com/en-us/library/ms683175.aspx

once we have such handle, we can call SetFocus() :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41319
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: SetFocus question.

Postby HunterEC » Fri Oct 14, 2016 6:11 am

Antonio:

How do I call that function from Harbour ? Thank you very much !
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Re: SetFocus question.

Postby Antonio Linares » Fri Oct 14, 2016 7:27 am

Gustavo,

Copia este código al final de tu PRG principal

Code: Select all  Expand view
#pragma BEGINDUMP

#include <windows.h>
#include <hbapi.h>

HB_FUNC( GETCONSOLEWINDOW )
{
   hb_retnll( GetConsoleWindow() );
}

#pragma ENDDUMP
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41319
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: SetFocus question.

Postby HunterEC » Mon Feb 20, 2017 3:02 pm

Having this at the bottom of my main FW .PRG gives me 2 compiler errors, eventhough it links and creates the executable (EXE).

Code: Select all  Expand view
Embarcadero C++ 7.00 for Win32 Copyright (c) 1993-2015 Embarcadero Technologies, Inc.
test.c:
Error E2451 test.prg 304: Undefined symbol 'buffer' in function HB_FUN_GETCONSOLEWINDOW
Error E2451 test.prg 304: Undefined symbol 'dwSize' in function HB_FUN_GETCONSOLEWINDOW
*** 2 errors in Compile ***
Borland Resource Compiler  Version 5.40
Copyright (c) 1990, 1999 Inprise Corporation.  All rights reserved.
Turbo Incremental Link 6.70 Copyright (c) 1997-2014 Embarcadero Technologies, Inc.
* Application successfully built *


Code: Select all  Expand view

#pragma BEGINDUMP

#include <windows.h>
#include <hbapi.h>

HB_FUNC( GETCONSOLEWINDOW )
{
   hb_retclen( buffer, dwSize );
}

#pragma ENDDUMP
 
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 13 guests