Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Saving A Picture Box as An Icon

Posted on 1997-04-24
2
Medium Priority
?
418 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 200 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…
Suggested Courses

722 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