hico=ExtractIcon(0,"c:\1.exe",0)
DrawIcon Picture1.hDC,0,0,hicoDrawIcon VB声明 
Declare Function DrawIcon Lib "user32" Alias "DrawIcon" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long 
说明 
在指定的位置画一个图标 
返回值 
Long,非零表示成功,零表示失败。会设置GetLastError 
参数表 
参数 类型及说明 
hdc Long,设备场景 
x,y Long,想描绘图标的位置(逻辑坐标) 
hIcon Long,欲描绘图标的句柄 
DrawIconEx VB声明 
Declare Function DrawIconEx Lib "user32" Alias "DrawIconEx" (ByVal hdc As Long, ByVal xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long 
说明 
描绘一个图标或鼠标指针。与DrawIcon相比,这个函数提供了更多的功能 
返回值 
Long,非零表示成功,零表示失败。会设置GetLastError 
参数表 
参数 类型及说明 
hdc Long,要在其中画图的一个设备场景的句柄 
xLeft,yTop Long,图标左上角的位置,用逻辑坐标表示 
hIcon Long,要描绘的图标的句柄 
cxWidth,cyWidth Long,希望的图标宽度和高度。图标会自动缩放,与指定的值相符 
istepIfAniCur Long,如果hIcon是个动画指针,那么该参数指定描绘动画中的哪幅图象。注意Win32不能区分图标和指针 
hbrFlickerFreeDraw Long,如设为一个刷子句柄,那么函数会将图标画入一幅内存位图,并用背景色填充。随后,将图象直接复制到指定的位置。这样做可绘图时减少闪烁(因为画图过程中重现) 
diFlags Long,下述常数之一: 
DI_COMPAT 描绘标准的系统指针,而不是指定的图象 
DI_DEFAULTSIZE 忽略cxWidth和cyWidth设置,并采用原始的图标大小 
DI_IMAGE 绘图时使用图标的XOR部分(即图标没有透明区域) 
DI_MASK 绘图时使用图标的MASK部分(如单独使用,可获得图标的掩模) 
DI_NORMAL 用常规方式绘图(合并 DI_IMAGE 和 DI_MASK) 
注解 
应检查Windows95是否与指定的标志及参数兼容。Win32用户手册宣称函数与Windows 95是兼容的,但在实际运用中发现它有一定的限制
 

解决方案 »

  1.   

    Const DI_MASK = &H1
    Const DI_IMAGE = &H2
    Const DI_NORMAL = &H3
      

  2.   

    是大侠的Form1.frmVERSION 5.00
    Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.1#0"; "COMDLG32.OCX"
    Begin VB.Form Form1 
       Caption         =   "Form1"
       ClientHeight    =   4770
       ClientLeft      =   60
       ClientTop       =   345
       ClientWidth     =   7785
       LinkTopic       =   "Form1"
       ScaleHeight     =   4770
       ScaleWidth      =   7785
       StartUpPosition =   3  'Windows Default
       Begin MSComDlg.CommonDialog CommonDlg1 
          Left            =   2910
          Top             =   3270
          _ExtentX        =   847
          _ExtentY        =   847
          _Version        =   327680
       End
       Begin VB.PictureBox pixLarge 
          Appearance      =   0  'Flat
          AutoRedraw      =   -1  'True
          AutoSize        =   -1  'True
          BackColor       =   &H80000005&
          ForeColor       =   &H80000008&
          Height          =   480
          Left            =   3840
          ScaleHeight     =   450
          ScaleWidth      =   450
          TabIndex        =   3
          Top             =   1620
          Width           =   480
       End
       Begin VB.PictureBox pixSmall 
          Appearance      =   0  'Flat
          AutoRedraw      =   -1  'True
          AutoSize        =   -1  'True
          BackColor       =   &H80000005&
          ForeColor       =   &H80000008&
          Height          =   240
          Left            =   1680
          ScaleHeight     =   210
          ScaleWidth      =   210
          TabIndex        =   2
          Top             =   1650
          Width           =   240
       End
       Begin VB.CommandButton Command2 
          Caption         =   "Command2"
          Height          =   495
          Left            =   4530
          TabIndex        =   1
          Top             =   4020
          Width           =   1215
       End
       Begin VB.CommandButton Command1 
          Caption         =   "Command1"
          Height          =   495
          Left            =   1050
          TabIndex        =   0
          Top             =   3870
          Width           =   1215
       End
       Begin VB.Label Label2 
          AutoSize        =   -1  'True
          Caption         =   "Label2"
          Height          =   180
          Left            =   4245
          TabIndex        =   5
          Top             =   2775
          Width           =   540
       End
       Begin VB.Label Label1 
          AutoSize        =   -1  'True
          Caption         =   "Label1"
          Height          =   180
          Left            =   1515
          TabIndex        =   4
          Top             =   2715
          Width           =   540
       End
    End
    Attribute VB_Name = "Form1"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
    '在form中添加2个按钮(Command1 & Command2),
    '两个label(Label1 & Label2),
    '两个picture boxe (pixSmall and pixLarge).
    '保证form和两个picturebox的scale modes设置为1(Twips)
    '设置两个picture box的属性如下:
    '    Appearance = 0 (flat)
    '    AutoRedraw = True
    '    AutoResize = False
    '    BorderStyle = 0 (none)
    '设置pixSmall的属性:
    '    Height = 240 twips
    '    Width = 240 twips'设置pixLarge的属性:
    '    Height = 480 twips
    '    Width = 480 twips'把下面的代码放在Form中Option ExplicitPrivate Sub Form_Load()
      
      Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2End Sub
    Private Sub Command2_Click()  Unload MeEnd Sub
    Private Sub Command1_Click()
        Dim hImgSmall As Long  'the handle to the system image list
      Dim hImgLarge As Long
      Dim fName As String    'the file name to get icon from
      Dim fnFilter As String  'the file name filter
      Dim r As Long
      
        
      On Local Error GoTo Command1ErrorHandler
      
        
      fnFilter = "All Files (*.*)|*.*|"
      fnFilter = fnFilter & "Applications (*.exe)|*.exe|"
      fnFilter = fnFilter & "Windows Bitmap (*.bmp)|*.bmp|"
      fnFilter = fnFilter & "Icon Files (*.ico)|*.ico"  CommonDlg1.CancelError = True
      CommonDlg1.Filter = fnFilter
      CommonDlg1.ShowOpen  fName = CommonDlg1.filename
      
        
      hImgSmall& = SHGetFileInfo(fName, 0&, _
                                  shinfo, Len(shinfo), _
                                  BASIC_SHGFI_FLAGS Or SHGFI_SMALLICON)  hImgLarge& = SHGetFileInfo(fName, 0&, _
                                  shinfo, Len(shinfo), _
                                  BASIC_SHGFI_FLAGS Or SHGFI_LARGEICON)
      
        
        Label1.Caption = Left$(shinfo.szDisplayName, _
                  InStr(shinfo.szDisplayName, Chr$(0)) - 1)    Label2.Caption = Left$(shinfo.szTypeName, _
                  InStr(shinfo.szTypeName, Chr$(0)) - 1)
      
      
      pixSmall.Picture = LoadPicture()
      pixSmall.AutoRedraw = True  pixLarge.Picture = LoadPicture()
      pixLarge.AutoRedraw = True
      
      
      Call ImageList_Draw(hImgSmall&, shinfo.iIcon, pixSmall.hDC, 0, 0, ILD_TRANSPARENT)
      Call ImageList_Draw(hImgLarge&, shinfo.iIcon, pixLarge.hDC, 0, 0, ILD_TRANSPARENT)
      
      pixSmall.Picture = pixSmall.Image
      pixLarge.Picture = pixLarge.Image
      Exit SubCommand1ErrorHandler:
    Exit SubEnd Sub
    '说明:
    '运行这个工程, 任意选择文件。在关闭common dialog时,
    '和所选文件关联的大小图标(或系统默认图标)就会显示,
    '条件是,该文件在注册表中有关联图标.
    Module1.basAttribute VB_Name = "Module1"
    Option ExplicitPublic Const MAX_PATH = 260
    Public Const SHGFI_DISPLAYNAME = &H200
    Public Const SHGFI_EXETYPE = &H2000
    Public Const SHGFI_SYSICONINDEX = &H4000 'system icon index
    Public Const SHGFI_LARGEICON = &H0 'large icon
    Public Const SHGFI_SMALLICON = &H1 'small icon
    Public Const SHGFI_SHELLICONSIZE = &H4
    Public Const SHGFI_TYPENAME = &H400
    Public Const ILD_TRANSPARENT = &H1 'display transparent
    Public Const BASIC_SHGFI_FLAGS = SHGFI_TYPENAME Or _
                                    SHGFI_SHELLICONSIZE Or _
                                    SHGFI_SYSICONINDEX Or _
                                    SHGFI_DISPLAYNAME Or _
                                    SHGFI_EXETYPEPublic Type SHFILEINFO
      hIcon As Long
      iIcon As Long
      dwAttributes As Long
      szDisplayName As String * MAX_PATH
      szTypeName As String * 80
    End TypePublic Declare Function SHGetFileInfo Lib _
      "shell32.dll" Alias "SHGetFileInfoA" _
      (ByVal pszPath As String, _
        ByVal dwFileAttributes As Long, _
        psfi As SHFILEINFO, _
        ByVal cbSizeFileInfo As Long, _
        ByVal uFlags As Long) As LongPublic Declare Function ImageList_Draw Lib "comctl32.dll" _
      (ByVal himl As Long, ByVal i As Long, _
        ByVal hDCDest As Long, ByVal x As Long, _
        ByVal y As Long, ByVal flags As Long) As LongPublic shinfo As SHFILEINFO