Results 1 to 5 of 5

Thread: Icons: Extracting them, saving them, replacing them

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    2

    Question

    Hi all!

    I really looked now over 2 Weeks in the web, and I wandered around in IRC Channels and board, but I didn't find ANY information, how to Save an extracted Icon to a file
    or how to replace an Icon of an exefile with another icon (well I believe if I can at least save the icon to a file, the second problem will be solved aswell).
    I tried to experiment with the call ExtractIconExA and DrawIcon to a PictureBox, BUT my problem is, that the SavePicture command only saves the icons in bitmap format, and I want them in ICO format.
    I don't need any alround functions, a short and fast way to extract and save small icons (those 766 byte large files I think) would do it completely.

    Thanks in advance for your help,

    Arzy

  2. #2
    Guest
    You can do this but it will be really hard. The icon is stored in the EXE itself hence you would have to binary edit it in order to change the icon.

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    2

    Yes I know, but I need the API Calls

    Originally posted by Megatron
    You can do this but it will be really hard. The icon is stored in the EXE itself hence you would have to binary edit it in order to change the icon.
    I'd be really glad if you can tell me at least HOW I extract icons and save them as Icons. The replacement of the EXE Icon is no difficulty then. If you want to know more about the project or you want to help me with the code anyways, I'd say we start an e-mail contact

  4. #4
    Guest
    Sure. Just use the ExtractIcon API to extract the Icon and use DrawIcon to draw the icon. This will give you a bitmap (of the Icon) and you can simply convert it to an Icon using an ImageList control.

    Add the following to a Form with a PictureBox, CommandButton and ImageList.
    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 Sub Command1_Click()
        Dim hIcon As Long
        'Extract the icon from Calculator
        hIcon = ExtractIcon(App.hInstance, "C:\Windows\Calc.exe", 0)
        'Draw the Icon on to Picture1
        DrawIcon Picture1.hdc, 0, 0, hIcon
        Picture1.Picture = Picture1.Image
        'Convert the Bitmap to an Icon
        ImageList1.ListImages.Add , , Picture1.Picture
        Set Picture1.Picture = Nothing
        Set Picture1.Picture = ImageList1.ListImages(1).ExtractIcon
        'Save the Icon
        SavePicture Picture1.Picture, "C:\Windows\Desktop\MyIco.ico"
    End Sub
    
    Private Sub Form_Load()
        'Set initial settings
        Picture1.AutoRedraw = True
        Me.ScaleMode = vbPixels
    End Sub

  5. #5
    Guest
    The ImageList control looks like 3 rectangles stacked on top of each other. It's should be underneath the ProgressBar.

    The library it's located in is called Windows Common Controls.

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