Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - using setcustomicon functionality
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

using setcustomicon functionality

 Post Reply Post Reply
Author
Message
venkyhyd View Drop Down
Groupie
Groupie


Joined: 29 June 2006
Location: India
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote venkyhyd Quote  Post ReplyReply Direct Link To This Post Topic: using setcustomicon functionality
    Posted: 05 August 2006 at 7:36am
Hi,
 
i want to load a icon from the resources on to the toolbar button.
i am getting the handle to the desired control with the following code.
 
 

CXTPCommandBars* pCommandBars = GetCommandBars();

CXTPToolBar* pMYTOOLBAR=pCommandBars->GetToolBar(IDR_MAINFRAME);

CXTPControl* pControl=pMYTOOLBAR->GetControls()->GetAt(1);

Can yoy please help me in using setcustomicon function to load an icon(say IDR_NEWICON from the resources)

Thanks

 

Back to Top
Bart View Drop Down
Newbie
Newbie
Avatar

Joined: 17 July 2006
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bart Quote  Post ReplyReply Direct Link To This Post Posted: 07 August 2006 at 7:56am
I'd like to do the same thing actually, replacing a toolbar button image at runtime. Or is this only possible by re-setting the entire toolbar image (used in the creation process?).
Back to Top
venkyhyd View Drop Down
Groupie
Groupie


Joined: 29 June 2006
Location: India
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote venkyhyd Quote  Post ReplyReply Direct Link To This Post Posted: 07 August 2006 at 11:14pm
Hi,
Now i could be able to set the custom icon at runtime using the following code
//to get the handle to a particular button in the toolbar

CXTPCommandBars* pCommandBars = GetCommandBars();

CXTPToolBar* pMYTOOLBAR=pCommandBars->GetToolBar(IDR_MAINFRAME);

int i=pMYTOOLBAR->GetControls()->GetCount();

CXTPControl* pControl=pMYTOOLBAR->GetControls()->GetAt(1);//here i am trying to get handle for the second button

//To get the handle to the icon IDI_ATOM present in the resources
pControl->SetIconId(IDI_ATOM);

HICON hIcon;

hIcon = AfxGetApp()->LoadIcon(IDI_ATOM);

pControl->SetCustomIcon(hIcon);//loading the icon onto the control

Hope this is clear enough
 
Back to Top
Bart View Drop Down
Newbie
Newbie
Avatar

Joined: 17 July 2006
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bart Quote  Post ReplyReply Direct Link To This Post Posted: 08 August 2006 at 1:26am
Exactly what I needed! ([edit]well, unless using CXTPControlPopupColor, see below...)
Thank you for your contribution and help!
Back to Top
Bart View Drop Down
Newbie
Newbie
Avatar

Joined: 17 July 2006
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bart Quote  Post ReplyReply Direct Link To This Post Posted: 08 August 2006 at 5:16am
Hmmm, discovered a few issues though:
 
When using this on CXTPControlPopupColor, it doesnt redraw properly if done from the UpdateUI handler (C++). When you move the mouse over it, the icon changes, but drawing is still wrong, as then the displayed color is no longer visible....
 
I'll thing I'll try to make 2 buttons, only showing the one thats applicable, even though that will make for some odd code and duplicate UI handling . Another option is chaning the overall toolbar's bitmap - if that can be changed runtime, but that has the disadvantage of duplicating the bitmap,
 
SetCustomIcon sounds nice, but in this case not a solution, unless I'm doing something wrong?
 
Back to Top
Oleg View Drop Down
Senior Member
Senior Member


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: 14 August 2006 at 9:09am
Don't use SetCustomIcon for this porpose.
 
Add icon to ImageManager:
 
pCommandBars->GetImageManager()->SetIcon(...);
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.046 seconds.