Date: 02-16-2022
Return to Index
created by gbSnippets
'Credit: Piere Bellisle
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
Global hDlg,Zoomed As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "PowerBASIC",300,300,200,200, %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 Zoomed = %SW_ShowMaximized Then Dialog Maximize hDlg
If Zoomed = %SW_ShowMinimized Then Dialog Minimize hDlg
Case %WM_Destroy
Settings_INI "save"
End Select
End Function
Sub Settings_INI(Task$)
Local WinPla As WindowPlacement, xResult, yResult, temp, INIFileName As WStringZ*%Max_Path
INIFileName = Exe.Path$ + Exe.Name$ + ".ini"
If Task$ = "get" Then
'get dialog top/left from INI file and use to set Dialog location
Getprivateprofilestring "All", "Left", "300", xResult, %Max_Path, INIFileName
Getprivateprofilestring "All", "Top", "300", yResult, %Max_Path, INIFileName
Dialog Set Loc hDlg, Val(xResult), Val(yResult) 'left/top
'get dialog width/height from INI file and use to set Dialog size
GetPrivateProfileString "All", "Width", "400", xResult, %Max_Path, INIFileName
GetPrivateProfileString "All", "Height", "200", yResult, %Max_Path, INIFileName
Dialog Set Size hDlg,Val(xResult), Val(yResult) 'width/height
Getprivateprofilestring "All", "Zoomed", Str$(%SW_ShowNormal), temp, %Max_Path, INIFileName: Zoomed = Val(temp)
End If
If Task$ = "save" Then
'save dialog size/location, as well as Min/Max state
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
WritePrivateProfileString "All", "Zoomed",Str$(WinPla.showCmd), INIFileName
End If
End Sub
http://www.garybeene.com/sw/gbsnippets.htm