说明:IDI_ICON1是ICON ID ,IDC_BUTTON1是BUTTON ID
环境:VS2005 MFC
解决方案:
HICON hIcon;
hIcon=AfxGetApp()->LoadIcon(IDI_ICON1);
GetDlgItem(IDC_BUTTON1)->ModifyStyle(0, BS_ICON, 0);
GetDlgItem(IDC_BUTTON1)->SendMessage(BM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)hIcon );
错误的方案:
m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON1);
GetDlgItem(IDC_BUTTON1)->SetIcon(m_hIcon, TRUE);
GetDlgItem(IDC_BUTTON1)->SetIcon(LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON1)),TRUE);
时间: 2024-10-05 03:23:28