Button Bitmap
-
Hi everybody, I have a button on the status bar. The following code is included in mainframe::oncreate function: CButton * button = new CButton; button->Create(_T("SMS"), WS_CHILD | WS_VISIBLE | BS_FLAT | BS_BITMAP, CRect(0, 0, 0, 0), &m_wndStatusBar, IDC_BUTTON_STATUS_BAR); button->SetBitmap( ::LoadBitmap( NULL, MAKEINTRESOURCE(IDB_BITMAP5) ) ); I want to place a BItmap in the button, as can be seen. But the above code does not work. The button simply appears empty. button->SetIcon(::LoadIcon(NULL, MAKEINTRESOURCE( IDI_ICON1 )) ); An attempt at loading an icon does not work either. (with the BS_ICON set). Can anyone help? :confused: Thanks Rui
-
Hi everybody, I have a button on the status bar. The following code is included in mainframe::oncreate function: CButton * button = new CButton; button->Create(_T("SMS"), WS_CHILD | WS_VISIBLE | BS_FLAT | BS_BITMAP, CRect(0, 0, 0, 0), &m_wndStatusBar, IDC_BUTTON_STATUS_BAR); button->SetBitmap( ::LoadBitmap( NULL, MAKEINTRESOURCE(IDB_BITMAP5) ) ); I want to place a BItmap in the button, as can be seen. But the above code does not work. The button simply appears empty. button->SetIcon(::LoadIcon(NULL, MAKEINTRESOURCE( IDI_ICON1 )) ); An attempt at loading an icon does not work either. (with the BS_ICON set). Can anyone help? :confused: Thanks Rui
I guess the problem lies in the
CRect(0, 0, 0, 0)
part. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
I guess the problem lies in the
CRect(0, 0, 0, 0)
part. Joaquín M López Muñoz Telefónica, Investigación y DesarrolloHi Joaquín, thanks for the try, but the following works: CButton * button = new CButton; button->Create(_T("SMS"), WS_CHILD | WS_VISIBLE | BS_FLAT | BS_ICON, CRect(0, 0, 0, 0), &m_wndStatusBar, IDC_BUTTON_STATUS_BAR); button->SetIcon( AfxGetApp()->LoadIcon( IDI_ICON1 ) ); I cannot understand why, this works and not the previous code. Why must I use AfxGetApp to LoadIcon() and not just LoadIcon()? Any answers? Rui
-
Hi Joaquín, thanks for the try, but the following works: CButton * button = new CButton; button->Create(_T("SMS"), WS_CHILD | WS_VISIBLE | BS_FLAT | BS_ICON, CRect(0, 0, 0, 0), &m_wndStatusBar, IDC_BUTTON_STATUS_BAR); button->SetIcon( AfxGetApp()->LoadIcon( IDI_ICON1 ) ); I cannot understand why, this works and not the previous code. Why must I use AfxGetApp to LoadIcon() and not just LoadIcon()? Any answers? Rui
Because you need an instance handle in order to find and load the icon. The NULL value you supplied as the first parameter to ::LoadIcon and ::LoadBitmap was insufficient.
-
Because you need an instance handle in order to find and load the icon. The NULL value you supplied as the first parameter to ::LoadIcon and ::LoadBitmap was insufficient.
-
Because you need an instance handle in order to find and load the icon. The NULL value you supplied as the first parameter to ::LoadIcon and ::LoadBitmap was insufficient.
OK, I understand that, what is bothering me is, after reading the MSDN documentation, I don't understand how to get the "Handle to an instance of the module whose executable file contains the icon to be loaded"? Thanks for your time and excuse my ignorance. Cheers Rui
-
OK, I understand that, what is bothering me is, after reading the MSDN documentation, I don't understand how to get the "Handle to an instance of the module whose executable file contains the icon to be loaded"? Thanks for your time and excuse my ignorance. Cheers Rui
The hInstance parameter is passed by Windows to WinMain when an application is started. Use AfxGetInstanceHandle() to get it. If that does not answer you, I don't understand your question. Try rephrasing it and posting again and perhaps someone can help.