Solved

Need some help with bitmap on button

Posted on 2009-07-14
10
306 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now