Problem with drawing custom Windows controls

北城余情 提交于 2019-12-06 09:05:12

问题


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:

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" );

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.

Thanks,

James


回答1:


You called DrawThemeBackground with CP_BACKGROUND and CP_DROPDOWNBUTTONRIGHT. Perhaps you should also call it with CP_BORDER if you want the border to match the standard combobox?



来源:https://stackoverflow.com/questions/5275619/problem-with-drawing-custom-windows-controls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!