|
Ah, geez.
I'm going to go put my head in the sand. Gimme 10 minutes.
Sincerely, thanks for the help!
|
|
|
|
|
Like2Byte wrote: I'm going to go put my head in the sand.
Haha - that's the hard way to code!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: that's the hard way to code!
No, that's the new age way to code. Having your head in the sand, or other equally dark places, is fine as long as you keep typing!
led mike
|
|
|
|
|
Hi
I have a basic question about classic message loop of Win32 programs.
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
Why doesn't this message loop take all processor time?
I also increment the priority level:
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
In another MFC application i created a new thread with infinite loop( I mean in function there is only "infinite while loop", as classic win32 message loop) and also set priority to THREAD_PRIORITY_HIGHEST. That loop blocked all other threads. But why doesn't win32 message loop block other threads?
Thanks.
|
|
|
|
|
sawerr wrote: Why doesn't this message loop take all processor time?
Because GetMessage() blocks until a message is available in the queue.
If you want it to spin and consume nearly all of the CPU time for a core,
use PeekMessage() instead of GetMessage().
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: Because GetMessage() blocks until a message is available in the queue.
Is this something like that:
GetMessage()
{
while(true)
{
if(queue == EMPTY)
Sleep(100);
}
}
|
|
|
|
|
We all would hope the Windows kernel is event driven, and not polling all the time.
|
|
|
|
|
OK, but how can its pseudo-code be?
|
|
|
|
|
Hi,
GetMessage() {
if(queue == EMPTY) {
queue.AddWaiter(currentThread);
SwitchToForemostReadyThread();
}
return queue.RemoveMsg();
}
PutMessage(Message msg) {
queue.AddMsg(msg);
if(queue.HasWaitersWithHigherPriority(myPriority)) {
Thread thread=queue.RemoveWaiter();
SwitchToThread(thread);
}
}
Not a single busy-wait or polling loop!
The heart in the matter is the SwitchTo...Thread() methods save the current thread
state on its stack, and load another thread's state from its stack, effectively
performing a "thread switch".
|
|
|
|
|
sawerr wrote: Is this something like that
No, not at all.
Within GetMessage(), there's something like
GetMessage(...)
{
WaitForSingleObject(QueuedMessageEvent)
return message to caller
}
If the event isn't signalled when GetMessage() is called,
WaitForSingleObject() puts the thread in a "wait state", a state
where the thread is almost completely suspended - it uses VERY little
CPU time.
Using Sleep as you've shown is extremely inefficient.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for answers.
|
|
|
|
|
Hi I am new to mfc vc++,
In my application i want to have the uneditable combobox via code...
I dont want to use the dropdown list as a solution,
Please suggest me any other alternatives for this....
Thanks in advance
|
|
|
|
|
hariakuthota wrote: I dont want to use the dropdown list as a solution,
Why?
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]
|
|
|
|
|
I dont want to use the dropdownlist because in my application based on the combobox selection another combo box has to be populated with the first combobox seleted item.
EX: if i click "alphabets"
i have to set the other combobox to this value,
and i am not able to use the m_combobox2.setwindowtext() and also
SetDlgItemText(idc_combobox2,"string");
|
|
|
|
|
Try using SelectString instead of trying to set the text area directly.
Judy
|
|
|
|
|
tried but thats not working properly...
|
|
|
|
|
Possible you've to try better.
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]
|
|
|
|
|
As CPallini implies, the function does work correctly. You've done something wrong.
What does "it doesn't work" mean - with no code, we can't guess. Does the string you're trying to set exist in the second combo box?
Judy
|
|
|
|
|
I dont want to use the dropdownlist because in my application based on the combobox selection another combo box has to be populated with the first combobox seleted item.
EX: if i click "alphabets"
i have to set the other combobox to this value,
and i am not able to use the m_combobox2.setwindowtext() and also
SetDlgItemText(idc_combobox2,"string"); if i use the dropdownlist
|
|
|
|
|
Hi i am new to the concepts of mfc..
in my application i want to change the backgroung color of the button through ctlcolor for that i am ticking the option owner draw for the button.when i try to run the application i am getting abort error..
can anybody please suggest me the reason for this???
Thanks in advance...
|
|
|
|
|
hariakuthota wrote: can anybody please suggest me the reason for this???
The debugger can (for free!).
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: The debugger can (for free!)
Who is that guy? Does he make house calls?
|
|
|
|
|
Luc Pattyn wrote: Who is that guy?
Girl my friend, girl. And it's lovely to have a break with her (or simply a watch).
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]
|
|
|
|
|
Aha. That could be the reason why people tend to spend so much time debugging...
But then I wonder why they ask for help on sites like this one
|
|
|
|
|
Possibly because girls drive you crazy, after a while...
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]
|
|
|
|