The best way to save information about an application’s options, suchas toolbar positioning, is to write the settings to an INI file. To doso, two Windows API functions must be used: GetPrivateProfileInt and WritePrivateProfileString.Here are two functions that load and save settings to and from an INI file:
'These two Declare statements go in the 'Declarations section of a module Declare Function GetPrivateProfileInt Lib "Kernel" _ (ByVal lpApplicationName As String, _ ByVal lpKeyName As String, ByVal nDefault _ As Integer, ByVal lpFileName As String) As Integer Declare Function WritePrivateProfileString _ Lib "Kernel" (ByVal lpApplicationName As String, _ ByVal lpKeyName As String, ByVal lpString _ As String, ByVal lplFileName As String) _ As Integer Sub LoadToolbarInfo (Tb As Control, _ Section As String, ININame As String) Tb.DockRank = GetPrivateProfileInt(Section, _ "DockRank", Tb.DockRank, ININame) Tb.DockRankSeq = GetPrivateProfileInt(Section, _ "DockRankSeq", Tb.DockRankSeq, ININame) Tb.FloatingLeft = GetPrivateProfileInt(Section, _ "FloatingLeft", Tb.FloatingLeft, ININame) Tb.FloatingTop = GetPrivateProfileInt(Section, _ "FloatingTop", Tb.FloatingTop, ININame) Tb.FloatingWidthInBtns = _ GetPrivateProfileInt(Section, _ "FloatingWidthInBtns",Tb.FloatingWidthInBtns, _ ININame) Tb.DockStatus = GetPrivateProfileInt(Section, _ "DockStatus", Tb.DockStatus, ININame) End Sub Sub SaveToolbarInfo (Tb As Control, _ Section As String, ININame As String) Dim rc% rc = WritePrivateProfileString(Section, _ "DockStatus", CStr(Tb.DockStatus), ININame) rc = WritePrivateProfileString(Section, _ "DockRank", CStr(Tb.DockRank), ININame) rc = WritePrivateProfileString(Section, _ "DockRankSeq", CStr(Tb.DockRankSeq), ININame) rc = WritePrivateProfileString(Section, _ "FloatingLeft", CStr(Tb.FloatingLeft), ININame) rc = WritePrivateProfileString(Section, _ "FloatingTop", CStr(Tb.FloatingTop), ININame) rc = WritePrivateProfileString(Section, _ "FloatingWidthInBtns", _ CStr(Tb.FloatingWidthInBtns), ININame) End Sub
This code can be found in the SAMPLESTBARSAVE directory that’sincluded with Designer Widgets.