Yateesh K R
Yateesh K R

Reputation: 27

How do i customize my buttons?

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,)

Upvotes: 0

Views: 449

Answers (1)

Seth Kitchen
Seth Kitchen

Reputation: 1566

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"));

Upvotes: 1

Related Questions