Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have enabled Visual styles for my application:

C++
#pragma comment( linker, "/manifestdependency:\"type='win32' \
    name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
    processorArchitecture='*' publicKeyToken='6595b64144ccf1df' \
    language='*'\"")


I can set font for the date in the edit control with following approach:

C++
HFONT hf = (HFONT)SendMessage(hwndDateTimePicker, WM_GETFONT, (WPARAM)0, (LPARAM)0);
if (hf != NULL)
{
    LOGFONT lf = { 0 };

    GetObject(hf, sizeof(LOGFONT), &lf);

    lf.lfWeight = FW_BOLD;
    lf.lfUnderline = TRUE;

    hf = CreateFontIndirect(&lf);

    SendMessage(GetDlgItem(hDlg, IDC_DATETIMEPICKER1), WM_SETFONT
        (WPARAM)hf, (LPARAM)TRUE);
}

However, trying to use GetDC and SetTextColor (for example) does not work.

QUESTION:

Is there a workaround for my problem?

Maybe there is a way to get the handle of the edit control and subclass it, for example? Just a thought...
Posted
Updated 13-Feb-15 18:53pm
v2
Comments
enhzflep 26-Feb-15 15:08pm    
Hmm. I'm looking at the code in the Wine repo again, specifically, at this file:
https://github.com/wine-mirror/wine/blob/master/dlls/comctl32/datetime.c

And more specifically, at both the DATETIME_Paint (line 1045) and the DATETIME_Refresh (line 739) functions.

In the implementation it presents, neither function cause any messages to be sent to the parent which could be intercepted in order to change colours. It seems as though comctl32_color.clrGrayText and comctl32_color.clrWindowText are both hard-coded into the control.
It is also known to misbehave when sent the WM_PRINT message. :(

The only thing I can think of, which is almost certainly too much pain for too little gain - is to re-implement the control yourself, from the code in the wine repo.
This would be fairly straight-forward, if not for the fact that it needs to be themed. The theming engine that was introduced in XP does some funky stuff, one of which includes subclassing the controls itself, to have control over their appearance.

It also maintains an internal DB of various control class-names and their appearance, so that DrawThemeBackground etc. can work properly. Naturally, you wouldn't have the luxury of
(a) having uxtheme.dll subclass your new window-class.
(b) calling DrawThemeBackground.

So, from what I can tell - it's pretty much a horror-show no matter which way you try to approach it - as you've no doubt suspected/concluded over the past couple of weeks.
:-|

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900