Print Page | Close Window

Check Boxes with Icons?

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=13736
Printed Date: 06 October 2024 at 12:15pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Check Boxes with Icons?
Posted By: mrmathis
Subject: Check Boxes with Icons?
Date Posted: 19 March 2009 at 11:36am
Is this picture possible?  Check boxes with icons rather than text?  If so, how can I do this?
 


-------------
--Mike



Replies:
Posted By: Oleg
Date Posted: 20 March 2009 at 6:11am
Hello,
 
not supported by deafult :( but you can always create class from CXTPControlCheckBox, override
virtual CSize GetSize(CDC* pDC);
and
virtual void Draw(CDC* pDC);


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: mrmathis
Date Posted: 20 March 2009 at 2:19pm
Thanks for the pointers.  I have it working.  Here's my class:
 

// draw checkboxes with icons instead of text

class SECheckBoxWithIcon : public CXTPControlCheckBox

{

    DECLARE_XTP_CONTROL(SECheckBoxWithIcon)

 

public:

    SECheckBoxWithIcon()

    {

    }

 

    virtual CSize GetSize(CDC* pDC)

    {

        return(CSize(48,22));

    }

 

    virtual void Draw(CDC* pDC)

    {

        // code lifted from CXTPPaintManager::DrawControlToolBarParent

        CXTPRibbonTheme* pTheme = dynamic_cast<CXTPRibbonTheme*>(GetPaintManager());

        BOOL bPressed = GetPressed(), bSelected = GetSelected(), bEnabled = GetEnabled(), bChecked = GetChecked(), bPopuped = GetPopuped();

        CRect rcButton = GetRect();

        CSize szCheckBox = DrawControlCheckBoxMark(pTheme, pDC, rcButton, FALSE, bSelected, bPressed, bChecked, bEnabled);

        CRect rcCheck = CRect(CPoint(rcButton.left + 3, (rcButton.bottom + rcButton.top - szCheckBox.cy)/2), szCheckBox);

        DrawControlCheckBoxMark(pTheme, pDC, rcCheck, TRUE, bSelected, bPressed, bChecked, bEnabled);

 

        // draw the icon

        CPoint pt = CPoint(rcButton.left + szCheckBox.cx + 5, rcButton.top + 2);

        if (CXTPImageManagerIcon* pImage = GetImage())

        {

            pImage->Draw(pDC, pt);

        }

    }

 

    // protected function lifted from Codejock for access here

    CSize /*CXTPRibbonTheme::*/DrawControlCheckBoxMark(CXTPRibbonTheme* pPaintManager, CDC* pDC, CRect rc, BOOL bDraw, BOOL bSelected, BOOL bPressed, BOOL bChecked, BOOL bEnabled)

    {

        if (!bDraw)

            return CSize(13, 13);

 

        CXTPOffice2007Image* pImage = pPaintManager->LoadImage(/*FormatName*/(_T("TOOLBARBUTTONCHECKBOX")));

 

        ASSERT(pImage);

        if (!pImage)

            return CSize(13, 13);

 

        int nState = 0;

        if (!bEnabled)

            nState = 3;

        else if (bSelected && bPressed)

            nState = 2;

        else if (bSelected)

            nState = 1;

 

        if (bChecked == 1)

            nState += 4;

 

        if (bChecked == 2)

            nState += 8;

 

        pImage->DrawImage(pDC, rc, pImage->GetSource(nState, 12), CRect(0, 0, 0, 0));

 

        return CSize(13, 13);

    }

};

 

IMPLEMENT_XTP_CONTROL(SECheckBoxWithIcon, CXTPControlCheckBox)

 



-------------
--Mike


Posted By: Oleg
Date Posted: 23 March 2009 at 1:58am
Thanks for sharing :)

-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net