Windows XP风格:为什么我们在静态文本部件上获得深灰色背景? [英] Windows XP Style: Why do we get dark grey background on static text widgets?

查看:113
本文介绍了Windows XP风格:为什么我们在静态文本部件上获得深灰色背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用C ++和Win32编写Windows桌面应用程序。我们的对话框有一个丑陋的外观与Windows XP风格:静态文本的背景是灰色的。其中对话框背景也是灰色的,这不是问题,但在标签控件内,其中背景是白色的,文本的灰色背景非常明显。

We're writing Windows desktop apps using C++ and Win32. Our dialog boxes have an ugly appearance with "Windows XP style": the background to the static text is grey. Where the dialog box background is also grey, this is not a problem, but inside a tab control, where the background is white, the grey background to the text is very noticeable.

在过去,我们已经完成了许多我们自己绘制的控件,但是这些天,我们试图尽可能地使用标准的look'n'feel,并尽可能地避免覆盖标准行为。

In the past we have done a lot of our own drawing of controls, but these days we are trying to use the standard look'n'feel as much as possible, and to avoid overriding standard behaviour as much as possible.

我们使用的Win32 API,这有点过时,但我认为问题发生甚至与ATL。我们正在创建一个对话模板。文本在静态控件(0x0082)中。我们为样式设置的唯一标志是SS_LEFT。文本控件在标签控件内:SysTabControl32只有一个标志:WS_CLIPSIBLINGS设置它。我尝试了SS_WHITERECT和WS_EX_TRANSPARENT和其他设置,无效。

We are using the Win32 API, which is getting a bit dated, but I think the problem occurs even with ATL. We are creating a DIALOGTEMPLATE. The text is in a "static" control (0x0082). The only flag we set for the style is "SS_LEFT". The text control is inside a tab control: "SysTabControl32" with only one flag: WS_CLIPSIBLINGS set on it. I've experimented with SS_WHITERECT and WS_EX_TRANSPARENT and other settings, to no avail.

所有这些都是用标准的Windows对话框消息处理程序绘制的。我的主要问题是我们做错了什么?而不是我怎么能解决它?,虽然我会解决后者,如果没有人可以帮助我的第一个。

All of this gets drawn with the standard Windows dialog box message handler. My main question is "what are we doing wrong?" rather than "how can I work around it?", although I'll settle for the latter if no-one can help me with the first.

任何想法? / p>

Any ideas?

推荐答案

我们不会覆写WM_CTLCOLORSTATIC讯息。在我们的源代码中没有出现这个字符串,我们的消息处理程序中没有这样的字符串。

We're not overriding the WM_CTLCOLORSTATIC message. There's no occurrence of this string in our source code and nothing like it in our message handlers.

我们通过覆盖WM_DRAWITEM消息来解决这个问题,使用灰色背景(不带选项卡控件的对话框的标准)而不是白色背景(选项卡控件的内容的标准)绘制其内容。

We've worked around this problem by overriding the WM_DRAWITEM message for tab controls to paint their contents with the grey background (standard for dialog boxes without tab controls) rather than the white background (standard for the contents of tab controls).

        brush = CreateSolidBrush(GetSysColor(COLOR_MENU));
        FillRect(lpdis->hDC, &lpdis->rcItem, brush);
        SetBkColor(lpdis->hDC, GetSysColor(COLOR_MENU));
        wtext = ToWideStrdup(c->u.tabcontrol.Tabs[lpdis->itemID].name);
        rect = lpdis->rcItem;
        rect.top += DlgMarginY - 1;
        rect.bottom += DlgMarginY;
        DrawTextW(lpdis->hDC, wtext, -1, &rect, DT_CENTER | DT_VCENTER);
        free(wtext);
        DeleteObject(brush);

这显然是一个解决方法,不是我的问题的正确答案。

This is obviously a workaround, not a proper answer to my question.

顺便说一下,我们初始化common控件,其中我相信tab控件是一个,使用这样的代码...我不认为这是与问题相关吗?

Incidentally, we initialise the "common controls", of which I believe the tab control is one, using code like this...I don't suppose this is related to the issue?

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

hCommCtrl = GetModuleHandle("comctl32.dll");`
if (hCommCtrl) {
        ptrInit = (TfcInit_fn) GetProcAddress(hCommCtrl, "InitCommonControlsEx");
        if (ptrInit) {
            data.dwSize = sizeof(INITCOMMONCONTROLSEX);
            data.dwICC  = ctrlClass;
            if (ptrInit(&data) )
                gCommCtrlsInitialized |= ICC_TAB_CLASSES | ICC_BAR_CLASSES;
        }
}

这篇关于Windows XP风格:为什么我们在静态文本部件上获得深灰色背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