15,979
社区成员
发帖
与我相关
我的任务
分享
LRESULT CExRichEdit::WndProcNew(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
CExRichEdit * pWnd = NULL;
pWnd = (CExRichEdit *)CWnd::FromHandlePermanent( hWnd );
if( pWnd == NULL ){
return 0;
}
if( !(pWnd->m_Style & EX_RICHEDIT_LN) )
{
return CallWindowProc(pWnd->WndProcOld, hWnd, uMsg, wParam, lParam);
}
if( uMsg == WM_PAINT )
{
CallWindowProc(pWnd->WndProcOld, hWnd, uMsg, wParam, lParam);
HDC hDC = ::GetDC( hWnd );
CDC * pDC = new CDC;
pDC->Attach( hDC );
pDC->SetBkMode(TRANSPARENT);
//------------------------------------------------------------------------------------------------------
CDC MemDC;
CRect rect;
CBitmap m_Canvas;
pWnd->GetClientRect(&rect);
MemDC.CreateCompatibleDC(pDC);
m_Canvas.CreateCompatibleBitmap(pDC,rect.Width(),rect.Height());
MemDC.SelectObject(&m_Canvas);
MemDC.SetBkMode(TRANSPARENT);
//-------------------------------------------------------------------------------------------------------------
CRgn rgn2;
rgn2.CreateRectRgn( rect.left, rect.top, rect.left+pWnd->m_nweigth, rect.bottom );
MemDC.SelectClipRgn(&rgn2); // 裁剪边框
CRgn rgn1;
rgn1.CreateRectRgn( rect.left+pWnd->m_nweigth, rect.top, rect.right, rect.bottom );
// pWnd->RedrawWindow(0, &rgn1, RDW_INVALIDATE);
LOGFONT lf;
HFONT hFont,oldFont;
GetObject(GetStockObject(SYSTEM_FONT), sizeof(LOGFONT), &lf);
lf.lfHeight = -pWnd->m_cf.yHeight/15;
lf.lfWidth = 7;
lf.lfWeight = 300;
wsprintf( lf.lfFaceName, _T("%s"), _T("隶书") );
hFont = CreateFont(lf.lfHeight, lf.lfWidth,
lf.lfEscapement, lf.lfOrientation, lf.lfWeight,
lf.lfItalic, lf.lfUnderline, lf.lfStrikeOut, lf.lfCharSet,
lf.lfOutPrecision, lf.lfClipPrecision, lf.lfQuality,
lf.lfPitchAndFamily, lf.lfFaceName);
oldFont = (HFONT)pDC->SelectObject( hFont ); // 设置字体
CBrush BrushOver;
BrushOver.CreateSolidBrush( pWnd->m_nbclr ); // 行号底色底色
rect.right = pWnd->m_nweigth-7;
MemDC.FillRect( &rect, &BrushOver );
CPen PenLine;
PenLine.CreatePen(PS_INSIDEFRAME | PS_DOT, 1, pWnd->m_nclr);
pDC->SelectObject( &PenLine );
pDC->MoveTo( rect.right, rect.top);
pDC->LineTo( rect.right, rect.bottom);
BrushOver.DeleteObject();
PenLine.DeleteObject();
long s,e;
pWnd->GetSel( s,e);
CPoint pt, sPt, ePt;
COLORREF colorref = RGB( 255, 255, 255 );
colorref ^= pWnd->m_nclr; // 与背景色异或
int nSNum = pWnd->GetFirstVisibleLine(); // 可显第一行
int nLNum = pWnd->GetLineCount(); // 总行数
int nLVis = nLNum - nSNum;
CString sLNum;
for( int i=0; i<nLVis; i++)
{
sPt = pWnd->PosFromChar( s );
ePt = pWnd->PosFromChar( e );
pt = pWnd->PosFromChar( pWnd->LineIndex(nSNum+i) );
if( pt.y >= sPt.y && pt.y <= ePt.y ) MemDC.SetTextColor( colorref ); // 行号颜色
else MemDC.SetTextColor( pWnd->m_nclr);
sLNum.Format( _T("%4d"), nSNum+i);
MemDC.TextOut( 0, pt.y, sLNum , sLNum.GetLength() ); //绘制行号
}
//-------------------------------------------------------------------------------------------------
pDC->BitBlt(rect.left,rect.top,rect.Width(),rect.Height(),&MemDC,0,0,SRCCOPY);
MemDC.SelectObject( oldFont );
DeleteObject( hFont );
MemDC.DeleteDC();
pDC->DeleteDC();
delete pDC;
return 0;
}
return CallWindowProc(pWnd->WndProcOld, hWnd, uMsg, wParam, lParam);
}
void CExRichEdit::PreSubclassWindow()
{
// TODO: 在此添加专用代码和/或调用基类
long eventmask = GetEventMask() | ENM_PROTECTED | ENM_CHANGE;
SetEventMask( eventmask );
PostMessage( (UINT) EM_SETMARGINS , EC_LEFTMARGIN, (LPARAM)m_nweigth );
WndProcOld = (WNDPROC)SetWindowLong(this->GetSafeHwnd(), GWL_WNDPROC, (LONG)WndProcNew);
SetBackgroundColor( 0, m_bclr);
ExSetFont( m_cf );
// this->SetSel(charrange &cr );
CRichEditCtrl::PreSubclassWindow();
}