Click here to Skip to main content
11,433,800 members (58,216 online)
Click here to Skip to main content

WowButtons with the GdiDrawStream function

, 19 Mar 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
A very simple owner-draw button using the GdiDrawStream function.

Sample Image

Introduction

ThemeButton is a CButton derived class. It is a very simple graphical button, and has special bitmaps representing five button states: normal, hot, pressed, disabled, and default. Buttons are drawn as Windows draws it's theme-changeable buttons. Each theme bitmap has a background color and it's transparent.

For Drawing buttons I use the function GdiDrawStream; it's a private function. I'll explain how this function works and what kind of parameters it has. The main thing to use in that function is the GdiDrawStreamStruct structure. I think that function has parameters like: GetObject, handles to the Device Object, size of structure GdiDrawStreamStruct and pointer to the structure.

Using the code

The ThemeButton class has one public function, InitControl. This function has default parameters for Macintosh, Vista, XP and Luna Longhorn styles.

The parameters of the function are as follows:

  1. Bitmap resource identifier.
  2. Bitmap list orientation: vertical or horizontal.
  3. Width in pixels of each image from the bitmap list.
  4. Height in pixels of each image from the bitmap list.
  5. The transparent color of the bitmap.
  6. Font name for the button text.
  7. Button draw style: Mac, Vista, XP or Luna Longhorn style.
BOOL CWowButtonsDlg::OnInitDialog()
{
     CDialog::OnInitDialog();
     // Set the icon for this dialog.
     // The framework does this automatically
     //  when the application's main window is not a dialog
     SetIcon(m_hIcon, TRUE);  // Set big icon
     SetIcon(m_hIcon, FALSE); // Set small icon

     m_vista_but1.InitControl(IDB_VISTA_PUSHBUTTON_BMP,TRUE,21,23,RGB(0,0,0),
         _T("Tahoma"),ThemeButton::VISTA_STYLE);
     m_vista_but2.InitControl(IDB_VISTA_PUSHBUTTON_BMP,TRUE,21,23,RGB(0,0,0),
         _T("Tahoma"),ThemeButton::VISTA_STYLE);
     m_vista_but3.InitControl(IDB_VISTA_PUSHBUTTON_BMP,TRUE,21,23,RGB(0,0,0),
         _T("Tahoma"),ThemeButton::VISTA_STYLE);
     m_vista_but4.InitControl(IDB_VISTA_PUSHBUTTON_BMP,TRUE,21,23,RGB(0,0,0),
         _T("Tahoma"),ThemeButton::VISTA_STYLE);
     m_mac_but1  .InitControl(IDB_MAC_PUSHBUTTON_BMP,  
         TRUE,34,23,RGB(0,0,0),_T("Tahoma"),ThemeButton::MAC_STYLE);
     m_mac_but2  .InitControl(IDB_MAC_PUSHBUTTON_BMP,  
         TRUE,34,23,RGB(0,0,0),_T("Tahoma"),ThemeButton::MAC_STYLE);
     m_mac_but3  .InitControl(IDB_MAC_PUSHBUTTON_BMP,  
         TRUE,34,23,RGB(0,0,0),_T("Tahoma"),ThemeButton::MAC_STYLE);
     m_mac_but4  .InitControl(IDB_MAC_PUSHBUTTON_BMP,  
         
         TRUE,34,23,RGB(0,0,0),_T("Tahoma"),ThemeButton::MAC_STYLE);
     m_xp_but1   .InitControl(IDB_XP_PUSHBUTTON_BMP,    
         TRUE,20,23,RGB(0,0,0),_T("Tahoma"),ThemeButton::XP_STYLE);
     m_xp_but2   .InitControl(IDB_XP_PUSHBUTTON_BMP,   
         TRUE,20,23,RGB(0,0,0),_T("Tahoma"),ThemeButton::XP_STYLE);
     m_xp_but3   .InitControl(IDB_XP_PUSHBUTTON_BMP,   
         TRUE,20,23,RGB(0,0,0),_T("Tahoma"),ThemeButton::XP_STYLE);
     m_xp_but4   .InitControl(IDB_XP_PUSHBUTTON_BMP,    
         TRUE,20,23,RGB(0,0,0),_T("Tahoma"),ThemeButton::XP_STYLE);
     m_luna_but1 .InitControl(IDB_LONGHORN_PUSHBUTTON, 
         TRUE,28,23,RGB(0,0,0),_T("Tahoma"),ThemeButton::LUNA_LONGHORN);
     m_luna_but2 .InitControl(IDB_LONGHORN_PUSHBUTTON, 
         TRUE,28,23,RGB(0,0,0),_T("Tahoma"),ThemeButton::LUNA_LONGHORN);
     m_luna_but3 .InitControl(IDB_LONGHORN_PUSHBUTTON, 
         TRUE,28,23,RGB(0,0,0),_T("Tahoma"),ThemeButton::LUNA_LONGHORN);
     m_luna_but4 .InitControl(IDB_LONGHORN_PUSHBUTTON, 
         TRUE,28,23,RGB(0,0,0),_T("Tahoma"),ThemeButton::LUNA_LONGHORN);

     return TRUE;  // return TRUE  unless you set the focus to a control
}

