Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Aug 19, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Saving the Position of a Designer Widgets' Dockable Toolbar

The best way to save information about an application's options, such as toolbar positioning, is to write the settings to an INI file. To do so, 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, _ 
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 SAMPLES\TBARSAVE directory that's included with Designer Widgets.
Sheridan Software
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date