老师让在客户区实现文字输入,并且光标跟随移动
我的函数如下,光标是移动了,但以前的光标不消失啊!!
请大侠给我指点一下,我是菜鸟,所以请
void CCharView::OnDraw(CDC* pDC)
{
CCharDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
pDC->SetTextColor(fontdlg.GetColor());//获取字体对话框的颜色信息
oldfont=pDC->SelectObject(&cf);//选人获取的字体
CString str;
TEXTMETRIC tm;
CRect rectClient;
GetClientRect(&rectClient);
pDC->GetTextMetrics(&tm);
int i=pDoc->strchars.GetSize();
int ncount=rectClient.Width()/tm.tmMaxCharWidth;//计算客户区每行显示的字符数
int nline=1+i/ncount;//字符总行数
int hangliang;
//下面语句实现输入的时候换行
for(int m=0;m<nline;m++)
{
if(m==nline-1)
{
hangliang=i-(nline-1)*ncount;
}
else
hangliang=ncount;
for(int j=0;j<hangliang;j++)
{
str=pDoc->strchars.GetAt(j+m*ncount);
pDC->TextOut(j*tm.tmMaxCharWidth,16*m,str);
//关键!!!
::CreateCaret(m_hWnd,NULL,0,tm.tmHeight);
::ShowCaret(m_hWnd);
::SetCaretPos((j+1)*tm.tmMaxCharWidth,m*16);
}
}
那三个函数是我根据回的贴写上的,完全不明白用法,请你帮我完善好吗
我的函数如下,光标是移动了,但以前的光标不消失啊!!
请大侠给我指点一下,我是菜鸟,所以请
void CCharView::OnDraw(CDC* pDC)
{
CCharDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
pDC->SetTextColor(fontdlg.GetColor());//获取字体对话框的颜色信息
oldfont=pDC->SelectObject(&cf);//选人获取的字体
CString str;
TEXTMETRIC tm;
CRect rectClient;
GetClientRect(&rectClient);
pDC->GetTextMetrics(&tm);
int i=pDoc->strchars.GetSize();
int ncount=rectClient.Width()/tm.tmMaxCharWidth;//计算客户区每行显示的字符数
int nline=1+i/ncount;//字符总行数
int hangliang;
//下面语句实现输入的时候换行
for(int m=0;m<nline;m++)
{
if(m==nline-1)
{
hangliang=i-(nline-1)*ncount;
}
else
hangliang=ncount;
for(int j=0;j<hangliang;j++)
{
str=pDoc->strchars.GetAt(j+m*ncount);
pDC->TextOut(j*tm.tmMaxCharWidth,16*m,str);
//关键!!!
::CreateCaret(m_hWnd,NULL,0,tm.tmHeight);
::ShowCaret(m_hWnd);
::SetCaretPos((j+1)*tm.tmMaxCharWidth,m*16);
}
}
那三个函数是我根据回的贴写上的,完全不明白用法,请你帮我完善好吗
http://download.csdn.net/source/658570
int X, // horizontal position
int Y // vertical position
);//移动光标到指定位置
BOOL ShowCaret(
HWND hWnd // handle to window with caret
);//显示光标BOOL CreateCaret(
HWND hWnd, // handle to owner window
HBITMAP hBitmap, // handle to bitmap for caret shape
int nWidth, // caret width
int nHeight // caret height
);//创建光标,其中光标用位图表示
具体实例:// Load the application-defined caret resource.
hCaret = LoadBitmap(hinst, MAKEINTRESOURCE(120)); // Create a solid black caret.
CreateCaret(hwnd, hCaret, nWidth, nHeight);
// Adjust the caret position, in client coordinates.
SetCaretPos(x, y);
// Display the caret.
ShowCaret(hwnd);