Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Putting a bitmap on the button, here is the code for the button...

Status
Not open for further replies.

dringer

MIS
Jul 16, 2003
81
0
0
US
I want to put a bitmap on this button I have created, here is the code for the button, anybody any ideas???

// button2.cpp
#include <afxwin.h>
#define IDB_BUTTON 100
#define IDT_TIMER1 200

// Declare the application class
class CButtonApp : public CWinApp
{
public:
virtual BOOL InitInstance();
};
// Create an instance of the application class
CButtonApp ButtonApp;

// Declare the main window class
class CButtonWindow : public CFrameWnd
{
CButton *button;
CFont *font;

public:
CButtonWindow();
afx_msg void HandleButton();
afx_msg void OnSize(UINT, int, int); // USED FOR RESIZING
afx_msg void OnTimer(UINT);
DECLARE_MESSAGE_MAP()

};



// The message handler function
void CButtonWindow::HandleButton()
{
MessageBeep(-1);
}





// A message handler function
void CButtonWindow::OnSize(UINT nType, int cx,
int cy)
{
CRect r;
GetClientRect(&r);
r.InflateRect(-20,-20);
button->MoveWindow(r);
}


// A message handler function
void CButtonWindow::OnTimer(UINT id)
{
MessageBeep(-1);
}



// The message map
BEGIN_MESSAGE_MAP(CButtonWindow, CFrameWnd)
ON_BN_CLICKED(IDB_BUTTON, HandleButton)
ON_WM_SIZE() //RESIZE
ON_WM_TIMER() // beeb timer
END_MESSAGE_MAP()

// The InitInstance function is called once
// when the application first executes
BOOL CButtonApp::InitInstance()
{
m_pMainWnd = new CButtonWindow();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}


// The constructor for the window class
CButtonWindow::CButtonWindow()
{
CRect r;
// Create the window itself
Create(NULL,
&quot;CButton Tests&quot;,
WS_OVERLAPPEDWINDOW,
CRect(0,0,200,200));

// Set up the timer
SetTimer(IDT_TIMER1, 1000, NULL); // 1000 ms.

// Get the size of the client rectangle
GetClientRect(&r);
r.InflateRect(-20,-20);
// Create a button
button = new CButton();
button->Create(&quot;Push me&quot;,
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
r,
this,
IDB_BUTTON);



// Create a new 80 point TIMES NEW ROMAN
font = new CFont;
font->CreateFont(80,0,0,0,700,0,0,0,
ANSI_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH|FF_DONTCARE,
&quot;TIMES NEW ROMAN&quot;);
// Cause the label to use the new font
button->SetFont(font);
}
 
I don't have much experience with MFC but sure I can tell you SDK way
1.I loaded bitmap as IDB_YELLOW resource, from a file which has 16 by 16 bitmap.
2.Load Bitmap 16 by 16 using something like this
HBITMAP hBitmap;
hBitmap = LoadBitmap(hInst,MAKEINTRESOURCE(IDB_YELLOW))

3.Load bitmap on button using message BM_SETIMAGE, like this
SendDlgItemMessage(hDlg,IDC_YELLOW,BM_SETIMAGE,(WPARAM) IMAGE_BITMAP,(LPARAM) hBitmap)

Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top