2013-06-12 6 views
0

SetBkModeTRANSPARENT이라는 문 제가 있습니다. 이전 텍스트는 새 텍스트를 그리기 전에 비트 맵에서 지워지지 않습니다. 이것은 그리기 코드입니다.투명도가있는 SetBkMode를 사용할 때 배경을 수정하는 방법이 업데이트되지 않았습니다.

void PaintWindow(WTL::CDCHandle dc) 
{ 
    CRect rcWindow; 
    HFONT hPrevFont, hFont; 
    DWORD dwStyle; 
    UINT uTextFormat; 

    ATLVERIFY(GetWindowRect(rcWindow)); 
    dwStyle = GetStyle(); 

    // Setup Font to use. 
    hFont = GetFont(); 

    if (hFont != nullptr) 
     hPrevFont = dc.SelectFont(hFont); 
    else 
     hPrevFont = nullptr; 

    // Setup Text Format. 
    uTextFormat = 0; 

    if (dwStyle & SS_ENDELLIPSIS) 
     uTextFormat |= DT_END_ELLIPSIS; 

    if (dwStyle & SS_NOPREFIX) 
     uTextFormat |= DT_NOPREFIX; 

    if (dwStyle & SS_RIGHT) 
     uTextFormat |= DT_RIGHT; 

    // Draw Text. 
    dc.SetTextColor(m_crTextColor); 
    dc.SetBkMode(TRANSPARENT); 
    dc.DrawText(m_strText, m_strText.GetLength(), CRect(0, 0, rcWindow.Width(), rcWindow.Height()), uTextFormat); 

    // Clean up. 
    if (hPrevFont != nullptr) 
     dc.SelectFont(hPrevFont); 
} 

미리 감사드립니다.

+0

그래서 '투명도'를'오페라 '로 변경하려고 했습니까? –

+0

투명한 배경으로 텍스트를 그릴 필요가 있습니다. 그래서 OPAQUE는 선택 사항이 아닙니다. – UltimaWeapon

답변

1

해결되었습니다. 새 텍스트를 그리기 전에 부모 윈도우를 다시 그리는 코드를 추가했습니다. 이것은 완성 된 코드입니다.

void PaintWindow(WTL::CDCHandle dc) 
{ 
    CRect rcWindow; 
    HFONT hPrevFont, hFont; 
    DWORD dwStyle; 
    UINT uTextFormat; 
    ATL::CWindow wndParent; 

    ATLVERIFY(GetWindowRect(rcWindow)); 
    dwStyle = GetStyle(); 

    // Redraw Background. 
    wndParent = GetParent(); 

    if (wndParent != nullptr) 
    { 
     CRect rcInParent = rcWindow; 

     ATLVERIFY(wndParent.ScreenToClient(rcInParent)); 
     ATLVERIFY(wndParent.InvalidateRect(rcInParent)); 
     ATLVERIFY(wndParent.UpdateWindow()); 
    } 

    // Setup Font to use. 
    hFont = GetFont(); 

    if (hFont != nullptr) 
     hPrevFont = dc.SelectFont(hFont); 
    else 
     hPrevFont = nullptr; 

    // Setup Text Format. 
    uTextFormat = 0; 

    if (dwStyle & SS_ENDELLIPSIS) 
     uTextFormat |= DT_END_ELLIPSIS; 

    if (dwStyle & SS_NOPREFIX) 
     uTextFormat |= DT_NOPREFIX; 

    if (dwStyle & SS_RIGHT) 
     uTextFormat |= DT_RIGHT; 

    // Draw Text. 
    dc.SetTextColor(m_crTextColor); 
    dc.SetBkMode(TRANSPARENT); 
    dc.DrawText(m_strText, m_strText.GetLength(), CRect(0, 0, rcWindow.Width(), rcWindow.Height()), uTextFormat); 

    // Clean up. 
    if (hPrevFont != nullptr) 
     dc.SelectFont(hPrevFont); 
}