Displaying Cursor Position in the Status Bar
Posted
by Edward Duffy
on January 25th, 2001
In many applications in which you use CEditView and CRichEditView classes
it may be convineinent to let you user know the position of the cursor,
much like the IDE in Visual C++. After some quick searching through
MSDN and the CG discussion forms, I found out how easy it would be to add
this feature.
afx_msg void OnUpdateCurPosIndicator(CCmdUI *pCmdUI);
ON_UPDATE_COMMAND_UI(ID_INDICATOR_CURPOS,
OnUpdateCurPosIndicator)
void CMainFrame::OnUpdateCurPosIndicator(CCmdUI *pCmdUI)
{
CString strCurPos;
int nLineNum, nColNum;
int nSelStart, nSelEnd;
// you're going to have to get a pointer
// to the edit control in the view
m_wndEditCtrl->GetSel(nSelStart, nSelEnd);
nLineNum = m_wndEditCtrl->LineFromChar(nSelStart);
nColNum = nSelStart - m_wndEditCtrl->LineIndex(nLineNum);
strCurPos.Format(ID_INDICATOR_CURPOS,
nLineNum+1,
nColNum+1);
m_wndStatusBar.SetPaneText(
m_wndStatusBar.CommandToIndex(ID_INDICATOR_CURPOS),
strCurPos);
}
And that's about it. You can download a sample project if you wish, altough there's nothing special in it, really. Only thing that may be of any use is getting that pointer to the edit control.
Downloads
Download demo project - 38 KbDownload source - 2 Kb

Comments
There are no comments yet. Be the first to comment!