-2

I am using VC6 and the compiler is Win32 (for my university project). I have got several buttons on my dialog and I want to add different icons corresponding to different buttons.

I tried this code, as my button called IDC_BTN_AUTOSET and my icon is called IDR_MAINFRAME. This code gives no error, but it does not show me anything even if I change the button property to icon.

HICON h_Ico = (HICON) LoadImage( AfxGetResourceHandle(),"IDR_MAINFRAME", IMAGE_ICON, 32, 32,LR_LOADFROMFILE );
CButton *Button=(CButton*)GetDlgItem(IDC_BTN_AUTOSET);
Button->SetIcon( h_Ico );
SetIcon(h_Ico, TRUE);   
SetIcon(h_Ico, FALSE);
Adrian W
  • 4,563
  • 11
  • 38
  • 52
  • 1
    Why do you use VC6 (of the Windows NT era) for a university project, when you have VS2017 for free? – Amit G. Aug 21 '18 at 14:56

1 Answers1

0

This works fine, Make sure you set IDB_BITMAP1 as a CButton in your header file.

BOOL CVCDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    CButton* pBtn= (CButton*)GetDlgItem(IDC_BTN_AUTOSET);

   pBtn->ModifyStyle( 0, BS_BITMAP  );

   HBITMAP hIcn= (HBITMAP)LoadImage(
        AfxGetApp()->m_hInstance,
  MAKEINTRESOURCE(IDB_BITMAP1),
        IMAGE_BITMAP,
        0,0, // use actual size
        LR_DEFAULTCOLOR
    );

    pBtn->SetBitmap( hIcn );