Solved

Need some help with bitmap on button

Posted on 2009-07-14
10
303 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 30

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 30

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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 30

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 47
Include multiple hostnames in this command? 3 51
sumHeights  challenge 17 60
noX challenge 17 76
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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 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

12 Experts available now in Live!

Get 1:1 Help Now