Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Command Bars
  New Posts New Posts RSS Feed - SOLVED: How to set a IconID from a PictureBox
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

SOLVED: How to set a IconID from a PictureBox

 Post Reply Post Reply
Author
Message
McKloony View Drop Down
Senior Member
Senior Member
Avatar

Joined: 09 January 2007
Location: Germany
Status: Offline
Points: 340
Post Options Post Options   Thanks (0) Thanks(0)   Quote McKloony Quote  Post ReplyReply Direct Link To This Post Topic: SOLVED: How to set a IconID from a PictureBox
    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
Back to Top
Aaron View Drop Down
Senior Member
Senior Member
Avatar

Joined: 29 January 2008
Status: Offline
Points: 2192
Post Options Post Options   Thanks (0) Thanks(0)   Quote Aaron Quote  Post ReplyReply Direct Link To This Post 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....
Back to Top
McKloony View Drop Down
Senior Member
Senior Member
Avatar

Joined: 09 January 2007
Location: Germany
Status: Offline
Points: 340
Post Options Post Options   Thanks (0) Thanks(0)   Quote McKloony Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Aaron View Drop Down
Senior Member
Senior Member
Avatar

Joined: 29 January 2008
Status: Offline
Points: 2192
Post Options Post Options   Thanks (0) Thanks(0)   Quote Aaron Quote  Post ReplyReply Direct Link To This Post 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....
Back to Top
McKloony View Drop Down
Senior Member
Senior Member
Avatar

Joined: 09 January 2007
Location: Germany
Status: Offline
Points: 340
Post Options Post Options   Thanks (0) Thanks(0)   Quote McKloony Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Aaron View Drop Down
Senior Member
Senior Member
Avatar

Joined: 29 January 2008
Status: Offline
Points: 2192
Post Options Post Options   Thanks (0) Thanks(0)   Quote Aaron Quote  Post ReplyReply Direct Link To This Post 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....
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 27 May 2009 at 2:17am
... And don't forget to free resources with DestroyIcon
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.043 seconds.