15,980
社区成员




// 拷贝对应区域主框显示的内容
95. CDC *pDC = pParent->GetDC();
96. CDC MemDC;
97. MemDC.CreateCompatibleDC(pDC);
98. m_Bmp.CreateCompatibleBitmap(pDC,Rect.Width(),Rect.Height());
99. CBitmap *pOldBmp = MemDC.SelectObject(&m_Bmp);
100. MemDC.BitBlt(0,0,Rect.Width(),Rect.Height(),pDC,Rect.left,Rect.top,SRCCOPY);
101. MemDC.SelectObject(pOldBmp);
102. pParent->ReleaseDC(pDC);
BOOL CRichStatic::OnEraseBkgnd(CDC* pDC)
82.{
83. // 当背景色为透明时,需要保存与拷贝显示主框的显示区域
84. if (m_clrBackground == CLR_NONE)
85. {
86. if (m_Bmp.GetSafeHandle() == NULL)
87. {
88. CRect Rect;
89. GetWindowRect(&Rect);
90. CWnd *pParent = GetParent();
91. ASSERT(pParent);
92. pParent->ScreenToClient(&Rect); // 将坐标转换为与主对话框相对应
93.
94. // 拷贝对应区域主框显示的内容
95. CDC *pDC = pParent->GetDC();
96. CDC MemDC;
97. MemDC.CreateCompatibleDC(pDC);
98. m_Bmp.CreateCompatibleBitmap(pDC,Rect.Width(),Rect.Height());
99. CBitmap *pOldBmp = MemDC.SelectObject(&m_Bmp);
100. MemDC.BitBlt(0,0,Rect.Width(),Rect.Height(),pDC,Rect.left,Rect.top,SRCCOPY);
101. MemDC.SelectObject(pOldBmp);
102. pParent->ReleaseDC(pDC);
103. }
104. else // 将主框显示的内容拷贝回去
105. {
106. // CRect Rect;
107. // GetClientRect(Rect);
108. // CDC MemDC;
109. // MemDC.CreateCompatibleDC(pDC);
110. // CBitmap *pOldBmp = MemDC.SelectObject(&m_Bmp);
111. // pDC->BitBlt(0,0,Rect.Width(),Rect.Height(),&MemDC,0,0,SRCCOPY);
112. // MemDC.SelectObject(pOldBmp);
113. }
114. }
115.
116. return TRUE;
117.}
RECT rect;
GetWindowRect(&rect);
CBrush brush;
brush.CreateSolidBrush(m_clrBackground);
::SelectObject(lpDrawItemStruct->hDC, brush.m_hObject); // 设置画刷颜色
::SelectObject(lpDrawItemStruct->hDC, GetStockObject(NULL_PEN)); // 设置笔为空笔(不绘制边界)
Rectangle(lpDrawItemStruct->hDC, 0, 0,rect.right - rect.left, rect.bottom - rect.top);
void CRichStatic::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
if (m_clrBackground != CLR_NONE) // 若背景色不为CLR_NONE(CLR_NONE表示无背景色),则绘制背景
{
RECT rect;
GetWindowRect(&rect);
CBrush brush;
brush.CreateSolidBrush(m_clrBackground);
::SelectObject(lpDrawItemStruct->hDC, brush.m_hObject); // 设置画刷颜色
::SelectObject(lpDrawItemStruct->hDC, GetStockObject(NULL_PEN)); // 设置笔为空笔(不绘制边界)
Rectangle(lpDrawItemStruct->hDC, 0, 0,rect.right - rect.left, rect.bottom - rect.top);
}
CString strCaption; // 标题文字
GetWindowText(strCaption);
if (m_pTextFont != NULL)
{
::SelectObject(lpDrawItemStruct->hDC, m_pTextFont->m_hObject);
}
::SetTextColor(lpDrawItemStruct->hDC, m_clrText);
TextOut(lpDrawItemStruct->hDC, 0, 0, strCaption, strCaption.GetLength());
}
void CRichStatic::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
if (m_clrBackground != CLR_NONE) // 若背景色不为CLR_NONE(CLR_NONE表示无背景色),则绘制背景
{
RECT rect;
GetWindowRect(&rect);
CBrush brush;
brush.CreateSolidBrush(m_clrBackground);//这里
::SelectObject(lpDrawItemStruct->hDC, brush.m_hObject); // 设置画刷颜色
::SelectObject(lpDrawItemStruct->hDC, GetStockObject(NULL_PEN)); // 设置笔为空笔(不绘制边界)
Rectangle(lpDrawItemStruct->hDC, 0, 0,rect.right - rect.left, rect.bottom - rect.top);
}
CString strCaption; // 标题文字
GetWindowText(strCaption);
if (m_pTextFont != NULL)
{
::SelectObject(lpDrawItemStruct->hDC, m_pTextFont->m_hObject);
}
::SetTextColor(lpDrawItemStruct->hDC, m_clrText);
TextOut(lpDrawItemStruct->hDC, 0, 0, strCaption, strCaption.GetLength());
}