Calculate position

Calculate position

Postby MarcoBoschi » Thu Jul 07, 2011 1:18 pm

Hi,
If I click on Dialog Button Activate the dialog.
If I start with default values the dialog is positioned in
100 , 200 , 640 , 818 instead of 100 , 200 , 600 , 800

If I close dialog and click again the button I have 100 , 200 , 680 , 836

Every time the dialog is 40 pixel and 18 pixel more big than previus click
How can I calculate this differences in order to save in a .ini files the exact coords?



King regards

marco

Code: Select all  Expand view
#include "fivewin.ch"
REQUEST HB_GT_GUI_DEFAULT
#define crlf CHR(13)+CHR(10)

FUNCTION Main()

   LOCAL oMain
   LOCAL oBut1, oBut2
   LOCAL oTop    , nTop         := 100
   LOCAL oLeft   , nLeft        := 200
   LOCAL oBottom , nBottom      := 600
   LOCAL oRight  , nRight       := 800

   DEFINE WINDOW oMain

//    @ 1 ,  1  BUTTON oBut1 PROMPT "Dialog" ACTION ( Dialogo( oTop, oLeft, oBottom, oRight ) , ;
//                                                    segna( oMain, oTop, oLeft, oBottom , oRight ) )      SIZE 100 , 30

   @ 1 ,  1  BUTTON oBut1 PROMPT "Dialog" ACTION Dialogo( oTop, oLeft, oBottom, oRight ) size 100 , 30



   @ 1 , 90  BUTTON oBut2 PROMPT "Reset"  ACTION ( nTop := 100 , nLeft := 100 , nBottom := 600 , nRight := 800 , ;
                                                   oTop:refresh() , oLeft:refresh() , oBottom:refresh() ,oRight:refresh() ) SIZE 100 , 30

   @ 1 , 20 GET oTop     VAR nTop     OF oMain  SIZE 50 , 20
   @ 1 , 30 GET oLeft    VAR nLeft    OF oMain  SIZE 50 , 20
   @ 1 , 40 GET oBottom  VAR nBottom  OF oMain  SIZE 50 , 20
   @ 1 , 50 GET oRight   VAR nRight   OF oMain  SIZE 50 , 20


   ACTIVATE WINDOW oMain MAXIMIZED


RETURN NIL



FUNCTION DIALOGO( oTop, oLeft, oBottom, oRight )

   LOCAL oDlg


   DEFINE DIALOG oDlg FROM oTop:varget() , oLeft:varget() TO oBottom:varget() , oRight:varget() PIXEL  ;
   STYLE nOr( WS_CAPTION, WS_THICKFRAME, WS_SYSMENU, WS_MINIMIZEBOX, WS_MAXIMIZEBOX )
   oDlg:bResized = { || ( oDlg:CoorsUpdate() , aggiorna( oDlg, oTop, oLeft, oBottom , oRight ) ) }

   oDlg:bMoved := {|| oDlg:CoorsUpdate() , aggiorna( oDlg, oTop , oLeft, oBottom , oRight ) }
   ACTIVATE DIALOG oDLg  ON INIT oDlg:move( oTop:varget() , oLeft:varget() , oRight:varget() - oLeft:varget() , oBottom:varget() - oTop:varget() )


RETURN NIL

FUNCTION AGGIORNA( oDlg, oTop , oLeft, oBottom , oRight  )
   oTop:varput( oDlg:nTop )
   oLeft:varput( oDlg:nLeft )
   oBottom:varput( oDlg:nBottom )
   oRight:varput( oDlg:nRight )
   oTop:refresh()
   oLeft:refresh()
   oBottom:refresh()
   oRight:refresh()
RETURN NIL

 
 
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Calculate position

Postby MarcoBoschi » Fri Jul 08, 2011 7:36 am

any ideas?
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Calculate position

Postby Enrico Maria Giordano » Fri Jul 08, 2011 8:48 am

What do you want to do exactly?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Calculate position

Postby MarcoBoschi » Fri Jul 08, 2011 9:31 am

Enrico,
when I click the first time, If I dont' change the for values the dialog has to be created in 100 , 100 , 600 , 800
But it is positioned in 100 , 100 , 629 , 810
I Save these new positions and nex time I find the dialog in another position.
I have to calculate this delta 629 - 600 = 29 for Height and 810 - 800 = 10 for length
If I modified screen resolution or properties of windows desktop these two deltas are different.

Many thanks

marco
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Calculate position

Postby Enrico Maria Giordano » Fri Jul 08, 2011 9:44 am

I see no problem:

Code: Select all  Expand view
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg

    DEFINE DIALOG oDlg

    ACTIVATE DIALOG oDlg;
             ON INIT oDlg:Move( 100, 100, 800, 600 );
             ON CLICK SHOWCOORDS( oDlg )

    RETURN NIL


STATIC FUNCTION SHOWCOORDS( oDlg )

    ? oDlg:nTop, oDlg:nLeft, oDlg:nWidth, oDlg:nHeight

    RETURN NIL


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Calculate position

