TTreeView:Change Method changes coordinats of controls

Post Reply
Horizon
Posts: 1323
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 4 times

TTreeView:Change Method changes coordinats of controls

Post by Horizon »

Hi,

I use TreeView like below.

Code: Select all | Expand

#include "fivewin.ch"

Procedure Main()
Local Cx1:=136, CY1 := 74, CX2 := 652, CY2 := 911, ODlg, oFont
Local XNAME:=SPACE(25), oName   

DEFINE DIALOG oDlg FROM CX1,CY1 TO CX2,CY2 PIXEL ;
        STYLE nOr( WS_OVERLAPPEDWINDOW ) TRANSPARENT

    oDlg:SetColor(,10150628,)
    @ 10,7 TREEVIEW oTree OF oDlg SIZE 95, 100 PIXEL

    oTree:bChanged := { | oItem | oItem := oTree:GetSelected(), ;
                        If( ValType( oItem:Cargo ) == "B", Eval( oItem:Cargo ),) }

    @ 2, 03 GROUP oGrp1 TO 80,195 Pixel  

  @ 3, 90 GROUP oGrp TO 200,90 OF oDlg PIXEL

    // This lines are the same as Opt_Page1 Procedure, but nTop, nLeft does not print the
    // same place in same dialog. It is also change the get's height.
    @ 60,110 SAY "Enter your Name and Surname" OF oDlg PIXEL TRANSPARENT
    @ 58,210 GET oNAME VAR XNAME OF oDlg  PIXEL SIZE 150,10 UPDATE  

ACTIVATE DIALOG ODlg ;
    ON INIT (oDlg:nHeight:=CX2-cx1, oDlg:nWidth:=CY2-cy1, ;
                    oDlg:bResized := {|| ONRESIZE(oDlg, oGrp1, oGrp, oTree) })

RETURN .T.

Procedure ONRESIZE(oDlg, oGrp1, oGrp, oTree)
    oGrp1:nWidth:=oDlg:nWidth-30
    oGrp1:nHeight:=oDlg:nHeight-45
   
    oGrp:nTop   := oGrp1:nTop
    oGrp:nLeft  := oGrp1:nLeft
    oGrp:nHeight := oGrp1:nHeight
    oGrp:nWidth := 205

    oTree:nHeight := oGrp1:nHeight-25

    IF len(oTree:aItems)=0
        oTree:Add( "Selection 1"):Cargo = GenBlock("Opt_Page1", oDlg)
        oTree:Add( "Selection 2")
        oTree:Add( "Selection 3")
        oTree:Add( "Selection 4")
        oTree:Add( "Selection 5")

    ENDIF
   
RETURN

PROCEDURE Opt_Page1( oDlg )
Local XNAME:=SPACE(25), oName
    // This lines are the same as Opt_Page1 Procedure, but nTop, nLeft does not print the
    // same place in same dialog. It is also change the get's height.
    @ 60,110 SAY "Enter your Name and Surname" OF oDlg PIXEL TRANSPARENT
    @ 58,210 GET oNAME VAR XNAME OF oDlg  PIXEL SIZE 150,10 UPDATE     
RETURN

Static FUNCTION GenBlock(DialogName, oDlg)
RETURN {|| &(DialogName)( oDlg ) }


.RC File.

Code: Select all | Expand

  1 24 "WindowsXP.Manifest"
 


Image

I have get and say classes in dialog. But When I try to write same lines in another procedure that is sended from Treeview On change method, My get and says does not printed the same place. Is there any wrong code in my application?

Thanks
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
Posts: 1323
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 4 times

Re: TTreeView:Change Method changes coordinats of controls

Post by Horizon »

Any Idea?
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: TTreeView:Change Method changes coordinats of controls

Post by Enrico Maria Giordano »

1. You have to create the SAY and the GET the first time from the ON INIT clause.

2. It's not a good idea to create a new SAY and a new GET any time the selected tree item is changed.

