Hi,
Is it possible to find out the owner of the current object ?
#include "FiveWin.ch"
STATIC oWnd
STATIC oSay1, oSay2, cTit1:="", cTit2:=""
Function Main()
LOCAL oBtn1, oBtn2, oChk1, lChk1 := .F., oChk2, lChk2 := .F., aResp := {}
LOCAL oGet1, cTxt1 := "Click on get's button"
LOCAL oFont1, oRad, nValue := 1, i := 1
DEFINE FONT oFont1 NAME "Verdana" SIZE 0,-16
DEFINE WINDOW oWnd TITLE "Owner of the object"
@ 20, 40 BTNBMP oBtn1 PROMPT "Show Owner" OF oWnd PIXEL ACTION ShowResp2() SIZE 150,30 FLAT
@ 90, 40 CHECKBOX oChk1 VAR lChk1 OF oWnd PIXEL SIZE 100,15 ;
ON CHANGE ShowResp2()
@ 150, 40 RADIO oRad VAR nValue ;
ITEMS "&One", "&Two", "T&hree" _3D OF oWnd SIZE 150, 21 PIXEL;
ON CHANGE ShowResp2();
@ 80,220 SAY "Owner:" OF oWnd PIXEL FONT oFont1 SIZE 90,25
@ 80,310 SAY oSay1 VAR cTit1 OF oWnd PIXEL FONT oFont1 SIZE 150,25
@ 110,220 SAY "Curr.Obj:" OF oWnd PIXEL FONT oFont1 SIZE 90,25
@ 110,310 SAY oSay2 VAR cTit2 OF oWnd PIXEL FONT oFont1 SIZE 150,25
for i:= 1 TO Len(oRad:aItems)
oRad:aItems[ i ]:bGotFocus := {|| ShowResp2() }
next
ACTIVATE WINDOW oWnd CENTERED // on init ShowResp2() // xBrowse(oRad)
RELEASE FONT oFont1
Return(NIL)
//-----------------------------------------------//
Function ShowResp1()
LOCAL aResp := {}
AADD(aResp,{FindOwnerObj(),MiReadVar1()} )
oSay1:SetText(aResp[1,1]:ClassName())
oSay2:SetText(aResp[1,2]:ClassName())
oWnd:Update()
Return(NIL)
//-----------------------------------------------//
Function ShowResp2()
LOCAL aResp := {}
AADD(aResp,{FindOwnerObj(),CurrentCrtl()} )
oSay1:SetText(aResp[1,1]:ClassName())
oSay2:SetText(aResp[1,2]:ClassName())
oWnd:Update()
Return(NIL)
//-----------------------------------------------//
Function FindOwnerObj() // Para encontrar el Objeto del Diálogo activo
LOCAL aWindows:=GetAllWin(), ii:=1, oDlg
LOCAL nId:=GetActiveWindow() // Tengo el Handle
for ii=1 to len(aWindows)
oDlg := aWindows[ii]
IF VALTYPE(ODLG)=="O"
if oDlg:oWnd<>Nil
if oDlg:oWnd:hWnd==nId
oDlg:=oDlg:oWnd
ii:=len(aWindows)
endif
ENDIF
ENDIF
next
return(oDlg)
//-----------------------------------------------//
Function CurrentCrtl()
LOCAL oDlg, hFoc, oControl, nPos:=0, iii:=1
oDlg := FindOwnerObj() // Devuelve el Diálogo actual
hFoc := GetFocus() // Devuelve el control que tiene el foco
nPos := ASCAN(oDlg:aControls,{|o|o:hWnd==hFoc})
IF ( nPos != 0 )
oControl := oDlg:aControls[nPos]
endif
Return(oControl)
//-----------------------------------------------//
Function MiReadVar1()
LOCAL oDlg, hFoc, oControl, nPos:=0, iii:=1
oDlg := FindOwnerObj() // Devuelve el Diálogo actual
hFoc := GetFocus() // Devuelve el control que tiene el foco
nPos := ASCAN(oDlg:aControls,{|o|o:hWnd==hFoc})
IF ( nPos != 0 )
While .T.
if nPos-iii=1
oControl:=ReadVar()
Exit
endif
if oDlg:aControls[nPos-iif(nPos<=1,0,iii)]:ClassName()=="TGET"
oControl := oDlg:aControls[nPos-iif(nPos<=1,0,iii)]
exit
else
iii++
endif
enddo
ENDIF
Return(oControl)
//-----------------------------------------------//
TGet():New(2, 2, GenLocalBlock( nGet ), oDlg, ;
100,, "9.999",,,,,,, .T.,,,,,,,,,,, .T., ;
{||self:=HB_QSelf(),::cText(val(::GetText())+0.05)}, ;
{||self:=HB_QSelf(),::cText(val(::cText())-0.05)}, ;
{||self:=HB_QSelf(),val(::cText())>=0.6}, ;
{||self:=HB_QSelf(),val(::cText())<=1})
Natter wrote:Here I need the owner of the oVScroll object.
METHOD GetScrollbarObj( oSelf, lVScroll ) CLASS TGrid
LOCAL oObj, cTitle := ""
LOCAL hWnd := 0
DEFAULT oSelf := SELF
DEFAULT lVScroll := .T.
IF lVScroll
cTitle := "oVScroll"
IF __objHasData( oSelf, "oVScroll" )
oObj := oSelf:oVScroll // VERTICAL
ELSE
MsgInfo( "no oVScroll",cTitle )
ENDIF
ELSE
cTitle := "oHScroll"
IF __objHasData( oSelf, "oHScroll" )
oObj := oSelf:oHScroll // HORIZONTAL
ELSE
MsgInfo( "no oHScroll" ,cTitle)
ENDIF
ENDIF
IF VALTYPE( oObj ) = "O"
IF __objHasData( oObj, "hWnd" )
hWnd := oObj:hWnd
ELSE
MsgInfo( "no oObj:hWnd" ,cTitle)
ENDIF
ELSE
MsgInfo( "Object " + hb_valToExp(oObj),cTitle)
ENDIF
RETURN hWnd
TGet():New(2, 2, GenLocalBlock( nGet ), oDlg, ;
100,, "9.999",,,,,,, .T.,,,,,,,,,,, .T., ;
{||self:=HB_QSelf():oWnd,iif(::value+0.05>1,.T.,::cText(::value+0.05))}, ;
{||self:=HB_QSelf():oWnd,iif(::value-0.05<0.59,.T.,::cText(::value-0.05))})
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 64 guests