Postby MarcoBoschi » Fri Jul 08, 2011 10:32 am

Enrico,
If you run my program you can notice that the four coords change (see the four gets in the window)

Imagine that I have to save these coords in a ini file for store these information for later use.
....
...
...
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Calculate position

Postby Enrico Maria Giordano » Fri Jul 08, 2011 11:22 am

I don't understand your sample. Please check mine. You can use it for save and restore the dialog position.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Calculate position

Postby ukoenig » Fri Jul 08, 2011 12:15 pm

Marco,

Your rewritten Sample ( hoping, it is what You are looking for ) it is very short now :
Resize and Move the Dialog and get the needed Values : < Dialog-Top, Left, Hight and Width >
for Fields < nTop, nLeft, nHeight and nWidth > inside the Main-window.

It is just a quick Solution, maybe it can be done better.

Image

Code: Select all  Expand view

#include "fivewin.ch"

STATIC oMain, oDlg, nTop := 100, nLeft := 200, nHeight := 600, nWidth := 800, lActivated := .F.

REQUEST HB_GT_GUI_DEFAULT
#define crlf CHR(13)+CHR(10)

FUNCTION Main()
LOCAL oBut1, oBut2
LOCAL oDTop, oDLeft
LOCAL oDHeight, oDWidth


DEFINE WINDOW oMain

@ 1 ,  1  BUTTON oBut1 PROMPT "Dialog" ACTION Dialogo( oDTop, oDLeft, oDHeight, oDWidth ) size 100 , 30

// lActivated := .F. is needed because of < oDlg:End() > and no Dialog is visible !!!

@ 1 , 90  BUTTON oBut2 PROMPT "Reset"  ACTION ( nTop := 100 , nLeft := 100 , nHeight := 600 , nWidth := 800 , ;
                                              IIF( lActivated = .T., oDlg:End(), NIL ), ;
                                              DIALOGO( oDTop, oDLeft, oDHeight, oDWidth) ) SIZE 100 , 30

@ 1 , 20 GET oDTop  VAR nTop  OF oMain  SIZE 50 , 20 UPDATE
@ 1 , 30 GET oDLeft  VAR nLeft  OF oMain  SIZE 50 , 20 UPDATE
@ 1 , 40 GET oDHeight VAR nHeight OF oMain  SIZE 50 , 20 UPDATE
@ 1 , 50 GET oDWidth  VAR nWidth  OF oMain  SIZE 50 , 20 UPDATE

ACTIVATE WINDOW oMain MAXIMIZED

RETURN NIL

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

FUNCTION DIALOGO( oDTop, oDLeft, oDHeight, oDWidth)

lActivated := .T.

DEFINE DIALOG oDlg FROM nTop, nLeft TO nHeight, nWidth OF oMain PIXEL ;
STYLE nOr( WS_CAPTION, WS_THICKFRAME, WS_SYSMENU, WS_MINIMIZEBOX, WS_MAXIMIZEBOX )
   
oDlg:bResized = { || aggiorna(oDTop, oDLeft, oDHeight, oDWidth) }
oDlg:bMoved := {|| aggiorna(oDTop, oDLeft, oDHeight, oDWidth) }

ACTIVATE DIALOG oDlg NOWAIT  ON INIT oDlg:move( nTop, nLeft, nWidth, nHeight )

RETURN NIL

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

FUNCTION AGGIORNA(oDTop, oDLeft, oDHeight, oDWidth)

oDlg:CoorsUpdate()

nTop := oDlg:nTop
nLeft := oDlg:nLeft
nHeight := oDlg:nHeight
nWidth := oDlg:nWidth

oDTop:Refresh()
oDLeft:Refresh()
oDHeight:Refresh()
oDWidth:Refresh()

oDlg:cTitle := "Dialog-position and Size : Top " + Alltrim( STR( nTop )) + ;
          ",  Left : "  + Alltrim( STR( nLeft )) + ;
          ",  Height : " + Alltrim( STR( nHeight )) + ;
          ",  Width : "  + Alltrim( STR( nWidth ))

RETURN NIL
 


Best Regards
Uwe :lol:
Last edited by ukoenig on Fri Jul 08, 2011 12:33 pm, edited 3 times in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Calculate position

Postby MarcoBoschi » Fri Jul 08, 2011 12:31 pm

Uwe,
please try to click five times "Dialog" button and don't touch any other objects
You can see that at every click dialog become smaller
This is the problem
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Calculate position

Postby ukoenig » Fri Jul 08, 2011 12:38 pm

Marco,

You can use a logical Var, to make it impossible, to open a Dialog once more.
But I will check and try to fix it.
Like I told You : just a quick Solution.

Please change this line and add the defined logical var < lActivated >,
to make it impossible to open a Dialog twice with the Button.
The Button will open a Dialog only once. Maybe You can include a Message, that a Dialog is created.
With < Reset You can start again to Resize and Move a Dialog.

