I am programming strictly in C and WinAPI, no C++ or C#. I am a beginner and just learning to draw controls etc. The thing is that when I create Windows or other controls like Command Buttons, they have Windows Native look. Take a look at this:
But in Windows 7, the command buttons look like this:
Now, how do I get command buttons in my program to look like that. Is it even possible? I am following this tutorial, for reference: http://zetcode.com/gui/winapi/
Thanks.
A control is a child window that an application uses in conjunction with another window to enable user interaction. Controls are most often used within dialog boxes, but they can also be used in other windows. Controls within dialog boxes provide the user with a way to type text, choose options, and initiate actions.
To enable your application to use visual styles, you must use ComCtl32. dll version 6 or later. Because version 6 is not redistributable, it is available only when your application is running on a version of Windows that contains it. Windows ships with both version 5 and version 6.
Common Control ManifestGenerates an application manifest to enable the Common Control DLL that is included with Microsoft Windows XP and newer operating systems. Version 6 of the Common Control DLL does not automatically update the earlier version of the Common Controls that your existing applications use.
But you can use C/C++ to access the Win32 API just as you do to access standard C/C++ library functions. If you are to learn it, the best way is to find a compiler with Win32 SDK libraries, then write your C/C++ code using the tools. If you like, Visual Studio (community version) is a good choice for learning.
That's how the controls looked back in the 1990s, before themes (visual styles) were invented. As you've noticed, modern buttons are now painted all fancy-pants with gradients and throbbing and all that. But for backwards-compatibility reasons, you have to specifically request that your controls get that treatment, or they'll fall back to the legacy style.
You do that by specifying a manifest. You can either add one in plain text format to your application's root directory, or you can have Visual Studio (2005 and later) automatically embed one in your EXE.
The second route is the way I'd go. Add the following code to your stdafx.h
file to inform the compiler that you want it to add the manifest automatically upon building your project:
#if defined _M_IX86 #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") #elif defined _M_IA64 #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"") #elif defined _M_X64 #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") #else #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") #endif
This MSDN article has more information on visual styles than you could ever want.
And if you really want your application to look native, you need to change the background brush used for the main window. By default, it's set to use the same color as a textbox's background (white).
You want to use the color used to paint 3D controls, instead. Modify the hbrBackground
member of your WNDCLASS
(or WNDCLASSEX
) structure as shown here:
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
Why do you have to add 1? For backwards-compatibility reasons, again. The details are boring. :-)
You enable visual styles for your app by providing an XML manifest, either as a separate file or as an embedded resource. See Enabling Visual Styles for details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With