Solved

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

Posted on 2004-03-29
10
1,324 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

776 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