Results 1 to 3 of 3

Thread: How to save & load an exe's icon with the ExtractAssociatedIcon Win32 API function?

  1. #1
    Stiletto
    Guest

    How to save & load an exe's icon with the ExtractAssociatedIcon Win32 API function?

    Sups all
    i've put an icon of an exe in a picturebox
    now i need to know how can i save it and load it back...
    can some1 please tell me how to save & load an exe's icon with the ExtractAssociatedIcon Win32 API function?
    tnx

  2. #2
    Megatron
    Guest
    You can't use ExtractAssociatedIcon to replace the Application's current icon. It can only be used to retreieve it.

  3. #3
    Megatron
    Guest
    Okay, here's an example of how to save an Icon. First we use ExtractAssociatedIcon to extract the icon, then we use DrawIcon to draw the icon, finally, we use VB's SavePicture() function to save the icon.

    Add to a Form with a CommandButton and a PictureBox.
    Code:
    Private Declare Function ExtractAssociatedIcon Lib "shell32.dll" Alias "ExtractAssociatedIconA" (ByVal hInst As Long, ByVal lpIconPath As String, lpiIcon 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 Sub Command1_Click()
        
        Dim hIcon As Long
        
        Picture1.AutoRedraw = True
        hIcon = ExtractAssociatedIcon(App.hInstance, "C:\WINDOWS\CALC.EXE", 0)
        DrawIcon Picture1.hdc, 0, 0, hIcon
        Picture1.Refresh
        SavePicture Picture1.Picture, "C:\MYICON.ICO"
        
    End Sub

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