Solved

Displaying Bitmap on Command Button

Posted on 2000-02-22
9
338 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
Comment Utility
0
 

Author Comment

by:Vriz
Comment Utility
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
Comment Utility
Hi
   U can also try for CBitmapButton for that..
0
 
LVL 5

Expert Comment

by:Wyn
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 4

Accepted Solution

by:
captainkirk earned 20 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for the explaination.
0
 
LVL 4

Expert Comment

by:captainkirk
Comment Utility
thanks...

0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Universal fonts 2 138
Replacement selected text 2 47
Gotham fonts and Office 2013 6 50
no14 challenge 14 56
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now