Solved

Saving A Picture Box as An Icon

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now