|
Is a crtical section a way of ensuring the your code runs synchrounsly as window message processing seems to take precedence in code execution
|
|
|
|
|
It ensures only one thread can go through that code path: see Critical Section Objects (Windows)[^].
ForNow wrote: window message processing seems to take precedence Not sure what you mean by that.
|
|
|
|
|
In Short, No!
Critical Sections are Synchronisation Objects, It is of use only if your project is multi threaded,ie Has More than One thread running in the One Program. Each thread of your program, will wait in front of a CriticalSection where you try to Enter It, until all other threads leave it. It is a communal comunication deal between threads in a program. One thread of a program will not allow another thread to run, until the section is released. Other programs can switch thread in the mean time.
The Nature and context of the question worries me! You seem to have to learn an awfull lot more before you are ready to discus critical sections
Bram van Kampen
|
|
|
|
|
No,
It is NOT, and I explained that already!
However, I also answered your other question, in quite a lot of detail. Before you can attempt to learn MFC Multi Threaded Programming, you will need to learn basic MFC Programming, and elements of the Windows SDK. MFC is a thin wrapper around the Windows SDK. Sometimes you need the real thing! Definitely needed in Multithreading.
Cannot Help it, You need to study more before we can help you.
Bram
Bram van Kampen
|
|
|
|
|
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.
|
|
|
|
|
cr/lf 0X0D0A is treated as 1 character for rich edit purposes
thanks
|
|
|
|
|
Really? I just tested (using VS2008) and it came out as two separate characters. Here's the code I used:
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
|
|
|
|
|
I was referring to richedit when determining the selection position
|
|
|
|
|
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
modified 9-Mar-16 11:41am.
|
|
|
|
|
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
|
|
|
|
|
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 that CR and LF 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
modified 9-Mar-16 12:22pm.
|
|
|
|
|
I have 16 pieces of text in the 4 line edit control any one of whom I could potentially replace
|
|
|
|
|
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
|
|
|
|
|
Sorry, but I am not sure what relevance that has to the counting of characters.
|
|
|
|
|
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
modified 9-Mar-16 21:08pm.
|
|
|
|
|
... and I don't think you meant to post this message to me.
|
|
|
|
|
|
Relevance?
"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
|
|
|
|
|
EM_GETSELTEXT is explicit
This message returns the number of characters copied, not including the terminating null character.
The call is terminated by the null character and if you have CR,LF they will count as characters
The return is a CHARACTER COUNT, if your edit box is unicode mode it still reflects the character NOT THE NUMBER OF BYTES.
Hence when providing a buffer you are best to use an array of TCHAR rather than a standard byte array to allow for size difference.
Also note when size a TCHAR array use _countof DO NOT use sizeof for the same reason. Standard unicode aware coding practice.
Several of the comments have confusion between CHARACTER and BYTE within the meaning of the windows API. No such confusion exists.
In vino veritas
modified 16-Mar-16 2:46am.
|
|
|
|