Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't get selection back in edit control

Status
Not open for further replies.

wduty

Programmer
Jun 24, 2000
271
US
I have a program where I allow the user to determine the length of the selected text in an edit control. The user makes a menu selection which calls a function which gets the menu selection length (or the length of text in the whole control if there is no selection). The length then shows up in a MessageBox.

This works ok but when the MessageBox opens, the selection is lost. I tried to reset the selection immediately afterwards but it doesn't work. Here's the function:

void TextLength(HWND hWnd)
{
char pTemp[10];
ULONG len;
ULONG start;
ULONG end;
SendMessage(hWnd, EM_GETSEL, (WPARAM) &start, (LPARAM) &end);
if ((len = end - start) == 0) len = GetWindowTextLength(ghEdit); //if no selection, count all
ltoa(len, pTemp, 10);
MessageBox(ghEdit, pTemp, "Length of Text", MB_OK | MB_APPLMODAL);
SendMessage(hWnd, EM_SETSEL, (WPARAM) start, (LPARAM) end);
}

Thing is, if I comment out the MessageBox line, the EM_SETSEL message sends ok (I can tell because if I change it to something like: SendMessage(ghEdit, EM_SETSEL, (WPARAM) 0, (LPARAM) end); I can see the selection change). as long as I don't open a MessageBox. I tried a bunch of variations on both the MessageBox flags/HWNDS etc. as well as successive MessageBoxes to verify that the start and end values are still there. However, nothing works. Maybe I have to send an additional message to the main window? Any suggestions appreciated.

--Will Duty
wduty@radicalfringe.com

 
solved: I just made it a modeless dialog and that seemed to solve the problem.
--Will Duty
wduty@radicalfringe.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top