|
Question : SetIcon Problem
|
|
I have created a Dialog Bar in my ChildFrame. But I found the program will perform "illegal operation" when I try to "SetICon" for one of the button in the DialogBar.
How can I set an icon for the DialogBar?
My DialogBar is NOT Caption or Sysmenu.
And the error is: _AFXWIN_INLINE HICON CButton::SetIcon(HICON hIcon) it stop here ---> { ASSERT(::IsWindow(m_hWnd)); return (HICON)::SendMessage(m_hWnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); }
I do this with:
CButton * but; but=(CButton *)GetDlgItem(IDC_CTRL_B3); but->SetIcon(AfxGetApp()->LoadIcon(IDR_MAINFRAME));
Thanks
|
|
Answer : SetIcon Problem
|
|
change the style of the button to icon. It can be made in the resource editor. and this code must be in OnInitDialog()
It is better if you make this button IDC_CTRL_B3 to a member variable with the class wizard, and extern theApp, and the code:
BOOL CMyclass::OnInitDialog() { m_mybutton.SetIcon(theApp.LoadIcon(IDI_ICON2)) }
But change the ID from IDR_MAINFRAME to another, because you dont need to load it agan, just write this:
but->SetIcon(m_hIcon);
Good Luck
|
|
|
|