Solved

Saving A Picture Box as An Icon

Posted on 1997-04-24
2
396 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access 2013 combo box not working 3 51
Copy a row 12 64
How to compare ms sql hashbytes results within vb6 5 84
TT Auto Dashboard 13 95
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

837 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