这段代码可以返回Icon的HwndPrivate Sub cmdLoad_Click()    Dim hImgSmall As Long     ' The handle to the system image list
    Dim FileName As String    ' The file name to get icon from
    Dim r As Long    FileName$ = txtFileName.Text
   
    ' Get the system icons associated with the file
    hImgSmall& = SHGetFileInfo(FileName$, 0&, shinfo, Len(shinfo), _
                 BASIC_SHGFI_FLAGS Or SHGFI_SMALLICON)    hImgLarge& = SHGetFileInfo(FileName$, 0&, shinfo, Len(shinfo), _
                 BASIC_SHGFI_FLAGS Or SHGFI_LARGEICON)
   
    ' Fill in the labels with the image's file data
    lblFileName.Caption = Left$(shinfo.szDisplayName, _
               InStr(shinfo.szDisplayName, Chr$(0)) - 1)    lblFileType.Caption = Left$(shinfo.szTypeName, _
               InStr(shinfo.szTypeName, Chr$(0)) - 1)
   
    ' Set the pictureboxes to receive the icons.
    picSmall.Picture = LoadPicture()    picLarge.Picture = LoadPicture()
   
    ' Draw the associated icons into the picture boxes
    r& = ImageList_Draw(hImgSmall&, shinfo.iIcon, picSmall.hDC, 0, 0, ILD_TRANSPARENT)
    r& = ImageList_Draw(hImgLarge&, shinfo.iIcon, picLarge.hDC, 0, 0, ILD_TRANSPARENT)    
End Sub下面的声明用于设置Icon
Option ExplicitPublic Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
    (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function LoadIcon Lib "user32" Alias "LoadIconA" _
    (ByVal hInstance As Long, lpIconName As Any) As LongPublic Const GWL_HWNDPARENT = (-8)Public Const WM_GETICON = &H7F
Public Const WM_SETICON = &H80Public Const ICON_SMALL = 0
Public Const ICON_BIG = 1 以下是设置Icon的代码Private nRet         As Long
Private nMainhWnd    As LongPrivate Sub Form_Load()
    nRet = GetWindowLong(Me.hWnd, GWL_HWNDPARENT)
    Do While nRet
       nMainhWnd = nRet
       nRet = GetWindowLong(nMainhWnd, GWL_HWNDPARENT)
    Loop
End SubPrivate Sub Command1_Click()
    Dim hIcon As Long
    
    ' set the icon
    Set Me.Icon = Picture1.Picture
    ' get a handle to ICON_BIG
    hIcon = SendMessage(Me.hWnd, WM_GETICON, ICON_BIG, ByVal 0)
    ' send ICON_BIG to the main window
    SendMessage nMainhWnd, WM_SETICON, ICON_BIG, ByVal hIcon 
End Sub