绘制自定义Windows控件时出现问题 [英] Problem with drawing custom Windows controls

查看:86
本文介绍了绘制自定义Windows控件时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Windows中的uxTheme库来绘制自己的自定义控件,我无法弄清楚为什么我的控件看起来不像(假定)使用与我主题相同的常规Windows控件。 m使用:

I'm playing around with drawing my own custom controls using the uxTheme library in Windows, and I can't work out why my control doesn't look like the regular Windows control that (supposedly) uses the same theme I'm using:

上图显示了标准的Windows ComboBox(顶部)和使用ComboBox主题绘制的自定义控件(底部)。我无法解决的是为什么控件中的边框与标准控件的形状和颜色不同。

The above image shows a standard Windows ComboBox (top) and my custom control drawn using the ComboBox theme (bottom). What I can't work out is why the border from my control is a different shape and colour to the standard control.

在我的类构造函数中,我打开了主题数据:

In my class constructor I open the theme data:

mComboTheme = OpenThemeData( hwnd, L"COMBOBOX" );

然后在WM_PAINT的处理程序中,我只绘制了ComboBox组件的两个部分:

And then in the handler for WM_PAINT I'm just drawing two parts of the ComboBox components:

case WM_PAINT:
{
    PAINTSTRUCT ps;
    HDC         hdc;
    RECT        client;

    if( GetUpdateRect( hwnd, &ps.rcPaint, false ))
    {
        hdc = BeginPaint( hwnd, &ps );
        GetClientRect( hwnd, &client );

        if( IsThemeBackgroundPartiallyTransparent( mComboTheme, CP_BACKGROUND, CBXS_HOT ))
        {
            DrawThemeParentBackground( hwnd, hdc, &ps.rcPaint );
        }
        DrawThemeBackground( mComboTheme, hdc, CP_BACKGROUND, CBXS_HOT, &client, &ps.rcPaint );
        client.left = client.right - 20;
        DrawThemeBackground( mComboTheme, hdc, CP_DROPDOWNBUTTONRIGHT, CBXSR_HOT, &client, ps.rcPaint );

        EndPaint( *this, &ps );
    }
    break;
}

关于这两个控件为何看起来不同的任何建议都是

Any suggestions as to why these two controls don't look the same would be greatly appreciated.

谢谢

James

推荐答案

您使用 CP_BACKGROUND CP_DROPDOWNBUTTONRIGHT调用了 DrawThemeBackground 。如果您希望边框与标准组合框匹配,也许还应该用 CP_BORDER 调用它?

这篇关于绘制自定义Windows控件时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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