Click to See Complete Forum and Search --> : Using an icon as a button's face


Mr. Rattles
October 3rd, 1999, 05:36 PM
I have a class derived from CDaoRecordView with two buttons on it. I want to use icons I made as the faces of these buttons. In my CMyRecordView::OnInitialUpdate() I have the following code:

CButton *curButton = (CButton*)GetDlgItem(IDC_BUTTON_CV_ADD);
curButton->SetIcon(::LoadIcon(NULL, MAKEINTRESOURCE(IDI_ICON_CV_ADD)));
// curButton->UpdateData();

curButton = (CButton*)GetDlgItem(IDC_BUTTON_CV_SUB);
curButton->SetIcon(::LoadIcon(NULL, MAKEINTRESOURCE(IDI_ICON_CV_SUB)));
// curButton->UpdateData();



But when I run my program I have two blank buttons. How do I get the icons to show up correctly?

Thanks,
Erik

JohnCz
October 3rd, 1999, 07:08 PM
Did you check appropriate style of the button in resource editor? It must be set to Icon.

Mr. Rattles
October 3rd, 1999, 07:53 PM
Yes I did.

JohnCz
October 3rd, 1999, 08:16 PM
Got it. I have overlooked something.
Change:


curButton->SetIcon(::LoadIcon(NULL, MAKEINTRESOURCE(IDI_ICON_CV_ADD)));




To:


curButton->SetIcon(::LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_ICON_CV_ADD)));