Can I get object from handle?

Can I get object from handle?

Postby Horizon » Thu Apr 13, 2023 11:20 am

Hi,

I have two application of uses fwh.

First one is testfont.prg that is changed a little bit in fwh sample directory.
Code: Select all  Expand view  RUN
// Testing fonts

#include "FiveWin.ch"

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

function Main()

   local oWnd, fntArial, oSay

   DEFINE WINDOW oWnd FROM 1, 1 TO 20, 80 ;
      TITLE "Testing Fonts"

   DEFINE FONT fntArial NAME "Arial" SIZE 0, -25

   @ 2, 2 SAY oSay PROMPT "Hello world" FONT fntArial SIZE 180, 80
   oWnd:cargo:=oSay

   ACTIVATE WINDOW oWnd

   fntArial:End()

return nil

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


Second is
Code: Select all  Expand view  RUN
#include "FiveWin.ch"

// run testfont.prg before this


PROCEDURE Main()
    local oFont, oWnd, oBtn
    DEFINE FONT oFont NAME "Arial" SIZE 0, -25  

    DEFINE WINDOW oWnd FROM 30, 10 TO 40, 80 ;
      TITLE "My Test Windows"

    @ 1,3 BUTTON oBtn PROMPT "Change Hello World to HeyHeyHey" size 500,50 font oFont OF oWnd ACTION MyAction(oWnd)
    oWnd:cargo := oBtn

    ACTIVATE WINDOW oWnd
RETURN

FUNCTION MyAction(oWnd)
LOCAL cTestApp := "Testing Fonts", hWnd, hWnd_W, oWnd1
    //MsgInfo("Button pressed")
   
    hWnd := FindWindow( 0, cTestApp)
    IF !EMPTY(hWnd)
    ? "FOUND", hWnd, cTestApp
        BringWindowToTop( hWnd )
        hWnd_W := GetWindow(hWnd,0)
        ? hWnd, hWnd_W, "hWnd, hWnd from GetWindow()"
       
         
        oWnd1 := oWndFromhWnd(hWnd)
        xbrowser oWnd1
        ? oWnd1, oWnd1 == nil

        IF oWnd1 != nil
            oWnd1:SetFocus()
            oWnd1:ocargo:SetText("HeyHeyHey")
        ENDIF
    ELSE
        MsgAlert("Run testfont app before pressing button.")   
    ENDIF   
   
   
RETURN .T.


These can be builded via buildh32.bat in sample directory.

First run testfont application. then run MyWTest1 application. I want to change say prompt "Hello World" text in testfont to "HeyHeyHey" from pressing in MyTestTest1 application. I can not found the object.

I think oWndfromhWnd() function can only find objects within the same application.

Is there any idea?
Thanks.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: Can I get object from handle?

Postby karinha » Thu Apr 13, 2023 12:11 pm

Sorry, I didn't quite understand your question.

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

Re: Can I get object from handle?

Postby Horizon » Thu Apr 13, 2023 12:18 pm

karinha wrote:Sorry, I didn't quite understand your question.

Regards.

I have 2 applications compiled with fwh. the first one has a "SAY" object. the other has a button. When I press the button from the other program, I want to change the text of the say object in the first program.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: Can I get object from handle?

Postby karinha » Thu Apr 13, 2023 1:54 pm

Code: Select all  Expand view  RUN

// C:\FWH..\SAMPLES\HORIZON1.PRG

#include "FiveWin.ch"

#Define CLR_ORANGE     nRGB( 255, 165, 000 )

FUNCTION Change_Horizon()

   LOCAL oBtn, oSay, oFont
   LOCAL oWnd, FntArial, cSay := "Hello world" + SPACE(30)

   SET DATE TO AMERICAN

   HB_GCALL( .F. )

   DEFINE FONT fntArial NAME "Arial" SIZE 0, -25
   DEFINE FONT oFont    NAME "Arial" SIZE 0, -30 BOLD

   DEFINE WINDOW oWnd FROM 0, 0 TO 20, 80 TITLE "Change SAY in Time Real"

   @ 7.50, 10 SAY oSay VAR cSay FONT oFont SIZE 500, 80 OF oWnd UPDATE       ;
      COLORS CLR_ORANGE, CLR_WHITE TRANSPARENT CENTER

   @ 1, 10 BUTTON oBtn PROMPT "Change Hello World to HeyHeyHey" SIZE 500, 30 ;
      OF oWnd FONT FntArial ACTION( Cambia_Horizon( oSay ) )

   ACTIVATE WINDOW oWnd CENTERED

   fntArial:End()
   oFont:End()

   HB_GCALL( .T. )

   CLEAR MEMORY

