Non display characters for selection count
-
Hi I have 3 rows of text in my rich edit. At the end of each line I move a carriage return line feed, to force a new line /r/n. Do these 2 bytes count as 2 characters when determining the count for the selection Thanks
-
The documentation at EM_GETSELTEXT message (Windows)[^] does not explicitly say whether it does, or does not. But a simple test should prove it one way or another.
-
Really? I just tested (using VS2008) and it came out as two separate characters. Here's the code I used:
// the control contained the text: David\r\n
void CMyDialog::OnClickedOk()
{
int len = m_richedit.GetWindowTextLength();
TRACE(_T("Len = %d\n"), len);CString text; m\_richedit.GetWindowText(text); TRACE(\_T("Text = %s\\n"), text); for (int x = 0; x < len; x++) TRACE(\_T("%#x\\n"), text\[x\]);
}
The resulting output looked like: Len = 7 Text = David 0x44 0x61 0x76 0x69 0x64 0xd 0xa
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Really? I just tested (using VS2008) and it came out as two separate characters. Here's the code I used:
// the control contained the text: David\r\n
void CMyDialog::OnClickedOk()
{
int len = m_richedit.GetWindowTextLength();
TRACE(_T("Len = %d\n"), len);CString text; m\_richedit.GetWindowText(text); TRACE(\_T("Text = %s\\n"), text); for (int x = 0; x < len; x++) TRACE(\_T("%#x\\n"), text\[x\]);
}
The resulting output looked like: Len = 7 Text = David 0x44 0x61 0x76 0x69 0x64 0xd 0xa
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
So you are taking whatever text is already present in the edit control and adding CRLF to the end of it? I'm trying to ascertain if this is an appending issue (I've seen some weird ways in which folks try to append to an edit control) or something else.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
So you are taking whatever text is already present in the edit control and adding CRLF to the end of it? I'm trying to ascertain if this is an appending issue (I've seen some weird ways in which folks try to append to an edit control) or something else.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
For Crlf which is 2 bytes in memory aka the buffer I count 1 for determining the selection count
But are taking whatever text is already present in the edit control and adding CRLF to the end of it?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
But are taking whatever text is already present in the edit control and adding CRLF to the end of it?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
The text is included in the count for the cold I count as 1 character for porpouses of selection not 2 bytes
I misunderstood what you were attempting. You are using the
GetSel()
method to get the starting and ending positions of the control's selected text, correct? I tried that and with all of the text in the control selected, I found thatCR
andLF
are (like I would expect) considered two separate characters. In other words, start = 0 and end = 7."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
I misunderstood what you were attempting. You are using the
GetSel()
method to get the starting and ending positions of the control's selected text, correct? I tried that and with all of the text in the control selected, I found thatCR
andLF
are (like I would expect) considered two separate characters. In other words, start = 0 and end = 7."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
I use the Streamout api to get whatever is in the control the edit control has 4 lines at the end of each line is X0D0A CRLF I have to count the 0X0D0A as 1 character for the SetSel api when determining the pos I want to use in the selection thanks
So your end game is just to programmatically insert/replace some characters some place in the edit control?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
The text is included in the count for the cold I count as 1 character for porpouses of selection not 2 bytes
-
So your end game is just to programmatically insert/replace some characters some place in the edit control?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
The documentation at EM_GETSELTEXT message (Windows)[^] does not explicitly say whether it does, or does not. But a simple test should prove it one way or another.
Well, This is Familiar, in particular with the multi threaded question you asked earlier. MFC cannot realy handle multiple threads. No one seems to know why, I have asked the question before. At any rate, the only way MFC objects can communicate between threads is with the Old Fashioned WDK Kernel Function ::SendMessage(hWnd, Param1,Param2); In MFC you create your Message as WM_USER+(X), Create a Message Handler, and, manually add it to the message map. Any attempt to call an MFC Object from a different thread than in which it was created always ultimately lead to failure. The Symptoms are: Works, Add a Virtual Function: It stops Working Hope this helps
Bram van Kampen
-
I just tried this with an ordinary Edit control, and it returns both CR LF in the count.
You did not try this in a Multi Threaded Environment, as explained in the question previous of this :)
Bram van Kampen
-
You did not try this in a Multi Threaded Environment, as explained in the question previous of this :)
Bram van Kampen
-
Well, This is Familiar, in particular with the multi threaded question you asked earlier. MFC cannot realy handle multiple threads. No one seems to know why, I have asked the question before. At any rate, the only way MFC objects can communicate between threads is with the Old Fashioned WDK Kernel Function ::SendMessage(hWnd, Param1,Param2); In MFC you create your Message as WM_USER+(X), Create a Message Handler, and, manually add it to the message map. Any attempt to call an MFC Object from a different thread than in which it was created always ultimately lead to failure. The Symptoms are: Works, Add a Virtual Function: It stops Working Hope this helps
Bram van Kampen
-
Well, This is Familiar, in particular with the multi threaded question you asked earlier. MFC cannot realy handle multiple threads. No one seems to know why, I have asked the question before. At any rate, the only way MFC objects can communicate between threads is with the Old Fashioned WDK Kernel Function ::SendMessage(hWnd, Param1,Param2); In MFC you create your Message as WM_USER+(X), Create a Message Handler, and, manually add it to the message map. Any attempt to call an MFC Object from a different thread than in which it was created always ultimately lead to failure. The Symptoms are: Works, Add a Virtual Function: It stops Working Hope this helps
Bram van Kampen
Relevance? :confused:
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Sorry Richard, No I Did Not intend this for you. This topic became a Sort of a Labyrinth. The Original Person is evidently out of his/her depth! (S)he is still hammering the subject I see. I try to help, as we all do, but can get frustrated when good advise is ignored, as, I am sure you do to. Regards, Bram. :( ;) ;)
Bram van Kampen