HomeC&C++WainTutorialsSamplesTip&TrickTools


And now two hints to make the dialogbox look a bit more like other windows application.
First the font. By default windows will use its "system" font for the dialog, but to make it look like other dialog boxes we must set it to use the default GUI font.
To do this we could send a WM_SETFONT to all controls, as:
SendDlgItemMessage(hwndDlg,
                   AddRadioId, WM_SETFONT,
                   (WPARAM)GetStockObject(DEFAULT_GUI_FONT),
                   TRUE);
GetStockObject returns a standard GUI object, in this case the default GUI font, which is the one we will like to use.

We could do this for all controls, but that is a bit boring, so lets find a more elegant way.

EnumChildWindows is a function that can be used to enumerate all child windows and call a function for each of the childs. The childs are in our case the controls.

So we simply add this call:
EnumChildWindows(hwndDlg,
                 SetFontProc,
                 (LPARAM)GetStockObject(DEFAULT_GUI_FONT));
SetFontProc is our function that gets called for all child windows. It could look like:
BOOL CALLBACK SetFontProc(HWND aHwnd, LPARAM lParam)
{
   SendMessage(aHwnd, WM_SETFONT, lParam, TRUE);
   return TRUE;
}
lParam is the last parameter in the call to EnumChildWindows, that is the font.

And then all is set, all controls will use the right font, and when you add a new control to the dialog, it will automatic use the right font.
The call to EnumChildWindows should be the last thing for WM_CREATE, after all the controls are created.

To give your windows applications the right XP look, put the following into a file, called program.exe.manifest, and put it into the same folder as the executeable:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly
   xmlns="urn:schemas-microsoft-com:asm.v1"
   manifestVersion="1.0">
     <assemblyIdentity
       processorArchitecture="x86"
       version="5.1.0.0"
       type="win32"
       name="program.exe"/>
    <description>My Program</description>
    <dependency>
    <dependentAssembly>
    <assemblyIdentity
         type="win32"
         name="Microsoft.Windows.Common-Controls"
         version="6.0.0.0"
         publicKeyToken="6595b64144ccf1df"
         language="*"
         processorArchitecture="x86"/>
    </dependentAssembly>
    </dependency>
</assembly>
You have to change name="program.exe" and the name of the file to fit the name of your program.
For this to work you need to call InitCommonControls, or the application might not start.

The complete code is here.