Solved

Saving A Picture Box as An Icon

Posted on 1997-04-24
2
407 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

734 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