Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to put a bitmap image on a button in Visual C++

Posted on 2004-03-29
10
Medium Priority
?
1,654 Views
Last Modified: 2013-12-03
Hi Friends

  I just need the complete code,  to put a bitmap image on a Button. Button is located in standard dialog. I need this to be done on Visual C++

Thanks
venura
0
Comment
Question by:venuraib
[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
  • 5
10 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 10702513
Use CBitmapButton class. Check out MFC sample CTRLTEST.
0
 

Author Comment

by:venuraib
ID: 10702533
Hi AlexFM

I just want to do it using CButton Class, is it possible to do it throug CButton, Because When you add a Button Control normally it creates from CButton

thanks AlexFM
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 210 total points
ID: 10702630
Create CButton member using MFC Wizard and manually change it's type to CBitmapButton. Set it's Owner Draw style to TRUE.
To set bitmap for it, use one of two ways:
1) Add line to OnInitDlalog:
m_button.LoadBitmaps(IDB_BITMAP1);

or:
2) Use CBitmapButton::AutoLoad function as described in CBitmapButton Class MSDN topic:

To include a bitmap-button control in a dialog box

Create one to four bitmap images for the button.
Create a dialog template with an owner-draw button positioned where you want the bitmap button. The size of the button in the template does not matter.
Set the button's caption to a value such as "MYIMAGE" and define a symbol for the button such as IDC_MYIMAGE.
In your application's resource script, give each of the images created for the button an ID constructed by appending one of the letters "U," "D," "F," or "X" (for up, down, focused, and disabled) to the string used for the button caption in step 3. For the button caption "MYIMAGE," for example, the IDs would be "MYIMAGEU," "MYIMAGED," "MYIMAGEF," and "MYIMAGEX." You must specify the ID of your bitmaps within double quotes. Otherwise the resource editor will assign an integer to the resource and MFC will fail when loading the image.
In your application's dialog class (derived from CDialog), add a CBitmapButton member object.
In the CDialog object's OnInitDialog routine, call the CBitmapButton object's AutoLoad function, using as parameters the button's control ID and the CDialog object's this pointer.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:venuraib
ID: 10702768
Hi AlexFM

I am realy thank full to you for your effort to solve my problem. Half away it solve, thanks lot but It want have that button press and release effects. I think
you have describe it bellow I coudn't get it right help. If you don't mind please help me further to co,me out this problem.

Thanks a Lot
from
venura
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 10702792
Press and release effects are done using different bitmaps: U," "D," "F," or "X" for up, down, focused, and disabled states.
0
 

Author Comment

by:venuraib
ID: 10702832
yes my friend

Problem is I am not clear with that usage of U, D, F and X. Can you explain me again, I know your help is more than worth my 70 points. Just help me to get out of this problem

thank you lot
venura
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 10702844
U bitmap is button normal state. D bitmap is for pressed state. They may be completely different, but usually pressed state looks like normal, but with high brightness. F butmap usually contains focus rectangle, X bitmap is dimmed.
0
 

Author Comment

by:venuraib
ID: 10702870
Yes friend

How to Map these images to the button

thanks lot
venura
0
 

Author Comment

by:venuraib
ID: 10702916
Hi my Friend AlexFM

I am Actually appriciating your corperation towards my problem. So If you have enough time, just help me in future. I have to leave now
So Thank for you valuable effort given towards me. I'll accept your answer as the solution, but still last part is not clear. If don't mind
help me. Your help is more than this points.

Thank you
from
venura
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 10703037
To map these images to the button use LoadBitmaps with 4 arguments or AutoLoad function - this is described in my post.
0

Featured Post

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.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Loops Section Overview

610 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