Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CEdit - Highlight text

Posted on 2004-04-16
7
Medium Priority
?
1,738 Views
Last Modified: 2013-11-20
I have an CEdit control and I would like to highliht the text after the user press return. My code delete the text and doesn't highlight it. Any suggestions?

Code snippet:

BOOL CMyRecView::MyFunction()
{
   ....
   myEditCtrl.SetFocus();
   myEditCtrl.SetSel(0,-1)
    ....
}

I have tried :
  ((CEdit*)GetDlgItem(IDC_MY_EDIT))->SetSel(0, 2);
which remove the first two characters of the text instead of highlight.

Thanks inadvance.
0
Comment
Question by:DBOTMA
[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
7 Comments
 
LVL 4

Accepted Solution

by:
caner_elci earned 800 total points
ID: 10840533
myEditCtrl.SetSel( 0, -1 )  or myEditCtrl.SetSel( 0, 65535 ) would perfectly work.. But there may be a problem with focus or keyboard handling.. you say you wanna select the text when user presses Enter key, for example, when the user presses Enter, you get the message, select the text, then message bubbling continues and deselects the text.. so, check it out, clear virtual key state in WM_KEYDOWN and WM_KEYUP message handlers.. that would stop sending Enter key to MFC's CEdit and stuff..
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 10840569
Try this:

  myEditCtrl.SetFocus();
  myEditCtrl.PostMessageEM_SETSEL, 0, -1);
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 10840573
Correction:

 myEditCtrl.SetFocus();
 myEditCtrl.PostMessage(EM_SETSEL, 0, -1);
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 23

Expert Comment

by:Roshan Davis
ID: 10841155
Hi Alex,
SendMessage right?

Rosh :)
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 10841525
PostMessage. I don't see how MyFunction is called and my guess is that some keyboard message is not handled yet and it clears editbox.
0
 

Expert Comment

by:shetlandbob
ID: 10842312
Have you set the "Want Return" to true in the editbox properties? this may have an effect?

I have a dialog control with control variable "editBoxControl", the following code will select the entire string.

  CEdit* edit;
  edit = &editBoxControl;
  edit->SetSel(0,-1,false);


I wonder if the problem may be that when you press enter the text box is being cleared, and so there is nothing to highlight? thats the first thing I would check?

How are you capturing the return?
0
 

Author Comment

by:DBOTMA
ID: 10856089
BOOL CMyRecView::PreTranslateMessage(MSG* pMsg)
{
    if (pMsg->message == WM_KEYDOWN &&
         pMsg->wParam == VK_RETURN )
    {
       
         ...some code......
       
         return TRUE;                   //I ADD THIS RETURN WHICH FIXED MY PROBLEM
    }

    return CRecordView::PreTranslateMessage(pMsg);
}
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

604 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