?
Solved

Displaying Bitmap on Command Button

Posted on 2000-02-22
9
Medium Priority
?
388 Views
Last Modified: 2013-12-03
Hi all,

How do I display a bitmap on the command button? I would like to know the exact code. Thank you.
0
Comment
Question by:Vriz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 8

Expert Comment

by:VinExpert
ID: 2545409
0
 

Author Comment

by:Vriz
ID: 2545477
Thanks VinExpert, however, I do not really understand what is stated at the links. Could anyone write down the exact code and where to place them?
0
 
LVL 3

Expert Comment

by:akalmani
ID: 2545525
Hi
   U can also try for CBitmapButton for that..
0
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 
LVL 5

Expert Comment

by:Wyn
ID: 2546105
From MS.
class CBMTest1Dlg : public CDialog
{
protected:
      CBitmapButton button1, button2;
public:
      //{{AFX_DATA(CBMTest1Dlg)
            enum { IDD = IDM_TEST_BITMAP_BUTTON1 };
      //}}AFX_DATA
      CBMTest1Dlg();

      BOOL OnInitDialog();
      //{{AFX_MSG(CBMTest1Dlg)
      //}}AFX_MSG
      DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP(CBMTest1Dlg, CDialog)
      //{{AFX_MSG_MAP(CBMTest1Dlg)
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()


CBMTest1Dlg::CBMTest1Dlg()
      : CDialog(CBMTest1Dlg::IDD)
{
      // NOTE: The obsolete MFC V1 CBitmapButton constructor with 3 arguments is
      //  replaced by a call to LoadBitmaps.
      if (!button1.LoadBitmaps(_T("Image1Up"), _T("Image1Down"), _T("Image1Focus")) ||
            !button2.LoadBitmaps(_T("Image2Up"), _T("Image2Down"), _T("Image2Focus")))
      {
            TRACE0("Failed to load bitmaps for buttons\n");
            AfxThrowResourceException();
      }
}

BOOL CBMTest1Dlg::OnInitDialog()
{
      // each dialog control has special bitmaps
      VERIFY(button1.SubclassDlgItem(IDOK, this));
      button1.SizeToContent();
      VERIFY(button2.SubclassDlgItem(IDCANCEL, this));
      button2.SizeToContent();

      return TRUE;
}

/////////////////////////////////////////////////////////////////////////////

Hope helpful
Regards
Wyn
0
 
LVL 4

Accepted Solution

by:
captainkirk earned 80 total points
ID: 2547109
or you can use a regular button and set it's bitmap property and do something like this:

HANDLE hButton   = NULL;
CButton* pButton = NULL;

pButton = (CButton*)GetDlgItem(IDC_YOUR_BUTTON);

hButton = LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_YOUR_IMAGE), IMAGE_BITMAP, nDesiredWidth, nDesiredHeight, LR_DEFAULTCOLOR);

pButton->SendMessage(BM_SETIMAGE, IMAGE_BITMAP, MAKELPARAM(hButton, 0));


0
 

Author Comment

by:Vriz
ID: 2547809
Wyn, I don't really understand how to use your code. But thanks anyway. :)

captainkirk, your code works but can you explain what each step is doing? Thanks a lot.
0
 
LVL 4

Expert Comment

by:captainkirk
ID: 2547843
1) the GetDlgItem() call returns a pointer to the CWnd object corresponding to your button - you pass in the control ID for your button and you get back the pointer, which you then cast to a CButton pointer.

2)LoadImage() just gets the bitmap or icon for you and returns a handle to it. The MAKEINTRESOURCE macro converts your integer bitmap ID to a resource type compatible with Win32 resource-management functions. You pass in the desired width and height of your image in pixels as well.

3) The SendMessage() call tells the button that it needs to draw the bitmap and supplies the handle to the bitmap you just loaded.

hope that helps...
0
 

Author Comment

by:Vriz
ID: 2547965
Thanks for the explaination.
0
 
LVL 4

Expert Comment

by:captainkirk
ID: 2547975
thanks...

0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question