Solved

Saving A Picture Box as An Icon

Posted on 1997-04-24
2
402 Views
Last Modified: 2008-03-10
I need to save a PictureBox as an Icon.  What happens is I load an Icon from a DLL or EXE using the ExtractIcon and DrawIcon API calls just like below:

    Iconh = ExtractIcon(hModule, IconFilename$, Count)
    CurrentIcon = DrawIcon(pbIcons(Count).hdc, 0, 0, Iconh)
    pbIcons(Count).Refresh

the thing is I now want to save that as an ICON File...  I have tried the SavePicture but that doesn't work.  Everything I have seen tells me to see ICONWRKS that came with Visual Basic 3.0.  After looking at that I
determined that what they are doing is a bit different.  They are loading the Icon from a .ICO File and then they use the SavePicture to save it which will work just fine, only problem is I am not loading the icon from a file via (LoadPicture)....
0
Comment
Question by:tward
2 Comments
 
LVL 3

Accepted Solution

by:
ChrisLewis earned 100 total points
ID: 1425709
This is actually quite hard.  It seems that the DrawIcon API draws the Icon as a BMP.  I tried looking into the ListImage Control, which has an ExtractIcon method.  This *Should* do what you want, but I was getting GPF's all over the place.  This is the code that I have so far.+----------+----------+
+----------+----------+
Private Sub Command1_Click()
  Dim imgX As ListImage
  Set imgX = ImageList1.ListImages.Add(, , Picture1.Picture)
  Set imgX = Nothing
End Sub
Private Sub Command2_Click()
  Dim picX As Picture
  Set picX = ImageList1.ListImages(1).ExtractIcon  ' Make an icon.
  Picture2.Picture = picX
  Set picX = Nothing
End Sub
Private Sub Command3_Click()
  SavePicture Picture2.Picture, "C:\icon.ico"
End Sub

+----------+----------+
Try this, but I can't guarrentee that it will work.Chris

0
 
LVL 7

Author Comment

by:tward
ID: 1425710
That was enough to send me in the right direction, thanks...

Below is the code that acutally worked:

Dim ImgX as listimage

Set ImgX = imagelist1.listimages.Add(, , pbIcon.Image)
Set ImgX = Nothing
pbIcon.Picture = imagelist1.listimages(1).ExtractIcon

SavePicture pbIcon.Picture, CommonDialog1.filename


0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question