![]() |
SOLVED: How to set a IconID from a PictureBox |
Post Reply ![]() |
Author | |
McKloony ![]() Senior Member ![]() ![]() Joined: 09 January 2007 Location: Germany Status: Offline Points: 340 |
![]() ![]() ![]() ![]() ![]() 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 |
|
![]() |
|
Aaron ![]() Senior Member ![]() Joined: 29 January 2008 Status: Offline Points: 2192 |
![]() ![]() ![]() ![]() ![]() |
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.... |
|
![]() |
|
McKloony ![]() Senior Member ![]() ![]() Joined: 09 January 2007 Location: Germany Status: Offline Points: 340 |
![]() ![]() ![]() ![]() ![]() |
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 |
|
![]() |
|
Aaron ![]() Senior Member ![]() Joined: 29 January 2008 Status: Offline Points: 2192 |
![]() ![]() ![]() ![]() ![]() |
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.... |
|
![]() |
|
McKloony ![]() Senior Member ![]() ![]() Joined: 09 January 2007 Location: Germany Status: Offline Points: 340 |
![]() ![]() ![]() ![]() ![]() |
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 |
|
![]() |
|
Aaron ![]() Senior Member ![]() Joined: 29 January 2008 Status: Offline Points: 2192 |
![]() ![]() ![]() ![]() ![]() |
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.... |
|
![]() |
|
Oleg ![]() Admin Group ![]() Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
![]() ![]() ![]() ![]() ![]() |
... And don't forget to free resources with DestroyIcon
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |