Print Page | Close Window

SOLVED: How to set a IconID from a PictureBox

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=14375
Printed Date: 06 November 2025 at 8:08am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: SOLVED: How to set a IconID from a PictureBox
Posted By: McKloony
Subject: SOLVED: How to set a IconID from a PictureBox
Date Posted: 25 May 2009 at 3:52am
I loaded a 16x16 picture to a PictureBox. How can I set this Picture as IconID to a CommandBar Button?


-------------
Product: Xtreme SuitePro (ActiveX) 16.2.5

Platform: XP / Windows 7

Language: Visual Basic 6.0 SP6



Replies:
Posted By: Aaron
Date Posted: 25 May 2009 at 5:36am
Hi,
 
Add image to Commandbars.Icons:
 
     Icon:
     CommandBars.Icons.AddIcon Picture1.Picture.Handle, IMAGE_ID, xtpImageNormal
 
     Bitmap:
     CommandBars1.Icons.AddBitmap Picture1.Picture.Handle, IMAGE_ID, xtpImageNormal, False
   
 
 


-------------
Product: Xtreme SuitePro (ActiveX) version 15.0.2
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0

Zero replies is not an option....


Posted By: McKloony
Date Posted: 25 May 2009 at 8:42am
I tried it with:
 
ImageManager.Icons.AddBitmap Picture1.Picture.Handle, IMAGE_ID, xtpImageNormal, False
 
but it doesn't work. Now Bitmal will be added. Is there any function to find out why not?
 


-------------
Product: Xtreme SuitePro (ActiveX) 16.2.5

Platform: XP / Windows 7

Language: Visual Basic 6.0 SP6


Posted By: Aaron
Date Posted: 25 May 2009 at 11:12am
Hi,
 
Did you try following?
 
Select case Picture1.Picture.Type
    Case 3 'Picture = Icon
         ImageManager.Icons.AddIcon Picture1.Picture.Handle, IMAGE_ID, xtpImageNormal
    Case 1 'Picture = Bitmap
         ImageManager.Icons.AddBitmap Picture1.Picture.Handle, IMAGE_ID, xtpImageNormal, False
End Select
 
 


-------------
Product: Xtreme SuitePro (ActiveX) version 15.0.2
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0

Zero replies is not an option....


Posted By: McKloony
Date Posted: 26 May 2009 at 3:01am

I use the following code to extract a  Icon from a *.exe File:

Private Declare Function DrawIconEx Lib "user32" (ByVal hDC As Long, ByVal xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long
Private Declare Function ExtractIconEx Lib "shell32.dll" Alias "ExtractIconExA" (ByVal lpszFile As String, ByVal nIconIndex As Long, phiconLarge As Long, phiconSmall As Long, ByVal nIcons As Long) As Long
 
ReDim BigIco(RetWe)
ReDim SmlIco(RetWe)
 
RetWe = ExtractIconEx(FileName, 0, BigIco(RetWe), SmlIco(RetWe), 1)
With PicureBox
    .Height = 16 * Screen.TwipsPerPixelY
    .Width = 16 * Screen.TwipsPerPixelY
    Set .Picture = LoadPicture("")
    .AutoRedraw = True
    RetWe = DrawIconEx(.hDC, 0, 0, SmlIco(1), 16, 16, 0, 0, 3)
    .Refresh
End With
Select Case PicureBox.Picture.Type
Case 3: ImMan.Icons.AddIcon PicureBox.Picture.Handle, Prg_Icn2, xtpImageNormal
Case 1: ImMan.Icons.AddBitmap PicureBox.Picture.Handle, Prg_Icn2, xtpImageNormal, False
End Select

Set CommandBarButton = CommandBars.ActiveMenuBar.Controls.Add(xtpControlButton, ID_Test, "Test")
With CommandBarButton
 .flags = xtpFlagRightAlign
 .IconId = Prg_Icn2
 .Style = xtpButtonIconAndCaption
End With
 
 


-------------
Product: Xtreme SuitePro (ActiveX) 16.2.5

Platform: XP / Windows 7

Language: Visual Basic 6.0 SP6


Posted By: Aaron
Date Posted: 26 May 2009 at 2:12pm
Hi,
 
You can use BigIco and SmlIco directly to load icon into ImageManager
 
Note: retwe will contain number of returned icons, so you have to check retwe > 0 and BigIco and SmlIco aren't NULL. Following will extract icon and add it to ImageManager.Icons
 
 
Dim BigIco As Long
Dim smlIco As Long
dim retwe as Integer

retwe = ExtractIconEx(strFile, 0, BigIco, smlIco, 1)
ImMan.Icons.AddIcon SmlIco, 2, xtpImageNormal
 


-------------
Product: Xtreme SuitePro (ActiveX) version 15.0.2
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0

Zero replies is not an option....


Posted By: Oleg
Date Posted: 27 May 2009 at 2:17am
... And don't forget to free resources with mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN\2000APR\1033\wcesdkr.chm::/htm/uif_d_9.htm - DestroyIcon


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net