Page 1 of 2
Can I get object from handle?
Posted:
Thu Apr 13, 2023 11:20 am
by Horizon
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
// 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
#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.
Re: Can I get object from handle?
Posted:
Thu Apr 13, 2023 12:11 pm
by karinha
Sorry, I didn't quite understand your question.
Regards.
Re: Can I get object from handle?
Posted:
Thu Apr 13, 2023 12:18 pm
by Horizon
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.
Re: Can I get object from handle?
Posted:
Thu Apr 13, 2023 1:54 pm
by karinha
- Code: Select all Expand view
// 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.
Re: Can I get object from handle?
Posted:
Thu Apr 13, 2023 1:55 pm
by nageswaragunupudi
I think oWndfromhWnd() function can only find objects within the same application.
Yes, you are right.
Re: Can I get object from handle?
Posted:
Thu Apr 13, 2023 2:12 pm
by Horizon
karinha wrote:- Code: Select all Expand view
// 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.
Re: Can I get object from handle?
Posted:
Thu Apr 13, 2023 2:19 pm
by Horizon
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.
Re: Can I get object from handle?
Posted:
Thu Apr 13, 2023 2:22 pm
by karinha
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.
Re: Can I get object from handle?
Posted:
Thu Apr 13, 2023 3:10 pm
by karinha
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.
Re: Can I get object from handle?
Posted:
Thu Apr 13, 2023 5:00 pm
by Natter
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")
Re: Can I get object from handle?
Posted:
Thu Apr 13, 2023 6:20 pm
by Antonio Linares
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
#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.
Re: Can I get object from handle?
Posted:
Fri Apr 14, 2023 5:03 am
by Jimmy
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-findwindowexahttps://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-findwindowexw3rd Parameter "lpszClass" need (Windows) CLASS Name
i guess SAY -> "WC_STATIC" (or "STATIC")
when got Handle of Control
- Code: Select all Expand view
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 )
Re: Can I get object from handle?
Posted:
Sun Apr 16, 2023 5:25 pm
by reinaldocrespo
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.
Re: Can I get object from handle?
Posted:
Mon Apr 17, 2023 8:50 am
by Horizon
Thank you to all for your ideas.
I will check and write results here.
Re: Can I get object from handle?
Posted:
Mon Apr 17, 2023 2:20 pm
by Horizon
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
#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.