|
it's updated every ~15ms to 50ms (depending on the version of Windows). so, it is measuring time in the ms range, but the difference between two consecutive calls will never be less than ~15ms.
QueryPerformanceCounter is much more accurate.
|
|
|
|
|
How will I use QueryPerformanceCounter as a way of sampling data? I will still need a thread to loop a function call. And in that function will check QueryPerformanceCounter. But if posting a message takes longer than 6ms. Then QueryPerformanceCounter can only be as accurate as that.
Can you provide a code sample? Im fairly new to windows programming. I am basically learning from sample code that I find online. Thanks.
|
|
|
|
|
acerunner316 wrote: I will still need a thread to loop a function call. And in that function will check QueryPerformanceCounter.
right
acerunner316 wrote: But if posting a message takes longer than 6ms. Then QueryPerformanceCounter can only be as accurate as that.
right
maybe this article can help... scroll down to the bottom for a message-loop / QueryPerfCounter sample.
|
|
|
|
|
sorry, i'm still having trouble understanding. In code sample at the link you gave, I can see that the function is monitoring for any messages and checking for the time. But there is the message being generated from, and how?
|
|
|
|
|
acerunner316 wrote: But there is the message being generated from, and how?
the message comes from code outside the loop. this is pretty close to an old-style C Windows message loop. Windows is passing messages (button down, repaint, keydown, etc) to the application, which the app grabs, when it sees one, and starts processing with that Peek/Translate/DispathMessage bit - other code is responsible for handling the specific msgs. otherwise, every 40ms, the app does a run through its Render/Move/etc stuff, then goes back to looking for messages.
|
|
|
|
|
Isn't this similar to what I'm already doing, posting messages every 10ms? Because what I'm doing is posting the message repeatedly in a loop every 10ms. And then I have a function mapped to handle that message ON_MESSAGE(WM_UPDATE_DATA, OnUpdateData) . So the only difference I see is instead of using ON_MESSAGE, I will have my own function that loops to check for the message posted an respond to it. Is this right? Will this make the difference of the 6ms delay? Would I have to post this message like every 1ms in order to get the 1ms resolution?
|
|
|
|
|
acerunner316 wrote: Isn't this similar to what I'm already doing, posting messages every 10ms?
pretty much. but Sleep simply isn't that accurate. Sleep uses the system clock, which has a resolution closer to 15ms per tick in most modern versions of Windows. and, it's entirely possible for your sleeping thread to get preempted by another thread, further delaying its awakening.
i'm not sure what the overhead in PostMessage / ON_MESSAGE amounts to. but they're asynchronous anyway; apps respond to messages when they get around to it, not the instant they appear in their message. the time from PostMessage to the actual response is (i believe) indeterminate.
|
|
|
|
|
Chris Losinger wrote: pretty much. but Sleep simply isn't that accurate. Sleep uses the system clock, which has a resolution closer to 15ms per tick in most modern versions of Windows. and, it's entirely possible for your sleeping thread to get preempted by another thread, further delaying its awakening.
In that case, what do I use to loop posting of a message?
|
|
|
|
|
honestly, i don't know. Windows really isn't a real-time OS, and as far as I know, there's not a lot of high-level support for the kind of timing precision you seem to want. maybe you could check an open source game or audio application (ex. Audacity) that you could plunder for ideas.
|
|
|
|
|
|
acerunner316 wrote: I am using Sleep(10) in my thread to post a windows message every 10ms.
Sleep(10) doesn't sleep your thread fro 10 ms, as windows is not realtime system... actually it sleep time range between 10 ms to 54 ms depending on current load on the system and processor speed
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
Generally Windows NT and later have a timer interrupt of 10ms. However the HAL for some systems has set it to use 15ms. This means you can't sleep for less than that amount using the timeouts for Sleep() and Wait...() calls.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
1. Are you sure your function which is posting message takes '0'ms to execute ?
I raise this question because, if your calling code has a lot to do and then sleep 10 ms, the interval between subsequent calls would be
(Sleep time + Time taken to execute other part of the function).
If you are very specific about the response time, i dont think post message is the right way to address such issuesbecause the latency of the response is not guaranted.
You can use Events or a Semaphore-give-release technique to decrease the latency further.
but the technique you need to choose depends on your applcation.
Haribabu.
|
|
|
|
|
I don't know if it takes 0ms, but there is nothing else to my code other than repeatedly posting messages.
UINT CNOx1000MonitorDlg::FThreadLoop (LPVOID PptrToClass)<br />
{<br />
CMainWindowDlg *LptrClass = static_cast<CMainWindowDlg *>(PptrToClass);<br />
HWND *ptrWindowHandle = new HWND;<br />
*ptrWindowHandle = LptrClass->GetSafeHwnd();<br />
<br />
while(LptrClass->mbolThreadExecute)<br />
{<br />
::PostMessage(*ptrWindowHandle, WM_UPDATE_CONTROLS, 0, 0);<br />
::Sleep(10);<br />
}<br />
delete ptrWindowHandle;<br />
return 0;<br />
}
|
|
|
|
|
acerunner316 wrote: but 6ms delay is still way too slow
To get an understanding of how time works read Time is the Simplest Thing[^]
I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:
|
|
|
|
|
I've been looking at Microsoft's Expression Blend[^] the past couple of days and have read this article : .NET 3.0 WPF Tools && Examples[^].
We currently have a legacy MFC based application that does a lot of GDI rendering. What I would like to be able to do is embed an Expression Blend composition within our application and dynamically control the properties of the rendering through the wrapping app.
E.g. The Expression Blend composition is showing a red car rotating and the user chooses blue from our app, I'd like to dynamically change the render to blue.
Has anyone looked at embedded any XAML based creations within their own legacy MFC based apps?
Thanks in advance.
-- modified at 16:10 Thursday 4th January, 2007
Looks like Nish may have done some work in this area?
|
|
|
|
|
can someone explain what im doiing wrong here:
<br />
HBRUSH backBrush = ::CreateSolidBrush(RGB(pLevels->frequency[0][0],0,0));<br />
<br />
HDC memDC = CreateCompatibleDC ( hdc );<br />
HBITMAP bitmap1 = CreateCompatibleBitmap(memDC,prc->left,prc->bottom);<br />
HBITMAP oldBitmap = SelectObject(memDC,bitmap1);<br />
<br />
::FillRect(memDC,prc,backBrush);<br />
::Ellipse(memDC,20,20,120,120);<br />
::BitBlt(hdc,0,0,prc->left,prc->bottom,memDC,0,0,SRCCOPY);<br />
<br />
::DeleteObject( backBrush );<br />
::SelectObject(memDC, oldBitmap);<br />
::DeleteObject(bitmap1);<br />
::DeleteDC(memDC);<br />
It just doesnt display anything.
|
|
|
|
|
Is prc->left what you intended as the bitmap width in the call to
CreateCompatibleBitmap(memDC,prc->left... ??
It's used in BitBlt too...
Mark
|
|
|
|
|
|
ceejeeb wrote: yes it is the width
If that's the case then how will this work...
::FillRect(memDC,prc,backBrush);
Are you sure you don't mean to use prc->right?
Mark
|
|
|
|
|
ahh yes my mistake it was menat to be right.
Now its draws to the screen but not as intended the back background is dotted black and white.
|
|
|
|
|
try changing
HBITMAP bitmap1 = CreateCompatibleBitmap(memDC,prc->left,prc->bottom);
to
HBITMAP bitmap1 = CreateCompatibleBitmap(hdc,prc->right,prc->bottom);
The default bitmap for a dc is monochrome - you want a bitmap compatible with the original dc.
|
|
|
|
|
Thanks alot mark all is working fine now. Big Help.
|
|
|
|
|
I have a CTreeCtrl and an associated CImageList. Is there any way I can load images into the CImageList at runtime (e.g. from an .ico file supplied by the user) without them being hardcoded into the executable files ?
-- modified at 14:21 Thursday 4th January, 2007
cheers,
Neil
|
|
|
|
|
You can add/remove images from image lists dynamically.
Check out CImageList::Add() (::ImageList_AddIcon()), ::LoadImage(), etc.
Mark
|
|
|
|