c++ 使用抗锯齿设置WindowRgn

z9gpfhce  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(216)

SetWindowRgn支持反锯齿吗?如果支持,如何设置?

i34xakig

i34xakig1#

我猜区域本身不能设置为区域的边缘是抗锯齿的,但可以有一种方法来使用自定义区域和抗锯齿。
我正在努力与SetWindowRgn和自定义样式的CButton(BS_OWNERDRAW启用)圆角。我想设置一个圆角矩形区域,并在启用抗锯齿的情况下渲染一个圆角矩形按钮。当我启用抗锯齿时,我的按钮的边缘会干扰之前渲染中使用的颜色。当按钮由于状态变化(如悬停)而改变颜色时,这是一个问题,禁用或启用。我注意到如果我将OnEraseBkgn -call转发到基类,那么在启用了抗锯齿的情况下,渲染将在我的Region中正确工作。
我必须创建一个帐户,以便我可以分享我的经验。
这是一个设置我正在使用的自定义区域的片段:

CRect rectClient;
CRgn rgnRounded;

this->GetClientRect( rectClient );

rgnRounded.CreateRoundRectRgn( rectClient.left, rectClient.top,
    rectClient.right, rectClient.bottom, 24, 24 );
int result = this->SetWindowRgn( rgnRounded, TRUE );

字符串
然后我的EraseBkgnd处理程序:

/*!
The MFC framework calls this member function when the CWnd object 
background needs erasing (for example, when resized).
*/
BOOL CCustomButton::OnEraseBkgnd(
    _In_ CDC* pDC  //!< Specifies the device-context object.
)
{
    BOOL bRetVal = FALSE;

    // Call base class.
    bRetVal = __super::OnEraseBkgnd( pDC );

    return bRetVal;
}


然后我有我的渲染:

/*!
The MFC framework calls this member function for the owner of an 
owner-drawn button control.
*/
void CCustomButton::DrawItem(
    IN LPDRAWITEMSTRUCT lpDrawItemStruct  //!< Specifies a long pointer to a DRAWITEMSTRUCT data structure that contains information about the item to be drawn and the type of drawing required.
)
{
    // Get handle to drawing context.
    HDC hDC = lpDrawItemStruct->hDC;

    // Use Gdiplus rendering for rounded shape.
    Gdiplus::Graphics gr( hDC );

    // Get the client rectangle.
    CRect rectClient;
    GetClientRect( OUT &rectClient );  // void
    
    // Draw and fill rounded rectangle.
    Gdiplus::Rect gdiplusrectClient( 0, 0,
        rectClient.right - rectClient.left, rectClient.bottom - rectClient.top );
    Gdiplus::GraphicsPath pathRoundedRectangle;
    GetRoundRectPath( gdiplusrectClient, 24, &pathRoundedRectangle );  // My custom function.
    Gdiplus::Color colorBk;
    colorBk.SetFromCOLORREF( RGB( 255, 0, 0 ) );
    Gdiplus::SolidBrush brushBk( colorBk );
    gr.SetSmoothingMode( Gdiplus::SmoothingModeHighQuality );
    gr.FillPath( &brushBk, &pathRoundedRectangle );

}


似乎将OnEraseBkgnd传递给一个基类(比如从CButton派生的基类)可以清除背景,这样客户区的绘图上下文就包含了父窗口将在那里呈现的内容。这似乎很可能发生,因为为这个窗口设置了一个自定义区域。
编辑:好吧,仍然有一个问题,当包含控件的窗口被调整大小和控件移动,有一些残留可见.我认为有一种方法来解决,但我没有分配时间来进一步调查它.

相关问题