Solved

Tedit caret and char position

Posted on 1997-05-26
4
604 Views
Last Modified: 2013-12-03
Hi there

I am making my own editor as an array of single line TEdit boxes.
I need to be able to move the caret (cursor position) from one line to
another when the user presses the down arrow key.
The functions GetCaretPos and SetCaretPos work correctly as expected
however when the user presses a key for new input it appears in the Edit
box
at the last position that the caret was at. Not where I have the caret
positioned!!
I am using a system font (all characters the same size).

e.g. Say I have the caret between the Y and X on line 2 below. Then I use
the
mouse and go to a position between  D and E on line 1. If I press down
arrow
I can position the caret between the V and U as required. If I now enter a
character
Say Q it will appear between the Y and X  NOT between the V and U that I
want !!

Line 1       ABCDEF
Line 2       ZYXVUW

How do I get around this problem?

Below is my MoveCursorDown function

void TMyView::MoveCursorDown(int iCurrentEditCntIdx)
{
  TPoint  point;
  int iTemp;

  if(iCurrentEditCntIdx < iNbrEditControls - 1)
  {
    EditCnt[iCurrentEditCntIdx]->GetCaretPos(point);
    EditCnt[iCurrentEditCntIdx + 1]->SetFocus();
    EditCnt[iCurrentEditCntIdx + 1]->SetCaretPos(point);
  }
}


Thanks in anticipation of a reply

David Hicks.
0
Comment
Question by:DHICKS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
NickRepin earned 150 total points
ID: 1397658
You should use Get/SetSelection, not Get/SetCaretPos:

uint start,end;
EditCnt[iCurrentEditCntIdx]->GetSelection(start,end);
EditCnt[iCurrentEditCntIdx + 1]->SetFocus();
EditCnt[iCurrentEditCntIdx + 1]->SetSelection(end,end);
 
0
 

Author Comment

by:DHICKS
ID: 1397659
GetSelection(start,end);
Returns the starting (startPos) and ending (endPos) positions of the currently selected text. By using GetSelection in conjunction with GetSubText, you can get the currently selected text.

I have no selected text !!! Therefore I have no startPos or EndPos.

bool SetSelection(uint startPos, uint endPos);

Forces the selection of the text between the positions specified by startPos and endPos, but not including the character at endPos.  I don't want to select text !!!  I just want to move the caret (cursor) and entry position for new text !!
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1397660
Did you try it?
If there is no selection, GetSelection returns startPos==endPos==current caret position.
SetSelection(pos,pos) sets caret at pos position.
Please, refer to Win32 API.
0
 

Author Comment

by:DHICKS
ID: 1397661
Microsofts Get/SetSelection is poorly documented.
It works as you say even if you have no text selected.
Thanks
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question