用GetCursorPos(&pt)可获得当前光标的位置,但怎样像一般编辑器那样,随时获得光标的位置(行列),并将其显示在状态栏上?
解决方案 »
- 提问,如何在EXE安装包里面嵌入插件软件
- 无法打开包含文件 stdafx.h
- PC的USB端口与盘符对应问题?
- 按钮为什么会一直跑?
- 在对话框上添加了一个Button,设为Bitmap和OwnerDraw风格。但是不能为这个Button添加CBitmap的成员变量?
- www.java.sun.cn 上有没有JSP教程?我找不到?谢谢,JAVA版面的人气太少,所以在这里问。
- 各位,帮帮我,我不明白为什么我的窗体使用了MSFLEXGRID控件,就不能打开呢?
- 请教大家!!!!
- 关于ListView的问题
- dll如何暴露他的接口(如何调用他的对象,类)(VC++)
- VC操作数据库时说'CRecordSet' : undeclared identifier
- 文挡视图在哪里?
CPoint pt;
GetCursorPos(&pt);
我按照 ymbymb(毛病大哥) 的用法,结果获得的还是鼠标指针的位置。
void CMyView::GetCurrentPosition(int& iLine, int& iCol)
{
CRichEditCtrl& theCtrl = this->GetRichEditCtrl();
// 获取当前行号
iLine = theCtrl.LineFromChar(-1); int nLineStartPos = theCtrl.LineIndex(); long nSelStart, nSelEnd;
theCtrl.GetSel(nSelStart, nSelEnd); iCol = nSelStart-nLineStartPos+1;
}
{
……
}void CStatusBarView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
LPPOINT lp=NULL;
BOOL b=::GetCursorPos(lp);
CString str;
CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
CStatusBar* pStatus=&pFrame->m_wndStatusBar;
if(!b)
str="";
else
str.Format("Ln %d, Col %d",lp->x,lp->y);
if (pStatus){
pStatus->SetPaneText(0,str);
}
……
}
以上是我用的代码,运行过程中,b一直为0;
要获取关标的位置,可以用我说的办法。