Save and Restore Dialog Position

Save and Restore Dialog Position

Postby dpaterso » Wed Oct 26, 2011 7:58 pm

Hello,

A 'quick simple one' (I hope).

I have written my 'little app' and it works 'beautifully' (even if I have to say so myself). LOL!!!

However: is there any way to save the position of the dialog (application) (let's assume that on your 'first run' you moved it by dragging it to where you want it) and when you open the dialog (application) again (after closing it before) the dialog (application) is opened and displayed at its 'last used location'???

Before answering: bear in mind that my my dialog is a 'child dialog' with no buttons or anything like that, I don't want to be able to resize it or anything like that, I just want to have it opening at the location where is was 'last used' (I hope that makes sense). Please also note: the dialog is contained in a resource file i.e. it's not a dialog created from source code.

I've seached the forums (before asking this) and it would SEEM as though this 'facililty' is only available in newer versions of FWH / xHB (remember I'm still on 2007 'something').

Regards,

Dale.
dpaterso
 
Posts: 142
Joined: Tue Jan 24, 2006 9:45 am
Location: South Africa

Re: Save and Restore Dialog Position

Postby ukoenig » Wed Oct 26, 2011 10:23 pm

Dale,

Save the Dioalog-pos on Exit and Restore on Start from a INI-file :
( could be resized as well )

nTop := 400
nLeft := 300

Move the Resource ON INIT to the defined Position :

ACTIVATE DIALOG oDlg ;
ON INIT oDlg:Move( nTop , nLeft, oDlg:nWidth, oDlg:nHeight, .F. )

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: Save and Restore Dialog Position

Postby dpaterso » Thu Oct 27, 2011 7:26 am

Hello again,

