Menu

How to ownerdraw radio button?

Help
kite
2020-12-09
2021-01-16
  • kite

    kite - 2020-12-09

    I try to owner draw radio button appearance. But I cann't get it.
    I tested in DialogResizing demo:
    1. Modify mydialog:: OnInitDialog to add
    m_radioA.SetButtonStyle(BS_AUTORADIOBUTTON | BS_OWNERDRAW, TRUE);
    2. Override OnMessageReflect to handle DrawItem message
    case WM_DRAWITEM:
    {
    LPDRAWITEMSTRUCT pDIS = (LPDRAWITEMSTRUCT)lparam;
    CRect rc = pDIS->rcItem;
    CDC dc = pDIS->hDC;
    dc.SolidFill(RGB(32, 32, 32), rc);
    }
    return TRUE;

    But, the drawitem is not called, and radiobutton no any visual appearance, but can be click as normal radio button.
    
     
  • kite

    kite - 2020-12-11

    Solved.

     
  • David

    David - 2020-12-12

    Hi Kite,

    I'm pleased to see you were able to resolve this one.
    As you've noticed, the WM_DRAWITEM message needs to be handled in the dialog's DialogProc.

    Best regards,
    David

     
    • Erik Don

      Erik Don - 2021-01-16

      Hi. David How can we make all owner draw code in our inhired control class that we can re-use in different project?

       
  • Erik Don

    Erik Don - 2021-01-15

    Hi, David,
    Can we handle the WM_DRAWITEM in our customized control class, and how?
    Thank you!

     
  • David

    David - 2021-01-16

    Hi Erik,

    Yes we can handle the WM_DRAWITEM in our customized classes. The DDXDemo sample provides a practical demonstration of how to handle the WM_DRAWITEM in CView::DialogProc. This sample uses owner draw to render the status button and push button.

    Best regards,
    David

     
    • Erik Don

      Erik Don - 2021-01-16

      Great,I will learn it , Thank you!

       

Log in to post a comment.