Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example:
'Compilable Example: 'Jose Includes
'Compilable Example: 'Jose Includes
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
Global hDlg As Dword
Global Minimized, Maximized As Long
Global CFN As WStringZ * %Max_Path
Function PBMain() As Long
Dialog New Pixels, 0, "PowerBASIC",,,1200,800, %WS_OverlappedWindow To hDlg
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_InitDialog
Settings_INI "get"
If Maximized Then Dialog Show State hDlg, %SW_Maximize 'restore Maximized state if necessary
If Minimized Then Dialog Show State hDlg, %SW_Minimize 'restore Maximized state if necessary
Case %WM_Destroy
Settings_INI "save"
Case %WM_Help
CenterDialog hDlg
End Select
End Function
Sub Settings_INI(Task$)
Local x,y,w,h, tempz, INIFileName As WStringZ * %Max_Path, WinPla As WindowPlacement
'set ini filename
INIFileName = Exe.Path$ + Exe.Name$ + ".ini" 'get INI file name
Select Case Task$
Case "get"
'get dialog width/height from INI file and use to set Dialog size
GetPrivateProfileString "All", "Width", "1200", w, %Max_Path, INIFileName
GetPrivateProfileString "All", "Height", "800", h, %Max_Path, INIFileName
Dialog Set Size hDlg,Val(w), Val(h) 'width/height
'get dialog top/left from INI file and use to set Dialog location
Getprivateprofilestring "All", "Left", "0", x, %Max_Path, INIFileName
Getprivateprofilestring "All", "Top", "0", y, %Max_Path, INIFileName
If IsFile(INIFileName) Then Dialog Set Loc hDlg, Val(x), Val(y) 'left/top but only once INIFileName exists
'get value for string variables
GetPrivateProfileString "All", "CFN", "filename.txt", CFN, %Max_Path, INIFileName
'get value for numeric variables
Getprivateprofilestring "All", "Minimized", "0", tempz, %Max_Path, INIFileName : Minimized = Val(tempz)
Getprivateprofilestring "All", "Maximized", "0", tempz, %Max_Path, INIFileName : Maximized = Val(tempz)
Case "save"
If IsFile(INIFileName) Then Kill INIFileName 'clear the INI file Name to remove residual entries before saving
WinPla.Length = SizeOf(WinPla)
GetWindowPlacement hDlg, WinPla
WritePrivateProfileString "All", "Left", Str$(WinPla.rcNormalPosition.nLeft), INIFileName
WritePrivateProfileString "All", "Top", Str$(WinPla.rcNormalPosition.nTop), INIFileName
WritePrivateProfileString "All", "Width", Str$(WinPla.rcNormalPosition.nRight - WinPla.rcNormalPosition.nLeft), INIFileName
WritePrivateProfileString "All", "Height", Str$(WinPla.rcNormalPosition.nBottom - WinPla.rcNormalPosition.nTop), INIFileName
'save string variables
WritePrivateProfileString "All", "CFN", CFN, INIFileName
'save numeric variables
Minimized = IsIconic(hDlg)
Maximized = IsZoomed(hDlg)
WritePrivateProfileString "All", "Minimized", Str$(Minimized), INIFileName
WritePrivateProfileString "All", "Maximized", Str$(Maximized), INIFileName
End Select
End Sub
Sub CenterDialog(hWnd As Dword) 'center in CLIENT area of DeskTOp
Local sx,sy,dx,dy As Long 'screen/client, dialog dimensions
Desktop Get Client To sx,sy 'client size (Use DeskTop Get Size to center on screen)
Dialog Get Size hWnd To dx, dy 'dialog height/width
Dialog Set Loc hWnd, (sx - dx) / 2, (sy - dy) / 2
End Sub
http://www.garybeene.com/sw/gbsnippets.htm