Solved

Need some help with bitmap on button

Posted on 2009-07-14
10
311 Views
Last Modified: 2013-11-20
Hello,
I would like to change a bitmap on a button when the user clicks on the button.
So when the user clicks on my button I would like to set a disable picture to the button and also want to disable the button.
But I will only see a dark button with no picture on it.
Please help.
500 points.
Best regards,
Thomas

In OnIntitDialog()
                    m_bitmap.LoadBitmap(IDB_BITMAP_BUTTON_1);
	m_button.SetBitmap(m_bitmap);
                 (this works, I see the bitmap on my button)
                  .
                  .
                  .
                  .
                  (after the user clicks on this button, I would like to disable the button, and set a new bitmap on it)
                    m_bitmap.LoadBitmap(IDB_BITMAP_BUTTON_DISABLE);
	m_button.SetBitmap(m_bitmap);
 
               GetDlgItem(IDC_BUTTON1)->EnableWindow(false);//  disable

Open in new window

0
Comment
Question by:tsp2002
[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
  • 2
10 Comments
 
LVL 19

Expert Comment

by:alb66
ID: 24848448
You can load the bitmap for the enbled and the disable state with only one instructions using LoadBitmaps() instead of SetBitmap():

http://msdn.microsoft.com/en-us/library/6y6acs49.aspx
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 24848466
Hi tsp2002,

is it a CButton or a CBitmapButton? LoadBitmaps() only works for CBitmapButton.

I tested your code and it works fine for me ...

BTW: How does the button look if you don't disable it? A bitmap shown on a button is somehow 'grayed out' when the button is disabled, so the colors won't be the same as in the bitmap.

ZOPPO
0
 

Author Comment

by:tsp2002
ID: 24848482
how can I do this....the link will not work.
0
Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

 
LVL 31

Expert Comment

by:Zoppo
ID: 24848484
> button is somehow 'grayed out'
better said: Any color except white will become dark grey.
0
 
LVL 19

Expert Comment

by:alb66
ID: 24848500
>>>>> the link will not work

As Zoppo said, I tought about CBitmapButton...
0
 

Author Comment

by:tsp2002
ID: 24848501
it is a normal button....with in property bitmap true
0
 

Author Comment

by:tsp2002
ID: 24848509
> button is somehow 'grayed out'
better said: Any color except white will become dark grey.
 
yes it looks like there is something on the button....dark gray...but not my disable picture.
0
 

Author Comment

by:tsp2002
ID: 24848525
please see hardcopy
aaaa.BMP
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 500 total points
ID: 24848591
ok, then I guess it comes from the internal gray-scaling of the bitmap ...

I think you have two possibilities:

1. Don't disable the button - in this case you'd have to keep track of the button's state and handle all mouse/keaboard relevant messages.

2. Disable the button but somehow find a way it's drawn as enabled.


The 1. might be quite some effort, so I just tried to find a solution for 2. - here's one:

- Derive a new class from CButton, i.e. CMyButton
- Include the 'MyButton.h' in your dialog's header and declare 'm_button' as a CMyButton.
- Implement a WM_PAINT message handler for CMyButton like this:

> void CMyButton::OnPaint()
> {
>      DWORD dwStyle = GetStyle();
>      ModifyStyle( WS_DISABLED, 0 );
>      Default();
>      ModifyStyle( 0, dwStyle );
> }

This works fine in my test application ...

Hope that helps,

ZOPPO
0
 

Author Closing Comment

by:tsp2002
ID: 31603215
thank you...that works great...keep up the good works.... best regards, Thomas
0

Featured Post

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

630 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