You are here:

C++/Creating a button control

Advertisement


Question
-------------------------
Followup To
Question -
Hello,

How can I create a button control, not a regular one, but a white button with a blue frame that changes into orange frame when the mouse cursor is on the button ? (Like the buttons in Microsoft Internet Explorer 6.0 &
Like the buttons in this very page (I Agree, Cancel ))

Thanks

Answer -
Gil , Thank you for your question.

To change the appearance of all buttons on your computer, select Appearance in the Display Properties of your computer.

To set the properties of just one button in an application, intercept certain Windows messages (such as WM_CTLCOLORBTN) sent to that button or to the parent of the button, which is the dialog box in which that button appears. Further information is contained in the Buttons topic in the MSDN Library. You can search Microsoft's MSDN Library at http://search.microsoft.com/us/dev/default.asp.

David Spector


I have searched Microsoft's MSDN Library and I couldn't find a source code (or an example) how to create such a button.
Can you give me a source code for creating this button control ?
(I program Microsoft Visual c++ 6.0, Win32 App)

Thank You!

Gil Michael

Answer
Gil Michael, Thank you for your question.

To create a button, select the menu item to add a new Resource, and choose Dialog box. Next, edit the new dialog box in the Dialog Box Editor and add a button by dragging and dropping a button from the toolbox.

To intercept messages, add a dialog box procedure to your application. The topic "Button Color Messages" discusses the messages, and the "CreateDialog" topic discusses how to create a dialog box. The "DialogProc" topic discusses dialog box procedures.

The above assumes you are using Win32, not MFC.

I suggest that you read the MSDN Library topics about dialog boxes and controls thoroughly. This will give you the knowledge you need to solve your problem. If you find the MSDN Library difficult to understand, consult books about Windows programmaming such as Programming Windows by Charles Petzold.

David Spector

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


David Spector

Expertise

Highly knowledgeable in the C++ language, Visual C++ (MSVC), Windows API, documentation and other quality-assurance techniques, and debugging. Knowledgeable in MFC, COM, GUI design, and object-oriented design.

Experience

I have been a software engineer since 1965. I have been published. My specializations have been: biomedical programming, compiler implementation, and many kinds of Windows programming. I don't do Databases or other business-oriented stuff.

Publications
Windows?/DOS Developer's Journal, ACM SIGPLAN Notices, and Computer Science Press.

Education/Credentials
ICCP Systems Programming Certification
Master's degree equivalent in Computer Science

©2016 About.com. All rights reserved.