I'm completely new to MFC and have been working on this issue for a couple of days now and can't find any solution that works.
Problem:
I have a dialog class (Modal Dialog Box) with a style defined in an .rc file (Code below) and get the resource id of the icon (int m_icon
is the same as IDR_MAINFRAME
) from another class (OtherClass.rc).
All the text information inside the Dialog Box is set dynamically (Code below) but the same doesn't work with the Icon. The marked Icon in the image below is what I'm trying to set.
The Icon Resource is defined in another .rc file and the LoadImage seems to work as I can set the small Icon in the top left of the window. The only problem is setting the big icon in this image. (Not shown at all, just an empty space)
OtherClass.rc
IDR_MAINFRAME ICON "res\\MyIcon.ico"
Dialog.rc
ABOUTBOX DIALOGEX 0, 0, 285, 77
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "<<Aboutbox>>"
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
ICON ABOUT_ICON, ABOUT_ICON, 11, 10, 21, 20
LTEXT "", IDC_STATIC, 40, 10, 163, 8, SS_NOPREFIX
LTEXT "<<Package Name 1.00>>", ABOUT_NAME, 40, 20, 163, 8, SS_NOPREFIX
LTEXT "<<FileName>>", ABOUT_FILENAME, 40, 30, 163, 8, SS_NOPREFIX
DEFPUSHBUTTON "OK", IDOK, 217, 7, 60, 14, WS_GROUP
END
Dialog.cpp
BOOL AboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Window Title
SetWindowText(L"About " + m_title);
// Set Icon
HICON hIcon = (HICON)LoadImage(GetModuleHandleW(NULL), MAKEINTRESOURCE(m_icon), IMAGE_ICON, 96, 96, LR_DEFAULTCOLOR);
SetIcon(hIcon, TRUE);
SetIcon(hIcon, FALSE);
// Text
SetDlgItemText(ABOUT_NAME, m_name);
SetDlgItemText(ABOUT_FILENAME, m_filename);
return TRUE;
}
What I've tried doing is:
1. GetDlgItem(ABOUT_ICON)->SetIcon(hIcon, TRUE);
2. SendMessage(WM_SETICON, ICON_BIG, (LPARAM)hIcon);
and many more things along those lines but the icon space just remains empty. Neither the LoadImage
nor the GetDlgItem(ABOUT_ICON)
returns a nullptr
(already checked that).