EMG
Horizon
Posts: 1323
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 4 times

Re: TTreeView:Change Method changes coordinats of controls

Post by Horizon »

Thanks Enrico,

What is your suggestion? How should I do in Treeview on change clause.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: TTreeView:Change Method changes coordinats of controls

Post by Enrico Maria Giordano »

It depends on what you want to achieve. Create new controls again and again is not an option.

EMG
Horizon
Posts: 1323
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 4 times

Re: TTreeView:Change Method changes coordinats of controls

Post by Horizon »

Enrico,

This sample is made to introduce the problem. in fact my application is a bit different.

My Tree onchange block:

Code: Select all | Expand

   oTree:bChanged := { | oItem | oItem := oTree:GetSelected(), CleanSlate(oDlg);
                        If( ValType( oItem:Cargo ) == "B", Eval


in my on init.
Static hDemirbas := {}

Code: Select all | Expand

        AADD(hDemirbas, oTree:hWnd)
        AADD(hDemirbas, oGrp:hWnd)
        AADD(hDemirbas, oGrp1:hWnd)
       


Code: Select all | Expand

static function CleanSlate( oDlg )
LOCAL oCont, ij, ik, lBul
    ahSil := {}
    for ij:=1 to len(oDlg:aControls)
        oCont := oDlg:aControls[ij] 
        lBul := .f. 
        for jk:=1 to len(hDemirbas)
            if oCont:hWnd = hDemirbas[jk]
                lBul := .t.
                exit
            ENDIF
        next jk
        if !lBul
            AADD(ahSil, oCont:hWnd)
        endif
    next ij
    for jk=1 to len(ahSil)
        for ij:=1 to len(oDlg:aControls)
            oCont := oDlg:aControls[ij] 
            if oCont:hWnd = ahSil[jk]
                oCont:end()
                exit
            endif
        next
    next
    oDlg:Refresh()
return nil
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: TTreeView:Change Method changes coordinats of controls

Post by Enrico Maria Giordano »

Can you try to build a reduced and self-contained sample of the problem?

EMG
Horizon
Posts: 1323
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 4 times

Re: TTreeView:Change Method changes coordinats of controls

Post by Horizon »

I dont know how can I reduce the sample more than this.

Hakan

Code: Select all | Expand

#include "fivewin.ch"

static ahDontRemove

Procedure Main()
Local Cx1:=136, CY1 := 74, CX2 := 652, CY2 := 911
Local XNAME:=SPACE(25), oName   

    ahDontRemove := {}
   
    DEFINE DIALOG oDlg FROM CX1,CY1 TO CX2,CY2 PIXEL TRANSPARENT
    oDlg:SetColor(,10150628,)

    @ 10,7 TREEVIEW oTree OF oDlg SIZE 95, 100 PIXEL


    oTree:bChanged := { | oItem | oItem := oTree:GetSelected(), CleanOthers(oDlg),;
                        If( ValType( oItem:Cargo ) == "B", Eval( oItem:Cargo ),) }

    // This lines are the same as Opt_Page1 Procedure, but nTop, nLeft does not print the
    // same place in same dialog. It is also change the get's height.
    @ 60,110 SAY "Enter your Name and Surname" OF oDlg PIXEL TRANSPARENT
    @ 58,210 GET oNAME VAR XNAME OF oDlg  PIXEL SIZE 150,10 UPDATE  

ACTIVATE DIALOG ODlg ;
    ON INIT  (ON_INIT(oDlg, oTree))

RETURN .T.

Procedure ON_INIT(oDlg, oTree)
    oTree:nHeight := oDlg:nHeight-60

    oTree:Add( "Selection 1"):Cargo = GenBlock("Opt_Page1", oDlg)
    oTree:Add( "Selection 2"):Cargo = GenBlock("Opt_Page2", oDlg)
    oTree:Add( "Selection 3")
    oTree:Add( "Selection 4")
    oTree:Add( "Selection 5")
   
    AADD(ahDontRemove, oTree:HWnd)
RETURN

PROCEDURE Opt_Page1( oDlg )
Local XNAME:=SPACE(25), oName
    // This lines are the same as Opt_Page1 Procedure, but nTop, nLeft does not print the
    // same place in same dialog. It is also change the get's height.
    @ 60,110 SAY "Option Page 1 Surname" OF oDlg PIXEL TRANSPARENT
    @ 58,210 GET oNAME VAR XNAME OF oDlg  PIXEL SIZE 150,10 UPDATE     
RETURN

PROCEDURE Opt_Page2( oDlg )
Local XNAME:=SPACE(25), oName
    // This lines are the same as Opt_Page1 Procedure, but nTop, nLeft does not print the
    // same place in same dialog. It is also change the get's height.
    @ 100,110 SAY "Option page 2  Surname" OF oDlg PIXEL TRANSPARENT
    @ 98,210 GET oNAME VAR XNAME OF oDlg  PIXEL SIZE 150,10 UPDATE     
RETURN

Static FUNCTION GenBlock(DialogName, oDlg)
RETURN {|| &(DialogName)( oDlg ) }

static function CleanOthers( oDlg )
LOCAL oCont, ij, ik, lBul
    ahSil := {}
    for ij:=1 to len(oDlg:aControls)
        oCont := oDlg:aControls[ij] 
        lBul := .f. 
        for jk:=1 to len(ahDontRemove)
            if oCont:hWnd = ahDontRemove[jk]
                lBul := .t.
                exit
            ENDIF
        next jk
        if !lBul
            AADD(ahSil, oCont:hWnd)
        endif
    next ij
    for jk=1 to len(ahSil)
        for ij:=1 to len(oDlg:aControls)
            oCont := oDlg:aControls[ij] 
            if oCont:hWnd = ahSil[jk]
                oCont:end()
                exit
            endif
        next
    next
    oDlg:Refresh()
return nil
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: TTreeView:Change Method changes coordinats of controls

Post by Enrico Maria Giordano »

1. Remove the GETs inside Opt_Page1() and Opt_Page2(). They are not needed.

2. Use oSay:SetText() method to change the text of the SAY instead of creating a new one.

EMG
Horizon
Posts: 1323
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 4 times

Re: TTreeView:Change Method changes coordinats of controls

Post by Horizon »

Thank you Enrico,

I understand your solution, but I have different says, gets, checkbox, combobox in every option page. so I cant define them before activate dialog and just use them in option pages.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: TTreeView:Change Method changes coordinats of controls

Post by Enrico Maria Giordano »

So, hide them all and show only those that must be visible. But don't create them again and again if you don't want to consume all the Windows resources.

EMG
User avatar
James Bott
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: TTreeView:Change Method changes coordinats of controls

Post by James Bott »

Or create a different dialog for each set of says and gets. Then just hide the current dialog and show the new dialog. All the controls will aready be there.

James
Horizon
Posts: 1323
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 4 times

Re: TTreeView:Change Method changes coordinats of controls

Post by Horizon »

Thanks Enrico, James.

Enrico,

>>So, hide them all and show only those that must be visible. But don't create them again >>and again if you don't want to consume all the Windows resources.

I just want to ask to learn it. if we ended with their :End() Method, will I consume the windows resources? I have about ~250 options to get in this dialog. If I create all of them, don't I consume the windows resources.

James,
>>Or create a different dialog for each set of says and gets. Then just hide the current dialog >>and show the new dialog. All the controls will aready be there.

Can you please explain more?

Thanks again.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: TTreeView:Change Method changes coordinats of controls

Post by Enrico Maria Giordano »

Horizon wrote:if we ended with their :End() Method, will I consume the windows resources?


No, they shouldn't. But to do so you will need to access to the GET variable.

EMG
Post Reply