devxlogo

Saving the Position of a Designer Widgets’ Dockable Toolbar

Saving the Position of a Designer Widgets’ Dockable Toolbar

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.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist