How to save and restore windows position and size?

Post Reply
Horizon
Posts: 1329
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 6 times
Been thanked: 1 time

How to save and restore windows position and size?

Post by Horizon »

Hi,

I use this methods to save and restore my main window. It works ok. but when i move to window, my sizes changes.

How can I solve this problem?

Thanks

Code: Select all | Expand

METHOD Koordinat_Save() CLASS tApplication
LOCAL XFILE, aMyIni,cParagraf
    xFILE=::CROOT+"AAAA.INI"
    aMyIni := IniLoad(XFILE)
    cParagraf := "DESKTOP_"+ALLTRIM(::aUSERINFO[1])
    IniPut(aMyIni,cParagraf,"nTop",NTRIM(::oWnd:nTop))
    IniPut(aMyIni,cParagraf,"nLeft",NTRIM(::oWnd:nLeft))
    IniPut(aMyIni,cParagraf,"nHeight",NTRIM(::oWnd:nHeight))
    IniPut(aMyIni,cParagraf,"nWidth",NTRIM(::oWnd:nWidth))
    IniSave(aMyIni,XFILE)

    MsgInfo("Masaüstü koordinatlar saklandı.("+ALLTRIM(XFILE)+")","Bilgi")
RETURN
//---------------------------------------------------------------------------//
METHOD Koordinat_Restore() CLASS tApplication
LOCAL XFILE, aMyIni,cParagraf, nTop, nLeft, nHeight,
nWidth     
    xFILE=::CROOT+"AAAA.INI"
    aMyIni := IniLoad(XFILE)
    cParagraf := "DESKTOP_"+ALLTRIM(::aUSERINFO[1])

    nTop        := 0
    nLeft       := 0
    nHeight := 0
    nWidth  := 0

    IF FILE(XFILE)
        nTop        := VAL(OIniGet(aMyIni,cParagraf,"nTop","0"))
        nLeft   := VAL(OIniGet(aMyIni,cParagraf,"nLeft","0"))
        nHeight := VAL(OIniGet(aMyIni,cParagraf,"nHeight","0"))
        nWidth  := VAL(OIniGet(aMyIni,cParagraf,"nWidth","0"))
    ENDIF

    IF !EMPTY(nTop) .AND. !EMPTY(nLeft) .AND. !EMPTY(nHeight) .AND. !EMPTY(nWidth)
        ::oWnd:SetSize(nWidth, nHeight, .T.)
        ::oWnd:SetPos(nTop, nLeft)
    ENDIF

RETURN
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
User avatar
avista
Posts: 301
Joined: Fri Jun 01, 2007 9:07 am
Location: Macedonia

Re: How to save and restore windows position and size?

Post by avista »

Hi,

You can use function

aKoordinat := GetWndRect(oDlg:hWnd)

Best regards,
Horizon
Posts: 1329
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 6 times
Been thanked: 1 time

Re: How to save and restore windows position and size?

Post by Horizon »

Thank you for your answer.

I have found the solution like that.

Code: Select all | Expand

   ::oWnd:Normal()      <------- It solves my problem.
   ::oWnd:SetSize(nWidth, nHeight, .T.)
   ::oWnd:SetPos(nTop, nLeft)
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Post Reply