?
Solved

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

Posted on 2004-03-29
10
Medium Priority
?
1,559 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
A short article about problems I had with the new location API and permissions in Marshmallow
Progress
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

777 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