views:

223

answers:

4

I'm working with some windows API to create a little application. I already created the buttons, windows, alright.

But the problem is the components I created don't look like the OS theme. They look very simple:

As you can see on image

See the button as example.

How do I enable the Windows theme? It can be in C or Delphi.

+6  A: 

For an application using windows controls, that is documented in this msdn article

Edit: To make a long story short, Windows needs to know for an application if it was intended to use the new style controls. Some older apps just aren't compatible with the new skinned looks of XP and later. Each exe should therefore declare with which version it is compatible in a manifest, an embedded xml file in the executable. The manifest is used for other things like declaring what you are or aren't compatible with (DLL versions, 120 dpi) as well as registration-free com.

jdv
I couldn't find a way to make it on code.I want the components as the theme of the SO, that is the same behavior the components have when created by Delphi IDE.
SaCi
I'm no delphi expert. I googled an article about delph and manifests though: http://delphi.about.com/library/bluc/text/uc111601a.htm
jdv
Only Microsoft would make it an "opt-in" feature to *fit in and use the standard look*
jalf
+1  A: 

If you're using Delphi 2007 or later, Project > Options > Application > Use Windows Themes needs to be checked.

(This should be automatically checked for new applications).

Mike Sutton
That doesn't work if you're not using VCL, right?
Harriv
If you're using standard windows controls (which VCL is a wrapper around) it should work.
Mike Sutton
You can create a Windows control the Win API way, using CreateWindow etc. This is what `TButton`, `TEdit` etc. does. Most VCL controls are simply wrappers for standard Windows controls.
Andreas Rejbrand
If you create all the vcl on runtime, this option isn't available.
SaCi
+2  A: 
  1. It depends on what version of Delphi you're using. IIRC pre-Delphi 6 you need to add the needed manifest by hand. D7 and later has a component that need to be dropped on a form to add theme support (it simply adds the manifest), until D2007 IIRC added a simple check in the project options.
  2. Earlier version of Delphi won't show themed design form. You will see themes only at run time.
  3. Not all controls may support themes. Themes require the proper draw API to be called, if a control doesn't comply it won't be themed. The standard grid is a good example, it isn't draw themed until a late version.
ldsandon
Yes. I just want to make a remark on the third point. Most VCL controls, such as `TButton`, `TEdit`, `TListBox` etc. are simply wrappers for OS controls, and hence, the rendering is done by Windows, not by Delphi code. These are easily themed the normal way. Now, some VCL controls, such as `TGrid`, are not native OS controls, but rather drawn by Delphi code. These will look exactly as the developer made them look. It is possible to use Windows API or `ThemeServices` to query properties/draw details of the curnt. theme, though. So some such controls are "themed" in some sense while most aren't.
Andreas Rejbrand
A: 

In Visual Styles Reference: Functions of MSDN, I found an interesting functions, that is, SetWindowTheme(). It can be used to either to apply or remove visual style to/from a control/window, there are several steps need to be done to enable Visual Style in an application.

To use Windows Theme api, you'll need JwaUxTheme unit of JEDI API Library.

However, applying theme from Windows Theme files (.theme) to an application seems has to be done by turning off visual style from controls and write owner drawn controls based on information from .theme files. MSDN has a documentation about .theme file specification (see the first reference below).

Some good references:

Is Windows Presentation Foundation (WPF) Themes bad? There is a code example how to load it here.

If you use VCL, Theme Engine and Skin Engine has a complete support of themes for Windows XP.

If beauty application is your priority (without supports for Windows themes), I think, BusinessSkinForm and DynamicSkinForm is the best choice.

Vantomex
I don't intend to use other skin, just use the Windows Standard, but when creating the components by VCL it isn't set by default.
SaCi
So, you need a pure Windows API way to apply theme to your application. I have made a google search and found a light to start get into it. See my edited answer.
Vantomex