Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need some help with bitmap on button

Posted on 2009-07-14
10
Medium Priority
?
320 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

783 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