0

I'm new to MFC, How can I customize buttons in such a way that

  1. It should be painted in background.
  2. Should be able to place a image on painted area and
  3. Should add text on painted area.

After browsing the internet I got to know that we need to override DrawItem method once the button is created with BS_OWNERDRAW style, How can i override DrawItem Method?

( MFC application using SDI,)

  • You override `DrawItem` in the same way you override any other class member in C++. I'm not sure, whether this is the question you meant to ask. – IInspectable Sep 10 '15 at 14:59

1 Answers1

1

In Global Variable:

CButton button;

In DoDataExchange:

DDX_Control(pDX, IDC_BUTTON, button);

where IDC_button is declared on your dialog resource and pDX is your CDataExchange

Where you want to add image:

button.SetBitmap((HBITMAP)LoadImage(AfxGetApp()->m_hInstance,
        MAKEINTRESOURCE(IDB_BITMAP1),
        IMAGE_BITMAP, 16, 16, LR_COLOR));

where m_hInstance is your CWinApp, IDB_BITMAP1 is a resource picture.

For text:

  button.SetWindowTextW(_T("TEXT"));
Seth Kitchen
  • 1,526
  • 19
  • 53