@ 1 , 1 BUTTON oBut1 PROMPT "Dialog" ;
ACTION IIF( lActivated = .F., Dialogo( oDTop, oDLeft, oDHeight, oDWidth ), ;
MsgAlert( "a Dialog is already created !","ATTENTION") ) size 100 , 30


Best Regards
Uwe :lol:
Last edited by ukoenig on Fri Jul 08, 2011 12:51 pm, edited 2 times in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Calculate position

Postby MarcoBoschi » Fri Jul 08, 2011 12:44 pm

Is it normal that four coords change?
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Calculate position

Postby ukoenig » Fri Jul 08, 2011 1:03 pm

Marco,

Only Position changed but You can change Width and Height as well.
You don't want to Resize ?

Image

Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Calculate position

Postby MarcoBoschi » Fri Jul 08, 2011 1:42 pm

My task is store in a ini files nTop, nLeft, nBottom and nRight
When I open the dialog again in the new position
The minimal samples posted works fine
In the real project the dialog has a listbox, Gets and buttons
EVery time I close and repoen It move up of about 2o pixels
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Calculate position

Postby MarcoBoschi » Fri Jul 08, 2011 3:22 pm

:oops: solution shameful

Code: Select all  Expand view
nTd  := VAL( GETPVPROFSTRING( "Lista"   , "nTop"          , ""    , ".\winrap_" + M->cUte_dos + ".ini" ) )  + 42
    nLd  := VAL( GETPVPROFSTRING( "Lista"   , "nLeft"         , ""    , ".\winrap_" + M->cUte_dos + ".ini" ) )
    nBd  := VAL( GETPVPROFSTRING( "Lista"   , "nBottom"       , ""    , ".\winrap_" + M->cUte_dos + ".ini" ) )  + 42
    nRd  := VAL( GETPVPROFSTRING( "Lista"   , "nRight"        , ""    , ".\winrap_" + M->cUte_dos + ".ini" ) )

I Hope in the future to understand why....
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Calculate position

Postby MarcoBoschi » Fri Jul 08, 2011 3:48 pm

Please,
compile this little program
Run it
Move the dialog in a new position and resize it
Now Click to store coords into dialogo.ini file
Restart program
you will find the dialog moved up!!

What's wrong?

:?:

I don't accept answers like you, your person, your job, job, etc.. etc..
Code: Select all  Expand view
#include "Fivewin.ch"
FUNCTION MAIN()
LOCAL oMain
DEFINE WINDOW oMain
ACTIVATE WINDOW oMain MAXIMIZED ON INIT main1()
RETURN NIL

FUNCTION MAIN1( )

    LOCAL oDlg
    LOCAL nTop , nLeft, nBottom, nRight

    nTop    := VAL( GETPVPROFSTRING( "Dialogo"   , "nTop"         , ""    , ".\dialogo.ini" )  )
    nLeft   := VAL( GETPVPROFSTRING( "Dialogo"   , "nLeft"        , ""    , ".\dialogo.ini" )  )
    nBottom := VAL( GETPVPROFSTRING( "Dialogo"   , "nBottom"      , ""    , ".\dialogo.ini" )  )
    nRight  := VAL( GETPVPROFSTRING( "Dialogo"   , "nRight"       , ""    , ".\dialogo.ini" )  )

    DEFINE DIALOG oDlg RESOURCE "DIALOGO"
    oDlg:nStyle = NOR( oDlg:nStyle, WS_THICKFRAME, WS_MAXIMIZEBOX , WS_MINIMIZEBOX )
    oDlg:ctitle := STR( oDlg:nTop ) + STR( oDlg:nLeft ) + STR( oDlg:nBottom ) + STR( oDlg:nRight )
    oDlg:ctooltip := "Please move or resize, Click and then close"

    oDlg:bResized = { || oDlg:CoorsUpdate()  }

    oDlg:bMoved := {|| oDlg:CoorsUpdate()  }

    ACTIVATE DIALOG oDlg ;
              ON INIT ( oDlg:Move( nTop, nLeft, nRight - nLeft , nBottom - nTop ) , oDlg:CoorsUpdate() ) ;
              ON CLICK SHOWCOORDS( oDlg )

    RETURN NIL


 STATIC FUNCTION SHOWCOORDS( oDlg )

   WritePProString( "Dialogo"   , "nTop"     , ALLTRIM( STR( oDlg:nTop    ,4 ) ) , ".\dialogo.ini"  )
   WritePProString( "Dialogo"   , "nLeft"    , ALLTRIM( STR( oDlg:nLeft   ,4 ) ) , ".\dialogo.ini"  )
   WritePProString( "Dialogo"   , "nBottom"  , ALLTRIM( STR( oDlg:nBottom ,4 ) ) , ".\dialogo.ini"  )
   WritePProString( "Dialogo"   , "nRight"   , ALLTRIM( STR( oDlg:nRight  ,4 ) ) , ".\dialogo.ini"  )
   oDlg:ctitle := STR( oDlg:nTop ) + STR( oDlg:nLeft ) + STR( oDlg:nBottom ) + STR( oDlg:nRight )
 RETURN NIL
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 61 guests