RETURN NIL
// Change_Horizon
FUNCTION Cambia_Horizon( oSay )

   LOCAL NewSay := SPACE(50)

   NewSay := "HeyHeyHey Horizon: " + DTOC( Date() )

   oSay:VARPUT( NewSay )

   oSay:SetColor( CLR_MAGENTA, CLR_WHITE )
   oSay:Refresh()

RETURN( .T. )

// FIN / END
 


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

Re: Can I get object from handle?

Postby nageswaragunupudi » Thu Apr 13, 2023 1:55 pm

I think oWndfromhWnd() function can only find objects within the same application.


Yes, you are right.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Can I get object from handle?

Postby Horizon » Thu Apr 13, 2023 2:12 pm

karinha wrote:
Code: Select all  Expand view  RUN

// C:\FWH..\SAMPLES\HORIZON1.PRG

#include "FiveWin.ch"

#Define CLR_ORANGE     nRGB( 255, 165, 000 )

FUNCTION Change_Horizon()

   LOCAL oBtn, oSay, oFont
   LOCAL oWnd, FntArial, cSay := "Hello world" + SPACE(30)

   SET DATE TO AMERICAN

   HB_GCALL( .F. )

   DEFINE FONT fntArial NAME "Arial" SIZE 0, -25
   DEFINE FONT oFont    NAME "Arial" SIZE 0, -30 BOLD

   DEFINE WINDOW oWnd FROM 0, 0 TO 20, 80 TITLE "Change SAY in Time Real"

   @ 7.50, 10 SAY oSay VAR cSay FONT oFont SIZE 500, 80 OF oWnd UPDATE       ;
      COLORS CLR_ORANGE, CLR_WHITE TRANSPARENT CENTER

   @ 1, 10 BUTTON oBtn PROMPT "Change Hello World to HeyHeyHey" SIZE 500, 30 ;
      OF oWnd FONT FntArial ACTION( Cambia_Horizon( oSay ) )

   ACTIVATE WINDOW oWnd CENTERED

   fntArial:End()
   oFont:End()

   HB_GCALL( .T. )

   CLEAR MEMORY

RETURN NIL
// Change_Horizon
FUNCTION Cambia_Horizon( oSay )

   LOCAL NewSay := SPACE(50)

   NewSay := "HeyHeyHey Horizon: " + DTOC( Date() )

   oSay:VARPUT( NewSay )

   oSay:SetColor( CLR_MAGENTA, CLR_WHITE )
   oSay:Refresh()

RETURN( .T. )

// FIN / END
 


Regards, saludos.


I guess I didn't explain my problem. I want to do it between 2 different applications.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: Can I get object from handle?

Postby Horizon » Thu Apr 13, 2023 2:19 pm

nageswaragunupudi wrote:
I think oWndfromhWnd() function can only find objects within the same application.


Yes, you are right.


Hi Mr. Rao,

Is it possible to save the oWnd object in first application and read it from second application. With this read information, do I have a chance to use this object as if it was created in the second application?

I'm building both apps myself.

Thanks.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: Can I get object from handle?

Postby karinha » Thu Apr 13, 2023 2:22 pm

Switching from one to another calling from one EXECUTABLE to the other, I believe it is impossible. maybe, if you create a database or a *.TXT and change it into an .exe and call it from the other, you know?

Pasar de uno a otro llamando de un EJECUTABLE a otro, creo que es imposible. tal vez, si creas una base de datos o un *.TXT y lo cambias a un .exe y lo llamas desde el otro, ¿sabes?

Sorry I can't be of more help.

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

Re: Can I get object from handle?

Postby karinha » Thu Apr 13, 2023 3:10 pm

An idea, do you have access to the sources of the two programs? If yes, I think you will be able to pass VIA PARAMETER, not sure.

Una idea, tienes acceso a las fuentes de los dos programas? En caso afirmativo, creo que podrá pasar VIA PARÁMETRO, no estoy seguro.

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

Re: Can I get object from handle?

Postby Natter » Thu Apr 13, 2023 5:00 pm

Hi, Horizon !

You can do this. In the TSAY application in the window method ::handleEvent() describing the processing of a unique event.
For example:
if valtype(nMsg)="C"
oDlg:AControls[1]:SetText(msg)
return
endif
::Super...
From the application with the button we find the handle of the window with TSAY
hWn:=FindWindow() and send him a PostMessage(hWn, "myText")
Natter
 
Posts: 1222
Joined: Mon May 14, 2007 9:49 am

Re: Can I get object from handle?

Postby Antonio Linares » Thu Apr 13, 2023 6:20 pm

Dear Hakan,

Here you have it using EnumChildWindows()

You can also query the control for its ID or class

