给CEditView加行号解决方案
给CEditView加行号
我用的VS2012,想给编辑器加上行号。。代码是在网上找的,我把原来代码中的wmemset、wsprintfW和TextOutW改成了memset、wsprintf和TextOut,因为一直提示“TCHAR类型的实参和LPWSTR类型的形参不符”。。改完后其他错误没了,只有下面代码33行和37行的L显示有错误,IntelliSense: "const wchar_t *" 类型的实参与 "LPCSTR" 类型的形参不兼容。。L"*"和L"%d"是什么意思啊?怎么改?
------解决思路----------------------
我喜欢用_T
TextOut(hdcView, 0, i, _T("*"), 1);
------解决思路----------------------
楼上正解,顶一个
我用的VS2012,想给编辑器加上行号。。代码是在网上找的,我把原来代码中的wmemset、wsprintfW和TextOutW改成了memset、wsprintf和TextOut,因为一直提示“TCHAR类型的实参和LPWSTR类型的形参不符”。。改完后其他错误没了,只有下面代码33行和37行的L显示有错误,IntelliSense: "const wchar_t *" 类型的实参与 "LPCSTR" 类型的形参不兼容。。L"*"和L"%d"是什么意思啊?怎么改?
RECT rectWin;
this->GetClientRect(&rectWin);
UINT uViewWidth = cxCharWidth * 4;
UINT uViewHeight = rectWin.bottom;
// Count Visible Line
int nViewLineMin = this->GetEditCtrl().GetFirstVisibleLine() + 1;
int nViewLineMax = (uViewHeight / cyCharHeight) + nViewLineMin;
// Get DC
CClientDC dc(this);
HDC hdcView = ::CreateCompatibleDC(dc.GetSafeHdc());
HBITMAP hbmScaled = CreateCompatibleBitmap(dc.GetSafeHdc(), uViewWidth, uViewHeight);
HGDIOBJ hbmOld = SelectObject(hdcView, (HGDIOBJ)hbmScaled);
// Fill Rect
RECT rectLine;
rectLine.left = rectLine.top = 0;
rectLine.bottom = uViewHeight;
rectLine.right = uViewWidth;
FillRect(hdcView, &rectLine, (HBRUSH) (COLOR_WINDOW + 1));
// Draw the Number
static TCHAR strNumber[7];
memset(strNumber, 0, 7);
int nLeft = uViewWidth - 3;
int nBufferSize = 0;
SetTextAlign(hdcView, TA_RIGHT);
int nCurrentLine = this->GetEditCtrl().LineFromChar(-1) + 1;
SetTextColor(hdcView, RGB(41,41,41));
for (UINT i = 1; i <= uViewHeight ; i += cyCharHeight)
{
if(nCurrentLine == nViewLineMin)
{
SetTextAlign(hdcView, TA_LEFT);
SetTextColor(hdcView, RGB(255,0,0));
TextOut(hdcView, 0, i, L"*", 1);
SetTextColor(hdcView, RGB(41,41,41));
SetTextAlign(hdcView, TA_RIGHT);
}
nBufferSize = ::wsprintf(strNumber, L"%d", nViewLineMin++);
TextOut(hdcView, nLeft, i, strNumber, nBufferSize);
}
// Draw the Line
// Initialize the pen's brush.
LOGBRUSH lb;
lb.lbStyle = BS_SOLID;
lb.lbColor = RGB(255,0,0);
lb.lbHatch = HS_CROSS;
// Create a pen to darw line
HPEN hPen = ExtCreatePen(PS_GEOMETRIC | PS_DASHDOTDOT, 1, &lb, 0, NULL);
HGDIOBJ hOldPen = SelectObject(hdcView, (HGDIOBJ)hPen);
MoveToEx(hdcView, uViewWidth - 1, 0, 0) ;
LineTo(hdcView, uViewWidth - 1, uViewHeight);
// Restore the old Pen
SelectObject(hdcView, hOldPen);
DeleteObject(hPen);
// Draw the Image To Client View
BitBlt(dc.GetSafeHdc(), 0, 0, uViewWidth, uViewHeight, hdcView, 0, 0, SRCCOPY);
// Restore the old Bitmap
SelectObject(hdcView, hbmOld);
DeleteDC(hdcView);
DeleteObject(hbmScaled);
------解决思路----------------------
我喜欢用_T
TextOut(hdcView, 0, i, _T("*"), 1);
------解决思路----------------------
楼上正解,顶一个