VB4.0 ExtractIcon, DrawIcon API calls 
Author Message
 VB4.0 ExtractIcon, DrawIcon API calls

OK...let me know what I'm doing wrong!  I just can't figure this one
out!

I'm extracting icons from exe's and dll's to place them in a ImageList
to get them on a VB 4.0 (32bit) toolbar custom control.  

Here's what I'm doing.....

Declarations:

Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As
Long, ByVal y As Long, ByVal hIcon As Long) As Long

Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA"
(ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal
nIconIndex As Long) As Long

Declare Function GetModuleHandle Lib "kernel32" Alias
"GetModuleHandleA" (ByVal lpModuleName As String) As Long

Code:

hModule = GetModuleHandle("d:\vbpro\VB32.EXE")
Iconh = ExtractIcon(hModule, IconFile + Chr$(0), IconNumber - 1)
z% = DrawIcon(Form1.TempPicture.hdc, x, y, Iconh)
Dim imgX As ListImage
Dim btnX As Button
Set imgX = Form1.ImageList1.ListImages.Add(, "JUNK",
Form1.TempPicture.Picture))
Set btnX = Form1.Toolbar1.Buttons.Add(, "JUNK", , 0, "JUNK")

When it get to the point where I'm attempting to add a picture to the
ListImage control, I get a Run Time Error 431 "Invalid
Picture"...!!!????  Funny thing is...I can't do much of anything with
this extracted picture (Icon).  I get basically the same type of error
if I try and use the SavePicture method on my picture box control.

All this worked great under VB 3.0....except the toolbar control just
wasn't there.  As stated in the declarations above, I made sure I'm
calling all the 32 library functions instead of the 16 bit. The icon
makes it fin into the TempPicture control...but no dice when I try and
copy it to another control with the Picture property.

WHAT GIVES.....!!!!??????

Thanks in advance!!
Bob Templeton.



Thu, 30 Apr 1998 03:00:00 GMT  
 VB4.0 ExtractIcon, DrawIcon API calls

Quote:
>OK...let me know what I'm doing wrong!  I just can't figure this one
>out!
>I'm extracting icons from exe's and dll's to place them in a ImageList
>to get them on a VB 4.0 (32bit) toolbar custom control.  
>Here's what I'm doing.....
>Declarations:
>Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As
>Long, ByVal y As Long, ByVal hIcon As Long) As Long
>Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA"
>(ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal
>nIconIndex As Long) As Long
>Declare Function GetModuleHandle Lib "kernel32" Alias
>"GetModuleHandleA" (ByVal lpModuleName As String) As Long
>Code:
>hModule = GetModuleHandle("d:\vbpro\VB32.EXE")
>Iconh = ExtractIcon(hModule, IconFile + Chr$(0), IconNumber - 1)
>z% = DrawIcon(Form1.TempPicture.hdc, x, y, Iconh)
>Dim imgX As ListImage
>Dim btnX As Button
>Set imgX = Form1.ImageList1.ListImages.Add(, "JUNK",
>Form1.TempPicture.Picture))
>Set btnX = Form1.Toolbar1.Buttons.Add(, "JUNK", , 0, "JUNK")
>When it get to the point where I'm attempting to add a picture to the
>ListImage control, I get a Run Time Error 431 "Invalid
>Picture"...!!!????  Funny thing is...I can't do much of anything with
>this extracted picture (Icon).  I get basically the same type of error
>if I try and use the SavePicture method on my picture box control.
>All this worked great under VB 3.0....except the toolbar control just
>wasn't there.  As stated in the declarations above, I made sure I'm
>calling all the 32 library functions instead of the 16 bit. The icon
>makes it fin into the TempPicture control...but no dice when I try and
>copy it to another control with the Picture property.
>WHAT GIVES.....!!!!??????
>Thanks in advance!!
>Bob Templeton.

Try using an instance handle for the executing app.  The following
code snippet is from a working application:

   ' read all icons into image list
   For ndxIcons = 0 To lngNumIcons - 1
      mhndIcon = ExtractIcon(mhndInstance, strFileName, ndxIcons)
      picIcon.Picture = LoadPicture()  ' clear picture control
      lngRet = DrawIcon(picIcon.hdc, 0, 0, mhndIcon)
      picIcon.Refresh
      Set imgX = imglMain.ListImages.Add(ndxIcons + 1, ,
picIcon.Image)
   Next ndxIcons



Fri, 01 May 1998 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. The use of EXTRACTICON & DRAWICON function

2. LoadIcon, CreateIcon*.*, DrawIcon*.*, GetIconInfo and ExtractIcon

3. ExtractIcon api call and then saving the icon to a file (HELP)

4. API loadIcon and API drawicon

5. using DrawIcon or DrawIconEX call from VB

6. ExtractIcon in VB4

7. API: Using ExtractIcon and .Picture property

8. Icons, extracticon API

9. Icons, extracticon API

10. Icons, extracticon API

11. ExtractIcon API:NewBie needs help

12. ExtractIcon API

 

 
Powered by phpBB® Forum Software