---
title: "How to load an Icon on a CButton at Runtime?"  
description: "How to load an Icon on a CButton at Runtime?"  
author: "Dependra Pathak"  
published: 2011-03-28  
updated: 2020-09-18  
canonical: https://www.mindstick.com/interview/669/how-to-load-an-icon-on-a-cbutton-at-runtime  
category: "visual c++"  
tags: ["visual c++"]  
reading_time: 1 minute  

---

# How to load an Icon on a CButton at Runtime?

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);

## Answers

### Answer by Dependra Pathak

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);


---

Original Source: https://www.mindstick.com/interview/669/how-to-load-an-icon-on-a-cbutton-at-runtime

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
