15,978
社区成员
发帖
与我相关
我的任务
分享
BOOL CColorLightControl::InitControlEnd(SDrawControlShow *pDrawControlShow, CWnd *pWnd, CONTROL_INIT_STATUS initType)
{
if( initType==cis_status_dlg_init)
{
pDrawControlShow->dlgInitialized = TRUE;
return TRUE;
}
else if( initType==cis_status_control_init )
{
pDrawControlShow->controlInitialized = TRUE;
return TRUE;
}
if( !pDrawControlShow->dlgInitialized || !pDrawControlShow->controlInitialized)
return FALSE;
pDrawControlShow->SystemControls.RemoveAll();
int ClipRgnCount = 0;
for( int i=0; i<pDrawControlShow->IDCount; i++ ) //循环所有控件,定位所有系统控件
{
RECT boundRect;
BOOL bRes = FALSE;
if( m_CustomEdit.GetBoundControlPos(pDrawControlShow->pDrawControlInfo, i, &boundRect))
{
bRes = TRUE;
ClipRgnCount++;
}
else if(m_CustomControl.GetBoundControlPos(pDrawControlShow->pDrawControlInfo, i, &boundRect,pWnd))
{
bRes = TRUE;
ClipRgnCount++;
}
if(bRes)
{
//解析扩展部分
STranExpandInfo Temp;
CWnd *pCtrlWnd = pWnd->GetDlgItem(pDrawControlShow->pDrawControlInfo[i].boundID);
if(pCtrlWnd != NULL && IsWindow(pCtrlWnd->GetSafeHwnd()))
{
Temp.nID = i;
Temp.pWnd = pWnd;
Temp.pCtrlWnd = pCtrlWnd;
Temp.boundRect = boundRect;
Temp.pDrawControlInfo = &(pDrawControlShow->pDrawControlInfo[i]);
m_TranExpandManager.TranExpand(Temp);
//移动控件
pCtrlWnd->MoveWindow(&boundRect,FALSE); //系统控件移动位置,但不重绘
pDrawControlShow->SystemControls.Add(pCtrlWnd); //将系统控件加入需要重绘的控件集
if( pDrawControlShow->pDrawControlInfo[i].enable && pDrawControlShow->pDrawControlInfo[i].visible)
{
if( !pCtrlWnd->IsWindowVisible() /*|| initType!=cis_status_update*/)
pCtrlWnd->ShowWindow(SW_SHOWNORMAL);
}
else
{
if(pCtrlWnd->IsWindowVisible()/* || initType!=cis_status_update*/)
pCtrlWnd->ShowWindow(SW_HIDE);
}
}
}
}
CreateClipRgn(pDrawControlShow,pWnd);//取得屏幕背景刷新区域(将系统控件的区域从背景区域中挖除)
return TRUE;
}
void CColorLightControl::DrawAllControl(SDrawControlShow *pDrawControlShow, CWnd *pWnd)
{
if( pDrawControlShow->memDC==NULL || pDrawControlShow->memDC.m_hDC==NULL)
return;
CSingleLock SingleLock(&m_CriticalSection);
if(SingleLock.IsLocked())
return;
CString strResPath;
strResPath.Format(_T("%s%s"), g_appPath, g_pCltcontrolstyle->GetResourceDir());
Graphics mGraphics(pDrawControlShow->memDC.m_hDC);
if(pDrawControlShow->pCusBackGroundColor != NULL)
mGraphics.Clear(RgbToArgb(255, *pDrawControlShow->pCusBackGroundColor));
else
mGraphics.Clear(RgbToArgb(255, g_pCltcontrolstyle->GetBackGroundColor()));
pDrawControlShow->memDC.SelectObject(&pDrawControlShow->textFont);
pDrawControlShow->memDC.SetBkMode(TRANSPARENT);
if(pDrawControlShow != NULL && pWnd != NULL)
{
HWND hwnd = pWnd->GetSafeHwnd();
if(pDrawControlShow->pFrontDraw != NULL)
pDrawControlShow->pFrontDraw(hwnd, &pDrawControlShow->memDC);
}
CDrawCustomControl *pControl = NULL;
for(int nID = 0; nID<pDrawControlShow->IDCount; nID++ )
{
pDrawControlShow->memDC.SetTextColor(g_pCltcontrolstyle->GetBackGroundColor());
if( !pDrawControlShow->pDrawControlInfo[nID].visible )
continue;
pControl = GetDlgControl(pDrawControlShow->pDrawControlInfo[nID].controlType);
if(pControl != NULL)
{
pControl->DrawControl(pDrawControlShow, nID, strResPath,pWnd,g_pCltcontrolstyle->GetBackGroundColor()); //在内存DC中绘制自定义控件
}
}
if(pDrawControlShow != NULL && pWnd != NULL)
{
HWND hwnd = pWnd->GetSafeHwnd();
if(pDrawControlShow->pBehindDraw != NULL)
pDrawControlShow->pBehindDraw(hwnd, &pDrawControlShow->memDC);
}
if( pWnd!=NULL)
pWnd->RedrawWindow(); //触发Onpaint,使用双缓存机制
}
void CColorBaseDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
if(!m_baseDlgSetInfo.m_memDCInit)
return ;
m_pIColorLightControl->RePaintSystemControl(&m_cltControlShow); //将需要重绘的系统控件绘制出来
dc.SelectClipRgn(&m_cltControlShow.clientRgn, RGN_COPY); //将挖掉系统控件区域的背景区域选到当前对话框的dc中
dc.BitBlt(m_cltControlShow.clientRect.left, m_cltControlShow.clientRect.top,m_cltControlShow.clientRect.Width(), m_cltControlShow.clientRect.Height(), &m_cltControlShow.memDC, 0, 0, SRCCOPY); //双缓存复制
}
void CColorLightControl::RePaintSystemControl( SDrawControlShow *pDrawControlShow )
{
if( !pDrawControlShow->dlgInitialized || !pDrawControlShow->controlInitialized)
return;
for(int i = 0; i < pDrawControlShow->SystemControls.GetCount(); i++)
pDrawControlShow->SystemControls.GetAt(i)->PostMessage(WM_PAINT,0,0); //使用PostMessage发送WM_PAINT消息绘制系统控件
}
void cTree::OnPaint()
{
CPaintDC dc(this);
// get size
CRect rc;
GetClientRect(&rc);
// Create a compatible memory DC
CDC memDC;
memDC.CreateCompatibleDC(&dc);
// Select a compatible bitmap into the memory DC
CBitmap bitmap;
bitmap.CreateCompatibleBitmap( &dc, rc.Width(), rc.Height());
HBITMAP oldBmp=(HBITMAP)memDC.SelectObject(&bitmap);
// Let the control draws the tree.
DefWindowProc(WM_PAINT, (WPARAM)memDC.m_hDC, 0 );
// 'and' to the background,
dc.BitBlt(0,0,rc.Width(),rc.Height(),&memDC,0,0,SRCAND);
// set back
memDC.SelectObject(oldBmp);
// free
DeleteObject(bitmap.m_hObject);
DeleteObject(memDC);
}