VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 客户端邮件的列表
发表评论(0)作者:Karl Moore, 平台:VB6.0+Win98, 阅读:7752, 日期:2001-04-24
Listing the Mail Clients

How many mail clients do you have? Don注释:t bother looking in that little black book. Oh no, it only takes a quick dip in the registry to find out.

And this handy copy-and-paste code snippet will handle all that for you.

To use this code, simply call ListMailClients, passing in a List Box control as an argument. It will then clear the list and place names of all the installed mail clients onto it.

Of course, you can easily modify this code so it perhaps returns an array of names or further details about each mail program. But that注释:s for another tip.

This code works by dipping into the mail clients section of the registry, then enumerating all existing keys, placing their names in the specified List Box.

Usage

Call ListMailClients(List1)Code

注释: To be put inside a module

Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" _
  (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) _
  As Long

Declare Function RegEnumKey Lib "advapi32.dll" Alias _
  "RegEnumKeyA" (ByVal hKey As Long, ByVal dwIndex As Long, _
  ByVal lpName As String, ByVal cbName As Long) As Long

Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey _
  As Long) As Long

Public Const HKEY_LOCAL_MACHINE = &H80000002

Public Sub ListMailClients(ListBox As ListBox)
    
    Dim strKey As String * 255
    Dim lngRegKey As Long
    Dim intKey As Integer

    ListBox.Clear

    Call RegOpenKey(HKEY_LOCAL_MACHINE, "Software\Clients\Mail", lngRegKey)

    While RegEnumKey(lngRegKey, intKey, strKey, 255) = 0
        ListBox.AddItem Left(strKey, InStr(strKey, Chr(0)) - 1)
        intKey = intKey + 1
    Wend

    Call RegCloseKey(lngRegKey)

End SubTip by Karl Moore