Solved

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

Posted on 2004-03-29
10
1,364 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
  • 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 70 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 

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

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
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 …
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…

839 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