Results 1 to 3 of 3

Thread: Saving an icon

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Question

    Hi,

    I'm creating a little utility that extracts an icon from a *.exe or *.dll. I'm sure many of you have done it using the ExtractIcon API. Anyway, the programs just about finished except for one feature, saving the icon. The icon is stored inside a variable called lngIcon so how would I save it in the format of *.ico? Thanks
    rino_2
    Visual Basic, HTML
    Please Visit my Site: Richard's VB Site

  2. #2
    Guest
    Try this.

    Make a Form with a PictureBox, ImageList and CommandButton

    Code:
    Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
    Private Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
    Private Declare Function DestroyIcon Lib "user32.dll" (ByVal hIcon As Long) As Long
    
    Private Sub Command1_Click()
    
        'Extract the Icon and Draw it
        Retval = ExtractIcon(App.hInstance, "C:\Windows\Calc.exe", 0)
        DrawIcon Picture1.hdc, 0, 0, Retval
        Picture1.Picture = Picture1.Image
        
        'Convert the Bitmap to an Icon
        ImageList1.ListImages.Add 1, "Calc", Picture1.Picture
        Set Picture1.Picture = ImageList1.ListImages(1).ExtractIcon
        
        'Save the file
        SavePicture Picture1.Picture, "C:\Windows\Desktop\ttt.ico"
        'Free up resources
        DestroyIcon (Retval)
    
    End Sub
    
    Private Sub Form_Load()
    
        Picture1.AutoRedraw = True
        
    End Sub

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Thumbs up

    Thanks Megatron,

    I'll give that a try.
    rino_2
    Visual Basic, HTML
    Please Visit my Site: Richard's VB Site

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width