问题描述
大家好!
我有一个带有选项卡控件的基于Mfc的对话框.在此控件上,我想放置一个子对话框,其大小为选项卡控件的一半.该页面包含一些按钮和静态变量.
现在我的问题是:
我希望子对话框具有选项卡控件的背景,在某些XP样式中,该控件具有颜色渐变.
我试过了
Hi everyone!
I have a mfc based dialog with a tab control. On this control I want to place a child dialog, that is half the size of the tab control. The page contains some buttons ans statics.
Now my problem:
I want the child dialog to have the background of the tab control, which in some XP-styles has a color gradient.
I tried
EnableThemeDialogTexture(m_hWnd,ETDT_ENABLETAB);
但这仅在页面与选项卡控件一样大的情况下才有效.否则,渐变看起来会有所不同.
我也尝试过:
But that only works if the page is as big as the tab control. Otherwise the gradient looks different.
I also tried:
BOOL CDialogEx::OnEraseBkgnd(CDC* pDC)
{
DWORD style = GetExStyle();
if ( style & WS_EX_TRANSPARENT )
{
return TRUE;
}
return CDialog::OnEraseBkgnd(pDC);
}
这对于页面来说效果很好,但是页面上的控件看起来很糟糕,它们使用默认的颜色背景绘制.
我希望有人能帮帮忙.
This works fine for the page, but the controls on it look bad, the are drawn with a default color background.
I hope someone can help. Thanks ahead!
推荐答案
HBRUSH CBaseView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = __super::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor == CTLCOLOR_STATIC)
{
pDC->SetBkMode(TRANSPARENT);
return (HBRUSH)::GetStockObject(HOLLOW_BRUSH);
}
return hbr;
}
我注意到仅只读编辑控件存在此问题(因为系统将其视为静态控件),因此我将其固定为:(但不适用于渐变背景)
I noticed a problem with this only with read-only edit controls (because the system treats them as static controls), I fixed it like this: (but that wont work well for a gradient background)
HBRUSH CBaseView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = __super::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor == CTLCOLOR_STATIC)
{
pDC->SetBkMode(TRANSPARENT);
pDC->SetBkColor(RGB(242,242,242));
return (HBRUSH)m_hSTBackBrush;
}
return hbr;
}
祝你好运
Good luck
if((nCtlColor == CTLCOLOR_STATIC) || (nCtlColor == CTLCOLOR_BTN)) ...
如果您还有常规的按钮,它们可能看起来不正确(但您可以尝试一下).
我相信我会做这样的事情:
if you also have regular push buttons they may look wrong (but you can try it).
I believe what I would do is something like this:
HBRUSH CBaseView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
switch(pWnd->GetDlgCtrlId())
{
case IDC_CHECKBOX1:
case IDC_CHECKBOX2:
case IDC_RADIOBTN1:
case IDC_RADIOBTN2:
pDC->SetBkMode(TRANSPARENT);
return (HBRUSH)::GetStockObject(HOLLOW_BRUSH);
default:
return __super::OnCtlColor(pDC, pWnd, nCtlColor);
}
}
祝您好运,很高兴为您提供帮助
Good luck, glad to help
这篇关于放置在标签控件上的透明子对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!