Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Button no longer looks like a button...

Posted on 2000-03-16
9
Medium Priority
?
308 Views
Last Modified: 2013-12-03
Hi,

I am trying to customise the background colour of the buttons on my Win32 dialog (e.g. 1 red and 1 yellow). I have been investigating WM_CTLCOLORBTN and it only works with owner drawn buttons.

I have a MESSAGE_HANDLER() for the WM_CTLCOLORBTN and it is called before every button is drawn and if it is an owner drawn button the button will change its background colour to the HBRUSH that the message returns.

The only problem is, when the dialog displays, the button just looks like a flat rectangle. It is no longer raised like a button and I have lost the text on the button face.

Can anyone help me with this.. I have searched the archives and can't figure out why this has happened.. Do I have to supply the button images myself?!?!?!

Thanks in advance..

Emma
0
Comment
Question by:middlel
[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
  • 4
  • 4
9 Comments
 
LVL 5

Expert Comment

by:vachooho
ID: 2624758
you must overwrite OnDrawItem() and draw your button itself.
It is ownerdrawn!
0
 
LVL 15

Accepted Solution

by:
NickRepin earned 236 total points
ID: 2625819
MS SDK says:

Buttons with the BS_PUSHBUTTON, BS_DEFPUSHBUTTON, or BS_PUSHLIKE styles do not use the returned brush. Buttons with these styles are always drawn with the default system colors. Drawing push buttons requires several different brushes-face, highlight and shadow-but the WM_CTLCOLORBTN message allows only one brush to be returned. To provide a custom appearance for push buttons, use an owner-drawn button.
0
 

Author Comment

by:middlel
ID: 2627253
My button is an owner-drawn button.. So I have to handle the OnDraw message and provide 2 bitmaps.. One for the 3D look and one for how it looks when it has been pressed...? How do I make sure that the button is displayed properly when it is clicked and not clicked?

Would I have to send some kind of draw message when the user clicks..?
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 15

Expert Comment

by:NickRepin
ID: 2627346
In the WM_DRAWITEM handler, you have to check DRAWITEMSTRUCT.itemState member and draw the button accordingly.

ODS_DISABLED - button is disabled
(if your button can be disabled)

ODS_FOCUS - draw the focus rectangle (if you need it)

ODS_SELECTED - the button is pressed.
0
 

Author Comment

by:middlel
ID: 2627443
I have added a WM_DRAWITEM message for the dialog and it necer gets called.. I was hoping that the message would be on the parent control and it would just tell me which button the message was for.. Do I need to specifically handle the WM_DRAWITEM for each control..?

Also how do I tell the dialog to draw the button with my selected bitmap or default bitmap etc...

I was originally just coloring the button in with the following code when I handled the WM_CTLCOLORBTN message:

/*      HBRUSH hBrush = 0;

      ::DefWindowProc(m_hWnd, uMsg, wParam, lParam);

      DeleteObject(hBrush);
      
      hBrush = CreateSolidBrush(RGB(255,0,0));  
      
      return (LRESULT)hBrush;
*/
0
 

Author Comment

by:middlel
ID: 2628561
I have managed to get the button to work now.. I did have to create 3 images and I had to handle the item action in the LPDRAWITEMSTRUCT and if it was a selected action, I then had to check the item state to see if it was being selected or if it had just obtained the focus.. It was a real long winded process though..

Just one more question though... Why have I lost my button text.? Is there any way to get it back.? I tried calling TextOut() on the hDC but it didn't do anything..

thanks in advance

Emma
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2629732
You have to draw the text yourself every time when you draw the button.
Do it after drawing the bitmap.

TextOut must work fine, but it's better to use DrawText().
0
 

Author Comment

by:middlel
ID: 2636253
Ok, using DrawText() has displayed the title but the area immediately behind the text is now grey again...? I have tried to make it transparent but can't find anything to do that..?

Cheers!

Emma
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2637912
SetBkColor/SetTextColor or SetBkMode/SetTextColor
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…

604 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