Solved

Need some help with bitmap on button

Posted on 2009-07-14
10
308 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.

820 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