|
sunilkumar.d wrote: Can I have two worker threads with the
priority set to THREAD_PRIORITY_HIGHEST
Technically, Yes. In the real world if you do this your customers will not like you. You will hog the entire system, probably even on dual core systems. Don't do this, there is really no need unless you're writing some kind of real time control system and Windows is the wrong place to be doing that or unless you're intending to replace a core windows driver.
sunilkumar.d wrote: Is there any problem , if one thread created with "CreateThread" and
one with "AfxBeginThread"?.
I can't remember off the top of my head which API call AfxBeginThread ends up using but I'm guessing it's _begin_thread from the CRT. If you mix these threads with threads started with CreateThread then don't use Thread specific Locales or TLS in your CreateThread Thread and avoid passing objects beetween them unless you're in full control of those object, i.e. they're entirely your code and your data, no Window handles, streams or objects with base classes buried in the Windows headers. If you do that you should be fine but I've no idea why you would want to.
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|
|
sunilkumar.d wrote: In My VC application,Can I have two worker threads with the
priority set to THREAD_PRIORITY_HIGHEST.?
Why don't you try? Be aware about this info [^].
sunilkumar.d wrote: and Is there any problem , if one thread created with "CreateThread" and
one with "AfxBeginThread"?
Why do you need the above?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
sunilkumar.d wrote: Can I have two worker threads with the
priority set to THREAD_PRIORITY_HIGHEST.?
Yes, you can.
But chances that you are trying to solve a problem the wrong way is very close to 100%. Manipulating thread priorities is almost always wrong and is often used to disguise performance bottleneck that should be solved on the design level.
Explain what you're trying to do and why you think you need to increase the priority level of the threads. Most likely there is a better solution.
sunilkumar.d wrote: Is there any problem , if one thread created with "CreateThread" and
one with "AfxBeginThread"?.
If you're using MFC, and you are because otherwise AfxBeginThread() wouldn't be declared, you have to use AfxBeginThread() due to inner workings of the framework.
Read more about threads here[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Thanks for the immediate response.
Actually i have two threads.
One runs script file, which consists of some commands.
Each command to be sent to hardware via serial port and receive the result.
The other thread is serial port read thread.
If the Threadpriority is normal , my script file runs a bit slowly.
Thats why I want to increase the priority.
Regards,
Sunil Kumar
|
|
|
|
|
sunilkumar.d wrote: Actually i have two threads.
One runs script file, which consists of some commands.
Each command to be sent to hardware via serial port and receive the result.
The other thread is serial port read thread.
If the Threadpriority is normal , my script file runs a bit slowly.
Have you considered why the script runs slowly?
What you do by increasing the thread priority is saying "when this thread runs it's more important than other threads and should not be disturbed". My point is that if this is a problem, your thread that executes the script is interrupted by other threads. If that's you problem, have you considered why it is so?
Have you by any chance written a call to ::Sleep() somewhere? If so, that is most likely your source of problem. Read the article I linked to in my previous post followed by this[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Thanks a lot Roger
Regards,
Sunil Kumar
|
|
|
|
|
|
Stingray Studio is used to create a SECCustomStatusBar to display a toolbar in my application. The code is written in C++ using MFC, but I want to prevent the user from having the ability to resize the toolbar. The toolbar is to automatically resize when the application is not maximized and the user sets the application's window size to his/her preference.
Can this toolbar remove the ability for the operator to click, hold, and drag the bottom right corner of this toolbar to resize it?
|
|
|
|
|
Handle WM_MINMAXINFO. I think you should give the same number for min and for max, so there is no range for the user to change size.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Ive managed to read a whole text file into a string. The text file has 200 lines. I wanna read a specific line from the string, how can i do it? I tried getline(); but the problem is that it reads a line rite from the starting position of the string but not from a specific point.
nOmI
|
|
|
|
|
Well, you may read a line at time or may move a pointer inside the buffer.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
kindly would u like to elaborate ur reply bcoz im a bit new in C++ programming.
nOmI
|
|
|
|
|
Instead of reading the whole file at once, read it one line at a time until you get to the desired line. Otherwise, you'll need to parse the buffer (a line will by separated by a \r\n pair).
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Thank you for elaborating my lazy answer.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: Well, you may read a line at time or may move a pointer inside the buffer.
And you got 1 vote at time but now you get a pointer of 5.
|
|
|
|
|
Thank you, pal.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Did you try with CFile::Read ?
|
|
|
|
|
This function takes two parameters
1. first one is the path of file to be read.
2. second parametrs is the line number you want to get from the file.
CString GetLine(CString sFileName, int nLineNumber)
{
CStdioFile Inputfile;
CString sLine = _T("");
CFileException FileExc;
UINT nOpenFlags = CFile::modeRead;
if (!Inputfile.Open(sFileName, nOpenFlags, &FileExc)) {
FileExc.ReportError();
return "Error";
}
while(Inputfile.ReadString(sLine) && nCount < nLineNumber){
nCount++;
}
Inputfile.Close();
return sLine;
}
|
|
|
|
|
You may open the text file using "CStdioFile",
the read each line using ReadString().
Actually ReadString () reads each line at a time !!
|
|
|
|
|
Hi,
I have Parent and child windows, when i create new child windows it adds them,
but when i move them or bring one from the back it doesnt redraw properly,
i was wondering if there was a way i could redraw those windows properly,
and if that doesnt work im assuming that its probably cause each child is
sharing the same WndProc, is there a way to make the WndProc and array...
|
|
|
|
|
Are you returning the correct value when processing WM_PAINT messages?
|
|
|
|
|
well as im fairly new to child forms I dont know what value i should be returning
ive tried
UpdateWindow(hWnd) in case WM_ACTIVATE:
but that didnt really do anything,
its when i put another child window infront of another and click on the one behind it doesnt redraw and half the window is missing
i really dont ahve a clue how to sort that
|
|
|
|
|
|
well before that i found a semi way of sorting my problem but it caused tremendous flickering
case WM_PAINT:
{
HDC hdc;
PAINTSTRUCT ps;
hdc = BeginPaint( hWnd, &ps );
InvalidateRect(hWnd, NULL, TRUE);
UpdateWindow(hWnd);
EndPaint( hWnd, &ps );
}
return 0;
break;
i even tried
but im still having no luck
|
|
|
|
|
No no no!
The call to InvalidateRect() triggers the generation of a WM_PAINT message so that definately needs to come out.
UpdateWindows() does the same but the window procedure is called rather than letting the message run through the normal message queue so that call also needs removing.
The code you've shown doesn't actually do anything so I'm not surprised the window doesn't change on screen. Is that it or have you removed the painting code to make things clearer?
|
|
|
|