?
Solved

How to place a .bmp over a button

Posted on 1998-02-17
9
Medium Priority
?
416 Views
Last Modified: 2011-04-14
Addition to my question from 02-12-98 and galkins answer:

He told me to call CButton::SetBitmap to place a .bmp over a button.

(I need only one bitmap for the button, so this should be the right function)
This is what I tried in my C++ code:

BOOL CDiaKamera::Create()
{
CButton* pButton;
BOOL ret;

ret = CDialog::Create(CDiaKamera::IDD);
pButton = (CButton*) GetDlgItem(IDC_Home);
pButton->SetBitmap((HBITMAP) GetDlgItem(IDB_HOME));
return ret;
}
- IDC_Home is my button ID
- IDB_HOME is my bitmap I want to place over this button

...nothing happens...no bitmap visible...just an empty button.

Do I have to "redraw" the dialog to update the buttons ?
If yes, how can I do this ?

What's wrong here ?

-Stavi-
0
Comment
Question by:mitrakis
[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
  • 5
  • 3
9 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 120 total points
ID: 1182404
Answer coming.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1182405
The problem is GetDlgItem() returns a handle to a control in the dialog.  You use it correctly the first time, but the second time
in the line

pButton->SetBitmap((HBITMAP) GetDlgItem(IDB_HOME));

you use it to get a bitmap?  That's not what it does.

If the bitmap is stored in your resources, you can use LoadBitMap() to get it.  There are other ways of getting bitmaps (LoadImage(), LoadIcon(), for example) but this is probably the one you want.
0
 
LVL 32

Expert Comment

by:jhance
ID: 1182406
It's hard to complete with "Answer Coming" answers...
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 32

Expert Comment

by:jhance
ID: 1182407
jhance,

You have no right to complain, you "stole" one from me just a day  or two ago.  Besides, I recommend you answer the same way.  Don't waste time answering when someone else might be...  
0
 
LVL 22

Expert Comment

by:nietod
ID: 1182408
Thanks for your efforts !

Unfortunately, I don't know who's right of you... =;-)

I'll grade your answer...tomorrow...I have to test this out in my office.

Thanks again.

Best regards

-Stavi-
0
 
LVL 3

Author Comment

by:mitrakis
ID: 1182409
Our answers are the same.  both of us are suggesting that you use LoadBitmap() to get the bitmap.  jhance was suggesting that you use a static MFC bitmap object.  I don't think that is really necessary. Without knowing more about your code I cannot judge whethor or not that is a good idea, but the basic idea of both of our suggestions is the same.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1182410
I wouldn't normally use a static in the OnInitDialog but rather would just a it as a data member to the CDialog class.  I put it here for clarity.  The end result is the same.  BTW, the object you pass to the SetBitmap() member function MUST BE VALID at any time when the button might get repainted.  If you try my example without the static, you will see that it doesn't work.  Even though the HBITMAP was valid when SetBitmap() was called, it isn't valid later when the button actually get drawn.  I'm sure that diving down into the internals of MFC would yield an explanation but my assumption is that SetBitmap doesn't store the bitmap locally but rather assumes you are providing an HBITMAP that is valid for the life of the button.
0
 
LVL 32

Expert Comment

by:jhance
ID: 1182411
Is it possible that what you are talking about is that if you declare a local CBitmap (not static) the bitmap is disposed of when the CBitmap leaves scope and thus the button is not drawn correctly?  Using a static CBitmap will fix this, but has potentials for problems (with a few exceptions, static causes more problems than it solves).  If you drop the CBitMap completely and just LoadBitmap and pass the handle to SetBitmap().  I don't know much MFC, but I beleive you don't have to worry about freeing the bitmap as it will be freed when the button is destroyed, thus a CBitmap is not necessary and actually inappropriate as it will cause the bitmap to be deleted twice.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1182412
It works !
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
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