Solved

Displaying Bitmap on Command Button

Posted on 2000-02-22
9
364 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
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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 20 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do I customize my Standard Colors in PowerPoint 2010? 6 55
Login Script to Copy Folders 12 42
sumDigits challenge 9 170
dog bark java program 15 111
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
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…

830 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