second.prg
Code: Select all  Expand view  RUN
#include "FiveWin.ch"

// run first.prg before this

PROCEDURE Main()
    local oFont, oWnd, oBtn
    DEFINE FONT oFont NAME "Arial" SIZE 0, -25  

    DEFINE WINDOW oWnd FROM 30, 10 TO 40, 80 ;
      TITLE "My Test Windows"

    @ 1,3 BUTTON oBtn PROMPT "Change Hello World to HeyHeyHey" size 500,50 font oFont OF oWnd ACTION MyAction(oWnd)
    oWnd:cargo := oBtn

    ACTIVATE WINDOW oWnd
RETURN

FUNCTION MyAction(oWnd)
   
    LOCAL cTestApp := "Testing Fonts", hWnd
   
    hWnd := FindWindow( 0, cTestApp)

    IF ! EMPTY(hWnd)
       BringWindowToTop( hWnd )
       EnumChildWindows( hWnd,;
           { | hCtrl | If( GetWindowText( hCtrl ) == "Hello world",;
                           ( SetWindowText( hCtrl, "HeyHeyHey" ), InvalidateRect( hCtrl, .T. ) ),) } )
    ELSE
        MsgAlert("Run testfont app before pressing button.")  
    ENDIF  
   
   
RETURN .T.
regards, saludos

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

Re: Can I get object from handle?

Postby Jimmy » Fri Apr 14, 2023 5:03 am

hi,

when have only 1 x Control you can use FindWindowEx() "inside" FindWindow()
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-findwindowexa
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-findwindowexw

3rd Parameter "lpszClass" need (Windows) CLASS Name
i guess SAY -> "WC_STATIC" (or "STATIC")

when got Handle of Control
Code: Select all  Expand view  RUN
  SetWindowText( hCtrl, "HeyHeyHey" )


---

when you want to "send" to other App where you have no Source than you need a Tool like WinID or WinSPY
https://dennisbabkin.com/winid/
https://sourceforge.net/projects/winspyex/

you will get Information for Windows Class Name and also Control ID ( not for SAY = WC_STATIC )
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Can I get object from handle?

Postby reinaldocrespo » Sun Apr 16, 2023 5:25 pm

Hello ;

Another idea would be to generate a "network wide message" anytime an event is triggered. Then have your apps listen for that message on another thread. If the message is received, then update the object being displayed or execute whatever code to handle the message.

I know this is not exactly what you are asking but it might be a possible solution.

I do this a lot using triggers on tables to display status, sums, and other information in realtime without having to query the database.

Just an idea,


Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Can I get object from handle?

Postby Horizon » Mon Apr 17, 2023 8:50 am

Thank you to all for your ideas.

I will check and write results here.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: Can I get object from handle?

Postby Horizon » Mon Apr 17, 2023 2:20 pm

Antonio Linares wrote:Dear Hakan,

Here you have it using EnumChildWindows()

You can also query the control for its ID or class

second.prg
Code: Select all  Expand view  RUN
#include "FiveWin.ch"

// run first.prg before this

PROCEDURE Main()
    local oFont, oWnd, oBtn
    DEFINE FONT oFont NAME "Arial" SIZE 0, -25  

    DEFINE WINDOW oWnd FROM 30, 10 TO 40, 80 ;
      TITLE "My Test Windows"

    @ 1,3 BUTTON oBtn PROMPT "Change Hello World to HeyHeyHey" size 500,50 font oFont OF oWnd ACTION MyAction(oWnd)
    oWnd:cargo := oBtn

    ACTIVATE WINDOW oWnd
RETURN

FUNCTION MyAction(oWnd)
   
    LOCAL cTestApp := "Testing Fonts", hWnd
   
    hWnd := FindWindow( 0, cTestApp)

    IF ! EMPTY(hWnd)
       BringWindowToTop( hWnd )
       EnumChildWindows( hWnd,;
           { | hCtrl | If( GetWindowText( hCtrl ) == "Hello world",;
                           ( SetWindowText( hCtrl, "HeyHeyHey" ), InvalidateRect( hCtrl, .T. ) ),) } )
    ELSE
        MsgAlert("Run testfont app before pressing button.")  
    ENDIF  
   
   
RETURN .T.


Hi Antonio,

This code works just fine as I want it. but I think we can't find the object with the hCtrl we found with the EnumChildWindows, or I think we can do every operation when we change the hCtrl of the object we will create (in this case, TSAY).

Actually, I wanted this example just to see if this was done.

What I really want to do is to control the TWebView class, which works as a client in a window, from another application. In this case, I need to be able to access all methods. Maybe I should consider the advice of reinaldocrespo instead of direct access like this.

Thanks.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 42 guests