Solved

Displaying Bitmap on Command Button

Posted on 2000-02-22
9
357 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand to include initial dialog with two choices. 9 78
WinWaitActive parameters 12 31
tripleUp challenge 7 79
Way to decrease size of apk file 9 68
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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…

778 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