Click here to Skip to main content
Click here to Skip to main content

Davide Calabro's CButtonST class port to WTL

By , 26 Jun 2001
 

CButtonST

CButtonST

CButtonST

CButtonST

Introduction

Now you can use Davide Calabro's excellent CButtonSt class in your ATL/WTL projects. The Class is still called CButtonSt and it retains a majority of the original code. Just follow these simple instructions:

  1. Create a WTL Project
  2. Design the dialog and add the button controls
  3. Add the ButtonST.h header file to your project
  4. Assign a CButtonSt to each button.
  5. In OnInitDialog,
    • Subclass each member controls (CButtonST) to each ID using the SubclassWindow method.
    • uses the CButtonSt methods to change the appearance of the control.
  6. In your dialog, don't forget to add the macro REFLECT_NOTIFICATIONS which allows the buttons to get messages like WM_DRAWITEM.
  
class MyDialog : public CDialogImpl<MyDialog>
{
  BEGIN_MSG_MAP(MyDialog)
    ...
    MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
    REFLECT_NOTIFICATIONS()
  END_MSG_MAP()
  ...
  LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, 
    LPARAM /*lParam*/, BOOL& /*bHandled*/);
  ...
  CButtonST m_btn;
  ...
};

LRESULT MyDialog::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/,
  LPARAM /*lParam*/, BOOL& /*bHandled*/) 
{
  ...
  m_btn.SubclassWindow(GetDlgItem(IDC_BTN));
  m_btn.SetIcon(IDI_EOAPP);
  m_btn.SetFlat(false);
  ...
}

See Davide Calabro's original CButtonSt article for more details.

Latest Updates

  • 26 June 2001
    • Updated to Davide Calabro's version 3.2
    • Added support for defining the icons from an image list
    • Added support for creating dynamically the buttons
  • 14 June 2001 - Fixed a bug in the autorepeat feature

Serge Thank you.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Serge Weinstock
Web Developer
United Kingdom United Kingdom
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralTHANK YOU!memberlzhishen17 Sep '10 - 20:28 
Wink | ;)
GeneralSelectObject(pbmpOldBk) Bugmemberfreesindbad17 Feb '10 - 20:59 
http://www.codeguru.com/forum/archive/index.php/t-250506.html[^]
GeneralThank you !memberflg61873024 Nov '09 - 0:51 
A good thing!Very perfect!Thank you !
Generalloading in dialog barmemberanubis_ex21 Jun '05 - 10:37 
cannot load images over dialog bar(CDialogBar control)? why?
 
and if yes..how i could make this?

GeneralSome bugs.membert2di4u24 Nov '04 - 22:45 
ButtonST(452) rpImage.top += ((rpImage.Height() - dwHeight)/2);
 
When the image's size is larger than the button.
For example: if rpImage.Height() = 20 and dwHeight - 21
then rpImage.top = 0x7fffffff. Draw in wrong place!!!
 
and some others work in this way.
Fix advice: rpImage.top += ((rpImage.Height()/2 - dwHeight/2));
 

any way, thanks for your work.
GeneralAnother resource leak when using iconssussMarkus Steinlein11 Aug '04 - 0:05 
I found another resource leak in the code when using Icons. Icons are loaded from the projects resources using the LoadImage() function. MSDN states that Icons loaded in this way have to be deleted using DestroyIcon(). The FreeResources() method of the CButtonST class uses DeleteObject() instead which leads to a resource leak.
 
Correct the FreeResources() method to the following to avoid this resource leak:
 
[...]
if (m_csIcons[0].hIcon != 0) { ::DestroyIcon(m_csIcons[0].hIcon); }
if (m_csIcons[1].hIcon != 0) { ::DestroyIcon(m_csIcons[1].hIcon); }
[...]
 
yours,
Markus
GeneralPort STButton 3.9!memberRodger12 May '03 - 5:23 
Hey,
 
Any plans to port over the latest ButtonST version?
GeneralBug, resource leaksussJohn Gijs23 Apr '03 - 0:03 
I made a rotating button dispaying different bitmaps.
A resource leak was the result.
Analysis learns that the ::GetIconInfo() function
allocates 2 bitmaps that are not deleted by CButtonSt class
(See function CButtonST::SetIcon())
use DeleteObject to correct the error.
(The class was used in an application that controls a 4.000.000 Euro electron beam texturing machine for the largest cold roll mill in Arcelor.)
 
John.Gijs@Sidmar.arcelor.com
Generalm_bIsFlat - classic appearance and cool behaviormemberPablo Aliskevicius23 Apr '02 - 3:57 
Great stuff!
 
I'm using it in a 'conventional' looking application - only when the mouse hovers on a button, the text color changes (to light blue). The understatement is, according to a few users, quite cute...
 
In order to keep the classic look, the only way I found was setting m_bIsFlat to false - by using SetFlat(false), of course. But in OnMouseMove(), I was returning before changing the text color. Commenting out the line "if (!m_bIsFlat) { return 0; };" made the buttons work the way I wanted, but I don't feel comfortable with it.
 
Is there any other way to do this?
 
Thanks a lot,
 
Pablo.
GeneralKeyboard InputmemberRob Melchione25 Jan '02 - 8:12 
Hey, Does this class support keyboard input(TAB, SPACE, ENTER, etc...)??? If it does, I must be doing something wrong. I assume that it is not working as a result of the messages being reflected to the button, but I could be wrong.
 
Any help would be apprecitated.
 
Rob Melchione

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 27 Jun 2001
Article Copyright 2001 by Serge Weinstock
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid