CMacButton, CMacCheckBox '& CMacRadioButton

WEBINAR: On-demand webcast

How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >

ColorLBTest

Environment: VC6, NT4 SP4,

These three classes are my attempt at recreating the standard buttons on the Macintosh. The normal appearance of the buttons duplicates the 3D look of the more recent MacOS versions, but an old-style "flat" look can also be used by setting the button's Flat style in the resource editor.

The following public function is available for CMacButton:

  • void SetBold(BOOL bBold = TRUE)
  • BOOL GetBold()

The following public functions are available for CMacCheckBox and CMacRadioButton:

  • void SetCheck(int nCheck)
  • int GetCheck()

Follow these steps to add a CMacXXX button to a dialog:

  • Add the desired files to your project.
  • Add the appropriate include to the header file of your dialog class.
  • Add checkboxes/radio buttons/standard buttons to your dialog in the resource editor.
  • Use ClassWizard to add a member variable of type CMacButton, CMacCheckBox, or CMacRadioButton for the corresponding controls you just added. If the CMacXXX classes are not in the Variable Type list, choose CButton, and manually change the types in the header file of your dialog class.

To do list:

  • Add support for bitmaps on buttons
  • Add support for horizontal and vertical alignment
  • Add support for push-like check boxes and radio buttons
  • Add support for tri-state check boxes and radio buttons

Downloads

Download demo project - 34 Kb
Download source - 14 Kb


Comments

  • Checkbox is checked when using context sensitive help

    Posted by Legacy on 04/08/2002 12:00am

    Originally posted by: Manfred Peter

    Hello Paul,

    first congratulations to your fine work. We use your controls in our project AlligatorSQL - but we had some problems when using this in combination with context sensitive help.
    When we pressed on a checkbox control the value of the box was changed.

    We changed the following line to avoid this problem

    In the function :

    void CMacButtonsCheckBox::OnLButtonUp(UINT nFlags, CPoint point)


    .
    .
    .

    if (rect.PtInRect(point))
    {
    ==> if(m_bMouseDown) m_nCheck = (m_nCheck == 0 ? 1 : 0);

    // Send notify message to parent window.
    // Added by Eric Hwang.
    .
    .
    .

    Thanks again for your controls

    Manfred Peter
    (Alligator Company)
    http://www.alligatorsql.com


    Reply
  • value variable and UpdateData...

    Posted by Legacy on 02/18/2002 12:00am

    Originally posted by: DV

    When you create a bolean value variable for the control, you set the variable to 1 and call UpdateData(FALSE) the checkbox state are not updated ?!!!

    Reply
  • fix resource leak...

    Posted by Legacy on 11/25/2001 12:00am

    Originally posted by: Hyoungsik Woo

    Thansks your work~!
    
    

    I found two resource leaks at MacButtons.cpp & one resource leak at MacButtonTestDlg.cpp.
    Add line commented by hswoo.

    ### First resource leak at MacButtons.cpp ################
    ICON CMacButton::SetIcon(HICON hIcon)
    {
    ...
    if (hIcon)
    {
    // Get icon dimensions.
    ICONINFO iconInfo;
    ::ZeroMemory(&iconInfo, sizeof(ICONINFO));
    ::GetIconInfo(m_hIcon, &iconInfo);

    m_sizeImage.cx = iconInfo.xHotspot << 1;
    m_sizeImage.cy = iconInfo.yHotspot << 1;

    DeleteObject(iconInfo.hbmColor); // by hswoo.
    DeleteObject(iconInfo.hbmMask); // by hswoo.
    }
    ...
    } // SetIcon

    ### Second resource leak at MacButtons.cpp #############
    void CMacButton::DrawPushLikeButton(CDC *pDC, const CRect &rect, UINT nStyle, UINT nState)
    {
    CBrush brFill;

    if (nStyle & BS_FLAT)
    {
    COLORREF crFill = ::GetSysColor(COLOR_WINDOW);

    HBITMAP hBmp = GetDitherBitmap(pDC, crFill, ~crFill);
    CBitmap *pBmp = (hBmp ? CBitmap::FromHandle(hBmp) : NULL);
    ASSERT(pBmp);

    if (m_bMouseDown)
    brFill.CreatePatternBrush(pBmp);
    else if (m_nCheck)
    brFill.CreateSolidBrush(~crFill);
    else
    brFill.CreateSolidBrush(crFill);

    DeleteObject(hBmp); // by hswoo.
    ...
    }

    ### resource leak at MacButtonTestDlg.cpp ############
    void CMacButtonTestDlg::OnRadioBitmap()
    {
    HBITMAP hBitmap = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1));

    ...
    GetDlgItem(IDC_STATIC_IMAGEEFFECT)->EnableWindow();
    m_radioNone.EnableWindow();
    m_radioRaised.EnableWindow();
    m_radioSunken.EnableWindow();
    DeleteObject(hBitmap); // by hswoo
    }

    Reply
  • Make buttons "Tranparent"

    Posted by Legacy on 05/17/2001 12:00am

    Originally posted by: Bernd

    Hi, i found out how to make the buttons transparent, meaning having the same bgtColor like its parentWnd

    To manage it do the following:

    open the CMacButton (Baseclass) cpp File
    goto CMacButton::DrawButton

    seek for

    COLORREF bgColor = ::GetSysColor( COLOR_BTNFACE ); // COLOR_WINDOW

    modify the line to:

    COLORREF bgColor = GetOwner()->GetDC()->GetBkColor();

    That's it!!

    Tu try our set the backgroundcolor of your dialog to white or what ever. so are the Buttons have the same bgColor like your dialog.
    (Lokk especially for MacCheckbox and Macradiobutton)

    Greetings

    Bernd

    Reply
  • why happens the insuffient resource of a message ??

    Posted by Legacy on 10/27/2000 12:00am

    Originally posted by: kwang young

    i used to click Mac Control button,check button...etc
    
    but the import massege happened sometime.

    the message was the insuffient resource.

    what's problem ??

    please...

    Reply
  • Make this transparent?

    Posted by Legacy on 07/24/2000 12:00am

    Originally posted by: Trey

    Could someone show me how to make the CMacButton transparent?  I'm new to owner drawn controls and any help would be appreciated.
    
    

    Thanks,
    Trey

    Reply
  • flakey CMacMoreButton response to spacebar

    Posted by Legacy on 04/12/2000 12:00am

    Originally posted by: Rick Shide

    Try the spacebar action on the CMacMoreButton controls. The initial space will open the window up, but the arrow doesn't change to point down, subsequent spacebar on an open CMacMoreButton does nothing. If you then click on the CMacMoreButton after it was opened via a spacebar, the arrow then points down. Then hitting a spacebar on the CMacMoreButton when it is pointing down to an open area closes the area but the arrow remains pointing down.

    Nice controls, but you need to do more testing on response to keyboard.

    Reply
  • Legal ramifications

    Posted by Legacy on 02/16/2000 12:00am

    Originally posted by: JRB

    Be careful, I read somewhere that Apple does not allow the Mac look and feel to be used in apps running on other OS's

    Reply
  • tab order & focus on radio

    Posted by Legacy on 12/28/1999 12:00am

    Originally posted by: Rick Shide

    Unlike regular radio controls that are in the tab order, your control allows a tab to unset radio controls in a group. Also, selecting a radio control via the spacebar does not change the selection.

    Reply
  • Bugs & fix

    Posted by Legacy on 12/26/1999 12:00am

    Originally posted by: eric

    Hi,Paul
    
    Your mac style buttons are cool!But i've found some bugs:when you click CMacCheckBox or CMacRadioButton,the parent windows can not receive notify message.
    Here is the fix of the CMacCheckBox:
    ...
    void CMacCheckBox::OnLButtonUp(UINT nFlags, CPoint point)
    {
    ...

    if (rect.PtInRect(point))
    {
    m_bChecked = !m_bChecked;
    //send notify message to parent window
    //added by eric
    CWnd* pParent=GetParent();
    pParent->SendMessage( WM_COMMAND, MAKEWPARAM( GetDlgCtrlID(),BN_CLICKED ), (LPARAM)this->GetSafeHwnd () );
    }
    ...
    }
    Fix CMacRadioButton the same way.

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date