Part IV: Professional Database Development
962
Alias “SetWindowTextA”( _
ByVal hwnd As Long, _
ByVal lpszCaption As String) As Long
SetWindowTextA is much like altering the Caption property of a form. Many people find they
want to change the caption of the Access main window to make their applications look more profes-
sional. The function in Listing 27.6 cycles through the windows and controls of an Access application
until it finds the Access application form (class Omain), and then it changes the title-bar text.
LISTING 27.6
Changing the Title-Bar Text for a Window
Function ChangeTitle()
Dim RetVal As Long
Dim Parent As Long
Dim lngRet As Long
Dim Caption As String * 128
Dim CaptionSize As Long
Dim NewCaption As String
Dim WinHwnd As Long
Dim Class As String * 6
Dim ClassSize As Long
NewCaption = “My New Application Title”
CaptionSize = Len(caption)
ClassSize = Len(class)
WinHwnd = Me.hwnd
Do Until Trim(class) = “OMain”
Parent = GetParent(WinHwnd)
lngRet = apiGetClassName(Parent, Class, ClassSize)
WinHwnd = Parent
Loop
RetVal = apiSetWindowText(Parent, NewCaption)
End Function
SetWindowTextA returns 1 when successful, 0 when it fails.
Manipulating application settings
with the Windows API
In the past, software vendors and Microsoft have used .ini files to control the settings of their
applications. The system.ini and win.ini files controlled almost everything in older versions
of Windows. Back then, each application had an .ini file containing sections, string values, key
names, and integer values that related to everything from screen color to network protocols.