图形背景下对话框的CButtonST按钮未能刷新
以bmp图做对话框背景,下面是这个对话框的相关函数的主要内容。
对话框(这里称它作MyDlg)中用了CButtonST按钮。CButtonST按钮用了
DrawTransparent函
数。正常情况下一切OK。不过如果程序启动时前面有个东西挡住了它(比如有个总在前端
的程序)。则MyDlg启动完成后,移开挡在它前面的那个程序,会发现如果挡住部分有CBu
ttonST按钮,这个按钮未能显示出背景图来。
请有经验的大虾指正。多谢了。
// MyDlg.cpp : implementation file
//
void CMyDlg::OnPaint()
{
CPaintDC dc( this );
CRect rc;
GetClientRect( rc );
if ( !(HBITMAP)m_bitmap ) // If no bitmap is selected
dc.FillRect( rc, &m_brush );
if ( (HBITMAP)m_bitmap )
{
CDC* pDC;
CDC memDC;
CBitmap bmp;
BOOL bDrawOnMemDC = ( GetDisplayMode() != dispTile ) ? TRUE : FALSE;
if ( bDrawOnMemDC )
{
if ( GetDisplayMode() != dispStretch )
bmp.CreateCompatibleBitmap( &dc, rc.right, rc.bottom );
else
bmp.CreateCompatibleBitmap( &dc, m_sizeImage.cx, m_sizeImage.c
y );
memDC.CreateCompatibleDC( &dc );
memDC.SelectObject( &bmp );
pDC = &memDC;
}
else
pDC = &dc;
CPoint point;
for ( point.y = 0; point.y < rc.Height(); point.y += m_sizeImage.cy )
for ( point.x = 0; point.x < rc.Width(); point.x += m_sizeImage.cx
)
pDC->DrawState( point, m_sizeImage, &m_bitmap, DST_BITMAP | DS
S_NORMAL );
if ( bDrawOnMemDC == TRUE )
dc.BitBlt( 0, 0, rc.right, rc.bottom, pDC, 0, 0, SRCCOPY );
}
}
BOOL CMyDlg::OnEraseBkgnd( CDC* pDC )
{
return TRUE; // Return TRUE so background is not erased
}
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
switch(nCtlColor)
{
// case CTLCOLOR_EDIT:
case CTLCOLOR_STATIC:
// The Slider Control has CTLCOLOR_STATIC, but doesn't let
// the background shine through,
TCHAR lpszClassName[255];
GetClassName(pWnd->m_hWnd, lpszClassName, 255);
if(_tcscmp(lpszClassName, TRACKBAR_CLASS) == 0)
return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
case CTLCOLOR_BTN:
// let static controls shine through
pDC->SetBkMode(TRANSPARENT);
return HBRUSH(m_brushHollow);
default:
break;
};
return CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
// HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
// return hbr;