Thanks for the help Uwe (I'd actually typed another response to you prior to this one but for some reason I saved it as a 'Draft' instead of 'Submitting' it so the information in that post is now irrelevant).

OK: I think I've 'got it'.

I need to write an additional function that uses 'On Move oDlg:CoorsUpdate( )', save the 'oDlg:nTop' and 'oDlg:nLeft' values to variables, and save the variables to a configuration file etc. etc. etc. and then use those saved variables when opening and activating the dialog with 'oDlg:Move( nTop, nLeft )'.

Just one question that I have:

You noted to use a .ini file. Is there a particular function that creates (and writes to and reads from) a .ini file or is what you are describing simply the same as using 'Save To Something.Ini All Like oDlgCoors*' (and then using 'Restore From Something.ini All Like oDlgCoors* Additive'???

Regards.

Dale.
dpaterso
 
Posts: 142
Joined: Tue Jan 24, 2006 9:45 am
Location: South Africa

Re: Save and Restore Dialog Position

Postby ukoenig » Thu Oct 27, 2011 1:13 pm

A complete Sample using a INI-file :

Code: Select all  Expand view

#INCLUDE "FIVEWIN.CH"

// ------------ Testing SAVE / RESTORE Dlg-Position ---------------

STATIC c_path, nDlgTop := 50, nDlgLeft := 50

FUNCTION TEST_DLG()
LOCAL oDlg

c_path := CURDRIVE() + ":\" + GETCURDIR()

DEFINE DIALOG oDlg RESOURCE "
EMPTYDLG" OF oWndMain PIXEL

oDlg:bMoved := {|| ( oDlg:CoorsUpdate(), nDlgTop := oDlg:nTop, nDlgLeft := oDlg:nLeft ) }

ACTIVATE DIALOG oDlg ;
ON INIT ( GET_POS(), oDlg:Move( nDlgTop, nDlgLeft, oDlg:nWidth, oDlg:nHeight, .F. ) )

SAVE_POS()

RETURN NIL

// ---- READ from INI ------------------

FUNCTION GET_POS()
Local oInifile, cDlgTop := "
50", cDlgLeft := "50"

IF !FILE ( c_path + "
\DLGPOS.ini" )
    SAVE_POS(nDlgTop, nDlgLeft)
ELSE
    INI oInifile FILE c_path + "
\DLGPOS.ini"
        GET  cDlgTop    SECTION "
Dialog"    ENTRY   "Top"   OF oInifile DEFAULT "50"
        GET  cDlgLeft   SECTION "
Dialog"    ENTRY   "Left"      OF oInifile DEFAULT "50"
    ENDINI
ENDIF
nDlgTop := VAL(cDlgTop)
nDlgLeft := VAL(cDlgLeft)

// MsgAlert( nDlgTop, "
Get Top" )
// MsgAlert( nDlgLeft, "
Get Left" )

RETURN( NIL )

// ---------   WRITE to INI ------------------------

FUNCTION SAVE_POS()
LOCAL lSysini := .T., cIniFile := c_path + "
\DLGPOS.INI"

// MsgAlert( nDlgTop, "
Save Top" )
// MsgAlert( nDlgLeft, "
Save Left" )

IF WritePProString( "
Dialog", "Top", ALLTRIM(STR(nDlgTop)),  cIniFile ) = .F.
        lSysini := .F.
ENDIF
IF WritePProString( "
Dialog", "Left", ALLTRIM(STR(nDlgLeft)),  cIniFile ) = .F.
        lSysini := .F.
ENDIF

IF lSysini = .F. .or. !FILE( cInifile )
    MsgAlert("
Not possible, to write in  INI-File", "INI-File")
ENDIF

RETURN( NIL )


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: Save and Restore Dialog Position

Postby dpaterso » Thu Oct 27, 2011 2:48 pm

Hi Uwe,

Once again: thank you for taking all of that time and going to all of that effort to post a complete sample.

I had already got it working before I checked my email (and therefore this thread) although not QUITE as 'elegantly' as you in your sample!!! LOL!!!

Well and the above being said: the only difference (It would APPEAR anyway) is that I saved variables assigned with the values of 'oDlg:nTop' and 'oDlg:nLeft' using the 'old' 'Save All Like oDlgPos* To AppName.ini' and of course every time the dialog box is moved the variables in the file are updated using oDlg:CoorsUpdate( ) and then recalled or 'restored' when the application is opened again. I didn't know I even HAD the 'INI' and 'WritePProString( )' functions etc. in my version of FWH / xHB!!! LOL!!! So I did it the 'old fashioned way' (or 'the hard way')!!! LOL!!!

Sorry James (Bott)!!! Yet again: not 'Windows Standard' i.e. my .INI file is a MEMVAR file not a text file!!! LOL!!!

But as Antonio said to me in a previous post: it's definitely time for a FWH upgrade anyway (and just yesterday or the day before I received an email informing me that there is a new xHB version out too i.e. I'm still on their mailing list it would seem). I've not written any software for at least the past four years or so and I'm quite amazed at just how much I've forgotten i.e. even for this simple little application that I've had the need to write I had to refer to code that I wrote five or six years ago just to get the SYNTAX right let alone remember all the functions!!! LOL!!! What's ODD though: the ORIGINAL version of this little application I sort of 'knocked up quickly' in CA-Clipper 5.2e and that was 'like riding a bicycle' i.e. I think I had to refer to the CA-Clipper 5.2e Norton Guide ONCE ONLY (I wonder how many even remember CA-Clipper 5.2e and the Norton Guides)!!! LOL!!! But I needed it (this little application) to be written in Windows because I needed to interface it with another package using an ActiveX API which I couldn't do with DOS (anybody remember DOS)??? LOL!!!

I'm sure the above is WAY more than you wanted to or needed to know though!!! LOL!!!

But thanks once again. I really appreciate it.

Regards,

Dale Paterson.

Edit:

By the way: in the latest version (or in any version later than FWH / xHB 2007) has my ‘favourite topic’ been ‘fixed’ i.e. oLbx:BugUp( ) and oLbx:Upstable( )??? LOL!!!
dpaterso
 
Posts: 142
Joined: Tue Jan 24, 2006 9:45 am
Location: South Africa

Re: Save and Restore Dialog Position

Postby ronaldo » Fri Oct 28, 2011 7:25 pm

ACTIVATE dialog odlg on init restauraposicao(odlg) valid gravaposicao(odlg)



Function GravaPosicao(oTemDlg)
LOCAL aRect, nNome
LOCAL nDlg_Largura, nDlg_Altura

aRect := GetWndRect( oTemDlg:hWnd )
nNome := oTemDlg:cResName

WritePProString( nNome , "Topo" , alltrim(str(aRect[1])) , Curdrive()+":\"+Curdir()+"\VDialog-"+nNomeComputador+".ini")
WritePProString( nNome , "Esquerda" , alltrim(str(aRect[2])) , Curdrive()+":\"+Curdir()+"\VDialog-"+nNomeComputador+".ini")
Return(.t.)

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Function RestauraPosicao(oTemDlg)
LOCAl nTopo, nEsquerda, nNome
LOCAL Padr_Height := GetSysMetrics(1) //tamanhho da windows
LOCAL PadrWidth := GetSysMetrics(0) //tamanhho da windows
LOCAL nDlg_Largura, nDlg_Altura

nNome := oTemDlg:cResName

nTopo := VAL(GetPvProfString(nNome,"Topo" ,"55",Curdrive()+":\"+Curdir()+"\VDialog-"+nNomeComputador+".ini" ))
nEsquerda := VAL(GetPvProfString(nNome,"Esquerda","100",Curdrive()+":\"+Curdir()+"\VDialog-"+nNomeComputador+".ini" ))
oTemDlg:Move(nTopo, nEsquerda)
RETURN(NIL)
[b]Ronaldo Minacapelli[/b]
Sistemas, Hospedagem e Criação de WebSites
http://www.bazevani.com.br
User avatar
ronaldo
 
Posts: 139
Joined: Fri Nov 25, 2005 4:38 pm
Location: brasil

Re: Save and Restore Dialog Position

Postby dpaterso » Sat Oct 29, 2011 8:25 am

Hey ronaldo,

Thank YOU TOO for posting an example.

I thought that seeing everybody is being so helpful (as always) (and I'm especially grateful seeing as I've not 'been around' for a few years) I'd post MY 'version' for comparison (completed before getting all of the invaluable input that I’ve received):

Code: Select all  Expand view

***
#Include 'FiveWin.ch'
***

***
Function Main( )

// More public variables and checking for the API being active goes here

Public oDlg
Public nDlgTop, nDlgLeft

Set 3DLook       Off
Set Bell         Off
Set Century      On
Set Confirm      On
Set Date         British
Set Deleted      Off
Set Epoch To     1965
Set Exclusive    Off
Set Fixed        On
Set Scoreboard   Off
Set Decimals to  4

SetHandleCount( 127 )

// I start ALL my applications with the above 'Sets' i.e. 'old habits' I guess

// The usual fonts definitions etc. for the dialog go here

Define Dialog oDlg Resource 'DIALOG_1'

// The main code goes here with all the controls and inputs etc.

Activate Dialog oDlg On Init ( GetLastDlgPos( ), oDlg:Move( nDlgTop, nDlgLeft ) ) On Move ( oDlg:CoorsUpdate( ), nDlgTop := oDlg:nTop, nDlgLeft := oDlg:nLeft, SaveLastDlgPos( ) )

ResAllFree( )

Commit

Clear All

Close All

Return( Nil )
***

***
// Many other Functions for the application go down here
***

***
Function GetLastDlgPos( )
   
If File( 'ttcpcalc.ini' ) // The apps .exe is names 'ttcpcalc.exe'
   
   Restore From ttcpcalc.ini Additive
   
Else
   
   nDlgTop := 100
   nDlgLeft := 200

   Save All Like nDlg* To ttcpcalc.ini

EndIf

Return
***

***
Function SaveLastDlgPos( )

   Save All Like nDlg* To ttcpcalc.ini

Return
***

***
procedure AppSys

return
***
 


‘Old fashioned’ huh (but it works)!!! LOL!!!

Regards,

Dale.
dpaterso
 
Posts: 142
Joined: Tue Jan 24, 2006 9:45 am
Location: South Africa


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 55 guests