How to Get Program Manager Group Names into Combo Box in VBID: Q80410
|
To get a list of group names in the Windows 3.0 Program Manager, you can call the Windows API GetPrivateProfileString function from a Visual Basic program. This article describes a method of using the Windows API GetPrivateProfileString function to get all the group names from Program Manager and place them into a Visual Basic combo box.
Windows initialization (.INI) files contain information that defines
your Windows environment. Examples of Windows initialization files are
WIN.INI and SYSTEM.INI, which are commonly found in the C:\WINDOWS
subdirectory. Windows and Windows-based applications can use the
information stored in these files to configure themselves to meet your
needs and preferences. For a description of initialization files, read the
WININI.TXT file that comes with Microsoft Windows 3.0.
An initialization file is composed of at least an application name and
a key name. The contents of Windows initialization files have the
following format:
[Application name]
keyname=value
Declare Function GetPrivateProfileString% Lib "Kernel"
(ByVal lpAppName$, ByVal lpKeyName$, ByVal lpDefault$,
ByVal lpReturnedString$, ByVal nSize%, ByVal lpFileName$)
Argument Description
---------------------------------------------------------------------------
lpAppName$ Name of a Windows-based application that appears in the
.INI file.
lpKeyName$ Key name that appears in the .INI file.
lpFileName$ Points to a string that names the .INI file. If
lpFileName does not contain a path to the file,
Windows searches for the file in the Windows
directory.
lpDefault$ Specifies the default value for the given
key if the key cannot be found in the
.INI file.
lpReturnedString$ Specifies the buffer that receives the character
string.
nSize% Specifies the maximum number of characters
(including the last null character) to be copied to
the buffer.
Declare Function GetPrivateProfileString% Lib "kernel"
(ByVal lpAppName$, ByVal lpKeyName$,ByVal
lpDefault$,ByVal lpReturnString$,ByVal nSize%,
ByVal lpFileName$)
Sub Form_Load()
' This is the name of the group in the PROGMAN.INI file
lpAppName$ = "Groups"
' All group names start with Group: Group1, Group2, etc.
lpKeyName$ = "Group"
' If no group found return value in lpDefault$
lpDefault$ = ""
' Initialize string
lpReturnString$ = Space$(128)
Size% = Len(lpReturnString$)
' This is the path and name the PROGMAN.INI file.
lpFileName$ = "c:\windows\progman.ini"
Valid% = 1
i% = 0
While (Valid%)
i% = i% + 1
' The following three lines must be typed on a single line
Valid% = GetPrivateProfileString(lpAppName$, lpKeyName$
+ LTrim$(Str$(i%)), lpDefault$, lpReturnString$,
Size%, lpFileName$)
' Discard the trailing spaces and null character.
group$ = Left$(lpReturnString$, Valid%)
' check to see if string was returned. Change arguments
' passed to the Mid$ statement to change what is displayed in combo
' box. By setting number to 15 this strips c:\windows\
' and .GRP
' The following 2 lines must be on one line
If Valid% > 0 Then combo1.AddItem Mid(group$, 12,
Len(group$) - 15)
Wend
' Set text of combo box to first item in list
combo1.listindex = 0
End Sub
Additional query words: 2.00 3.00
Keywords :
Version :
Platform :
Issue type :
Last Reviewed: June 21, 1999