Update (3.7.2006)

  • Now, the function LoadImage is called with the LR_CREATEDIBSECTION flag.

Update (7.3.2007)

  • I change name of class to ThameButton. create new header file GdiDrawStream.h for drawing function, flags & structure declarations. I Add XP and Luna Longhorn Styles of Button.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Zack_from_georgia
Software Developer GeoMegasoft
Georgia Georgia
Programming is my sickness Smile | :) . I started programming 6 years later. Currently I working in my own company, established with my friend and teacher - Vakhtrang Tsvariani. I prefer to write and research very unusual things and this my habit. Currently I'm working to port CoverFlow in OpenGL and very soon it will be posted Smile | :) .

Comments and Discussions

 
GeneralGreat work!!! only one small thing Pin
yfital25-Mar-09 23:52
memberyfital25-Mar-09 23:52 
Generalexcellent work. Pin
GDA.Hans4-Feb-09 15:49
memberGDA.Hans4-Feb-09 15:49 
GeneralDEFAULT state doesn't work Pin
Joe Smith IX2-Oct-07 22:16
memberJoe Smith IX2-Oct-07 22:16 
GeneralCrashes on Windows 2000 Pin
Joe Smith IX30-Jul-07 7:31
memberJoe Smith IX30-Jul-07 7:31 
GeneralRe: Crashes on Windows 2000 Pin
Zaqro4-Aug-07 20:12
memberZaqro4-Aug-07 20:12 
GeneralRe: Crashes on Windows 2000 Pin
Zaqro4-Aug-07 20:15
memberZaqro4-Aug-07 20:15 
GeneralRe: Crashes on Windows 2000 [modified] Pin
Joe Smith IX2-Oct-07 22:12
memberJoe Smith IX2-Oct-07 22:12 
QuestionHow to apply the theme button to radio button Pin
axe_ara25-Apr-07 21:14
memberaxe_ara25-Apr-07 21:14 
AnswerRe: How to apply the theme button to radio button Pin
Zaqro11-May-07 0:05
memberZaqro11-May-07 0:05 
GeneralMaKaVeLi Pin
tabuka_n25-Mar-07 14:00
membertabuka_n25-Mar-07 14:00 
Generalvano Pin
vanichkas5-Jul-06 23:45
membervanichkas5-Jul-06 23:45 
GeneralPulse Animation Pin
Scott Moss5-Jul-06 2:04
memberScott Moss5-Jul-06 2:04 
GeneralZaqro Pin
Zaqro2-Jul-06 23:41
memberZaqro2-Jul-06 23:41 
GeneralGood work Pin
Jan BugCoder30-Jun-06 17:08
memberJan BugCoder30-Jun-06 17:08 
QuestionWhat is GdiDrawStream ? Pin
Davide Calabro29-Jun-06 2:45
memberDavide Calabro29-Jun-06 2:45 
Sorry, I don't know...

SoftechSoftware
Davide Calabro'
davide_calabro@yahoo.com
http://www.softechsoftware.it
GeneralZqr Pin
Zaqro25-Jun-06 23:58
memberZaqro25-Jun-06 23:58 
GeneralNo Buttons are drawed Pin
Devil for ever25-Jun-06 6:23
memberDevil for ever25-Jun-06 6:23 
GeneralRe: No Buttons are drawed Pin
sudhir mangla26-Jun-06 19:15
membersudhir mangla26-Jun-06 19:15 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150428.2 | Last Updated 19 Mar 2007
Article Copyright 2006 by Zack_from_georgia
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid