Toll Free: (877) 723-1442 U.S. and Canada
Support
ActiveX / COM
Visual C++ / MFC
Customer Spotlight
Corporate Partners
Contact Sales

Call center available M-F 9:00 - 6:00 US Eastern Time.

U.S. and Canada
(877) 723-1442

International
(517) 625-5729

Email

Create a custom theme for your application

Author: Kirk Stowell
Posted: November 16, 2004
Environment: Visual C++ MFC

You can create a custom theme for your application by deriving a class from any of the theme classes available in the toolkit.

Create a double gripper theme similar to Visual Studio 6.0.

  1. Create a new class derived from one of the predefined themes found in the toolkit. We are going to use CXTPDefaultTheme, however you can use any of the following theme classes:
  2. - CXTPDefaultTheme to inherit Office 2000 theme
    - CXTPOfficeTheme to inherit Office XP theme
    - CXTPOffice2003Theme to inherit Office 2003 theme
    - CXTPNativeXPTheme to inherit Native XP theme

     class CDoubleGripperTheme : public CXTPDefaultTheme

     {

     

     };



  3. Override the DrawCommandBarGripper of CXTPDefaultTheme base class (See XTPPaintManager.h).  This will allow us to add our own custom look for drawing the command bar grippers


  4.  class CDoubleGripperTheme : public CXTPDefaultTheme

     {

         virtual CSize DrawCommandBarGripper(

             CDC* pDC, CXTPCommandBar* pBar, BOOL bDraw);

     };

     

     

     [...]

     

     

     // DrawCommandBarGripper function.

     // if bDraw if FALSE must return gripper size.

     // if bDraw is TRUE must draw gripper. 

     CSize CDoubleGripperTheme::DrawCommandBarGripper(CDC* pDC,

          CXTPCommandBar* pBar, BOOL bDraw)

     {

         // If Toolbar is vertical docked

         if (pBar->GetPosition() == xtpBarRight ||

             pBar->GetPosition() == xtpBarLeft)

         {

             if (bDraw)

             {

                 CXTPClientRect rc(pBar);

                 Draw3dRect(pDC, CRect(3, 3, rc.right - 3, 6),

                     COLOR_BTNHILIGHT, COLOR_3DSHADOW);

                 Draw3dRect(pDC, CRect(3, 7, rc.right - 3, 10),

                     COLOR_BTNHILIGHT, COLOR_3DSHADOW);

             }

             return CSize(0, 10);

         }

         // if Toolbar is horizontal  docked

         else

             if (pBar->GetPosition() == xtpBarTop ||

                 pBar->GetPosition() == xtpBarBottom)

             {

                CXTPClientRect rc(pBar);

                if (bDraw)

                {

                    Draw3dRect(pDC, CRect(3, 3, 6, rc.bottom - 3),

                        COLOR_BTNHILIGHT, COLOR_3DSHADOW);

                    Draw3dRect(pDC, CRect(7, 3, 10, rc.bottom - 3),

                        COLOR_BTNHILIGHT, COLOR_3DSHADOW);

                }

                 return CSize(10, 0);

             }

             else return

        CXTPDefaultTheme::DrawCommandBarGripper(pDC, pBar, bDraw);

     }



  5. Call CXTPPaintManager::SetCustomTheme from CMainFrame's OnCreate method to use the theme we just created


  6.  int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)

     {

         ...

     

             // Use our own theme for drawing command bar grippers.

             CXTPPaintManager::SetCustomTheme(new

             CDoubleGripperTheme());

     

         return 0;

     }

Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Other products and/or company names may be trademarks or registered trademarks of their respective owners.