15,979
社区成员
发帖
与我相关
我的任务
分享
HBRUSH COwnEdit::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CEdit::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: 在此更改 DC 的任何特性
// TODO: 如果默认的不是所需画笔,则返回另一个画笔
//pDC->SetBkColor(GetSysColor(COLOR_3DFACE));
pDC->SetBkMode(TRANSPARENT);
return (HBRUSH)GetStockObject(HOLLOW_BRUSH);
//return hbr;
}
void COwnEdit::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: 在此处添加消息处理程序代码
// 不为绘图消息调用 CEdit::OnPaint()
CRect rect;
this->GetRect(&rect);
CDC* pDC=GetDC();
int nStyle = GetStyle() & ES_MULTILINE;
dc.MoveTo(rect.left,rect.bottom);
dc.LineTo(rect.right,rect.bottom);
CString str;
this->GetWindowText(str);
CFont* pFont=this->GetFont();
CFont oldFont;
dc.SelectObject(pFont);
dc.DrawText(str,&rect,DT_LEFT | DT_TOP);
dc.SetBkMode(TRANSPARENT);
//pDC->SetBkColor(GetSysColor(COLOR_3DFACE));
//pDC->SetBkMode(TRANSPARENT);
}
HBRUSH COwnEdit::CtlColor(CDC* pDC, UINT /*nCtlColor*/)
{
// TODO: 在此更改 DC 的任何特性
// TODO: 如果不应调用父级的处理程序,则返回非 null 画笔
//pDC->SetBkColor(GetSysColor(COLOR_3DFACE));
pDC->SetBkMode(TRANSPARENT);
return (HBRUSH)GetStockObject(HOLLOW_BRUSH);
//return NULL;
}
BOOL COwnEdit::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
{
// TODO: 在此添加专用代码和/或调用基类
//return CEdit::OnChildNotify(message, wParam, lParam, pLResult);
// We only want to handle WM_CTLCOLOREDIT messages - 32 bit only
if (message != WM_CTLCOLOREDIT)
{
return CEdit::OnChildNotify(message, wParam, lParam, pLResult);
}
HDC hdcChild = (HDC)wParam;
// Text is black – you can modify this by adding
// another variable for text color
// SetTextColor(hdcChild, RGB(0,0,0));
//SetBkColor(hdcChild, m_BackColor);
SetBkMode(hdcChild, TRANSPARENT);
//hdcChild->SetBkMode(TRANSPARENT);
return TRUE;
}
void COwnEdit::OnSetFocus(CWnd* pOldWnd)
{
CEdit::OnSetFocus(pOldWnd);
m_BackColor = RGB(255,255,0);
CDC* pDC = GetDC();
Invalidate(FALSE);
// TODO: 在此处添加消息处理程序代码
pDC->SetBkMode(TRANSPARENT);
}
void COwnEdit::OnKillFocus(CWnd* pNewWnd)
{
CEdit::OnKillFocus(pNewWnd);
// I am setting normal back color to white
// – you can modify this as you see fit
m_BackColor = RGB(255,255,255);
// Force a repaint
CDC* pDC = GetDC();
Invalidate(FALSE);
//pDC->SetBkMode(TRANSPARENT);
}
void COwnEdit::SetBkGrndColor()
{
// Delete the old brush
m_Brush.DeleteObject();
// Create a new brush in the specified color
m_Brush.CreateSolidBrush(m_BackColor);
CDC* pDC = GetDC();
pDC->SetBkMode(TRANSPARENT);
//pDC->SetBkColor(m_BackColor);
// Select the brush into this window’s device context
pDC->SelectObject(&m_Brush);
CRect rc;
// Get the client area of the edit control
GetClientRect(&rc);
ScreenToClient(&rc);
// Apply the device context to the client area of the edit control
//pDC->Rectangle(0, 0, rc.Width(), rc.Height());
// Rewrite the text since the backcolor paint
// overwrote the existing text
pDC->SetTextColor(RGB(0,0,0));
pDC->TextOut(2, 2, m_Text.GetBuffer(m_Text.GetLength()));
}
void CYourSlider::PreSubclassWindow()
{
// TODO: Add your specialized code here and/or call the base class
#ifdef SELF_GET
UINT id=::GetDlgCtrlID(this->m_hWnd);
//afxDump << id << "\n";
m_aInfo[m_CtrlCount].CtrlId=id;
m_CtrlCount++;
#endif
//
CSliderCtrl::PreSubclassWindow();
}
BOOL CYourSlider::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
//
#ifdef SELF_GET
UINT id=::GetDlgCtrlID(this->m_hWnd);
afxDump << id << "\n";
for(int jj=0;jj <= m_CtrlCount;jj++)
{
if((m_aInfo[jj].CtrlId > 0) && (m_aInfo[jj].CtrlId==id) && (m_aInfo[jj].pBkdBrush==0))
{// brush
CDC *pDCdlg=GetParent()->GetDC();
CRect rc;
GetWindowRect(&rc);
ScreenToClient(&rc);
afxDump << rc << "\n";
CDC dcMemCtrl;
dcMemCtrl.CreateCompatibleDC(pDC);//DeleteDC needed
CBitmap CtrlBmp;//DeleteObject needed
CtrlBmp.CreateCompatibleBitmap(pDC,rc.Width(),rc.Height());
CBitmap *pOldBitmap = dcMemCtrl.SelectObject(&CtrlBmp);
dcMemCtrl.BitBlt(0, 0, rc.Width(), rc.Height(), pDC,rc.left, rc.top,SRCCOPY);
CBitmap *nowBMP=dcMemCtrl.SelectObject(pOldBitmap);//
// copy to CB for checking
#ifdef TEST
OpenClipboard();
EmptyClipboard();
SetClipboardData(CF_BITMAP,nowBMP->GetSafeHandle());
CloseClipboard();
#endif
CBrush *pBackBr=new CBrush;
pBackBr->CreatePatternBrush(nowBMP);
m_aInfo[jj].pBkdBrush=pBackBr;
//
DeleteObject(CtrlBmp);
dcMemCtrl.DeleteDC();
ReleaseDC(pDCdlg);
return TRUE;
}
}
#endif
return TRUE;
}
BOOL CSelEdit::OnEraseBkgnd(CDC* pDC)
{
CDrawEditDlg *pdlg=(CDrawEditDlg*)GetParent();
CRect rc;
GetWindowRect(&rc);
ScreenToClient(&rc);
// afxDump << rc << "\n";
pDC->FillRect(rc,pdlg->m_pbrEd);//PatternBrush
return TRUE;
// return CEdit::OnEraseBkgnd(pDC);
}
CBrush* CDrawEditDlg::CreateBackgroundBrush(CDC* pDC,int ctrlId)
{
CDC dcMem;
dcMem.CreateCompatibleDC(pDC);//DeleteDC needed
CBitmap* pOldBitmap = dcMem.SelectObject(&m_bitmap);
// Retrieve the size of our bitmap...
BITMAP bmp;
m_bitmap.GetObject(sizeof(bmp),&bmp);
// and the size of our dlg's client area
CRect rect;
GetClientRect(&rect);
//
CRgn rgnClip;
CRect rc;
GetDlgItem(ctrlId)->GetWindowRect(&rc);
rgnClip.CreateRectRgnIndirect(rc);//DeleteObject needed
CDC* pDCex=GetDCEx(&rgnClip,DCX_PARENTCLIP);//ReleaseDC needed
// Fill the client area of dlg,include the ctrl with our bitmap
pDCex->StretchBlt(rect.left, rect.top,rect.Width(), rect.Height(),
&dcMem,0, 0, bmp.bmWidth, bmp.bmHeight,SRCCOPY);
// we create the background brush of SelEdit
CDC dcMemCtrl;
dcMemCtrl.CreateCompatibleDC(pDCex);//DeleteDC needed
CBitmap CtrlBmp;//DeleteObject needed
CtrlBmp.CreateCompatibleBitmap(pDCex,rc.Width(),rc.Height());
pOldBitmap = dcMemCtrl.SelectObject(&CtrlBmp);
ScreenToClient(&rc);
MapWindowPoints(this,rc);
// afxDump << rc << " xx\n";
dcMemCtrl.BitBlt(0, 0, rc.Width(), rc.Height(), pDCex, rc.left, rc.top, SRCCOPY);
CBitmap *nowBMP=dcMemCtrl.SelectObject(pOldBitmap);
// copy to CB for checking
#ifdef TEST
OpenClipboard();
EmptyClipboard();
SetClipboardData(CF_BITMAP,nowBMP->GetSafeHandle());
CloseClipboard();
#endif
CBrush *pBackBr=new CBrush;
pBackBr->CreatePatternBrush(nowBMP);
//
DeleteObject(rgnClip);
DeleteObject(CtrlBmp);
ReleaseDC(pDCex);
dcMemCtrl.DeleteDC();
//
return pBackBr;
}
//
#define ONE_DC
#ifdef ONE_DC // edit not hided !
BOOL CDrawEditDlg::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
if(!m_bInitEditBr)
{// add edit rect
m_bInitEditBr=TRUE;
m_pbrEd=CreateBackgroundBrush(pDC, IDC_SEL_EDIT);
}