No aparece la imagen en un boton
Hola, quiero que dos botones que tengo aparezcan con una imagen, pero no logro hacer que aparezca.
¿alguien me puede ayudar?
gracias por adelantado
/////CReprodBar.cpp
CReprodBar::CReprodBar()
{
if (!stop2.LoadBitmaps(IDB_STOP2,IDB_STOP2D,IDB_STOP2) ||
!play2.LoadBitmaps(IDB_PLAY2,IDB_PLAY2D,IDB_PLAY2))
{
TRACE0("Failed to load bitmaps for buttonsn");
AfxThrowResourceException();
}
}
void CReprodBar::InitButtons()
{
VERIFY(stop2.SubclassDlgItem(ID_STOP2, this));
//stop2.SizeToContent(); //sizeToContent se encarga de ajustar el boton al tamaño del
bitmap
VERIFY(play2.SubclassDlgItem(ID_PLAY2, this));
//play2.SizeToContent();
}
/////Reprod.h
...
protected:
CReprodBar m_pDlgBar;
...
/////ReprodBar.h
class CReprodBar : public CDialogBar
{
public:
void InitButtons();
...
protected:
CBitmapButton stop2, play2;
//////Reprod.h
int CReprod::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
if (!m_pDlgBar.Create(this,IDD_REPRODBAR,CBRS_BOTTOM,IDD_REPRODBAR))
{
TRACE0("Failed to create toolbarn");
return -1; // fail to create
}
m_pDlgBar.InitButtons();
...
}
¿alguien me puede ayudar?
gracias por adelantado
/////CReprodBar.cpp
CReprodBar::CReprodBar()
{
if (!stop2.LoadBitmaps(IDB_STOP2,IDB_STOP2D,IDB_STOP2) ||
!play2.LoadBitmaps(IDB_PLAY2,IDB_PLAY2D,IDB_PLAY2))
{
TRACE0("Failed to load bitmaps for buttonsn");
AfxThrowResourceException();
}
}
void CReprodBar::InitButtons()
{
VERIFY(stop2.SubclassDlgItem(ID_STOP2, this));
//stop2.SizeToContent(); //sizeToContent se encarga de ajustar el boton al tamaño del
bitmap
VERIFY(play2.SubclassDlgItem(ID_PLAY2, this));
//play2.SizeToContent();
}
/////Reprod.h
...
protected:
CReprodBar m_pDlgBar;
...
/////ReprodBar.h
class CReprodBar : public CDialogBar
{
public:
void InitButtons();
...
protected:
CBitmapButton stop2, play2;
//////Reprod.h
int CReprod::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
if (!m_pDlgBar.Create(this,IDD_REPRODBAR,CBRS_BOTTOM,IDD_REPRODBAR))
{
TRACE0("Failed to create toolbarn");
return -1; // fail to create
}
m_pDlgBar.InitButtons();
...
}
Hola davinia, creo que no necesitas complicar el codigo, observa como me funciona a mi:
en el archivo .h :
CButton m_Boton;
en el archivo .cpp:
DDX_Control(pDX, IDC_BOTON, m_Boton);
en el evento OnInitDialog:
HBITMAP _CBitmap;
_CBitmap = LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_MI_IMAGEN));
m_Boton->SetBitmap(_CBitmap);
Obviamente para lograr esto, debes modificar el estilo del boton y chequear Bitmap
Abrazos!!
en el archivo .h :
CButton m_Boton;
en el archivo .cpp:
DDX_Control(pDX, IDC_BOTON, m_Boton);
en el evento OnInitDialog:
HBITMAP _CBitmap;
_CBitmap = LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_MI_IMAGEN));
m_Boton->SetBitmap(_CBitmap);
Obviamente para lograr esto, debes modificar el estilo del boton y chequear Bitmap
Abrazos!!
