Home > DeveloperSection > Interviews > How to load an Icon on a CButton at Runtime?

Posted on    March-28-2011 8:36 AM

 Visual C++ Visual C++ 
Ratings:
 1 Answer(s)
  1492  View(s)
Rate this:

Dependra Pathak
Dependra Pathak

Total Post:77

Points:385
Posted on    March-28-2011 12:00 AM

CButton *btnsample = (CButton *)GetDlgItem(IDC_BUTTON1);
btnsample->ModifyStyle(0,BS_ICON,SWP_FRAMECHANGED); //change the style of CButton
HICON hIcon = ::LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_ICON)); //load an Icon assuming IDI_ICON is ID of ICON
btnsample->SetIcon(hIcon);

Don't want to miss updates? Please click the below button!

Follow MindStick