Jump to content
  • Advertisement
Sign in to follow this  
donjonson

win 32 with windows api

This topic is 4889 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am just playing around with windows api programming and I have a few questions I made a class to draw a line using win api anywhare in a window. it is drawn using a start point, length and an angle. So the first thing i did to test out this new class was simply make a rotating line abouta center point using a windows timer. I set the timer for 1 milisecond. each WM_TIMER message i add 1 to the angle of the line and redraw. This works properly, the line spins around it's start point. however I dont think it is operating at 1 khz (which is ther freq of a 1 milisecond timer if I am not mistaken). It seems to be going much slower. is this because my code is perhaps not very efficient or because of some inneficency in win32/winapi? I am at work now so I cant post the exe file but if you want to see it Ill post it when i get home

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
It is HIGHLY unlikely that your code would cause it to slow down...
I mean, after all you are just drawing a line....

How do you setup your timer???

Share this post


Link to post
Share on other sites
With Windows, there is no guarantee that your WM_TIMER messages will be received at exactly the interval you specified. GetMessage/PeekMessage will only post a WM_TIMER event when there are no events of higher priority in the queue. WM_TIMER is low priority. Also, there is a USER_TIMER_MINIMUM that defines the smallest time interval. If the value you specify is less than that, it is automatically (and quietly) set to USER_TIMER_MINIMUM. So, just because the interval is represented in milliseconds doesn't mean that the resolution will be 1 millisecond.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
from msdn:

"The WM_TIMER message is a low-priority message. The GetMessage and PeekMessage functions post this message only when no other higher-priority messages are in the thread's message queue."

Share this post


Link to post
Share on other sites
Use QueryPerformanceCounter to get a high-resolution time value. Then simply update your angle as part of your message loop, scaling the change in angle by the amount of time elapsed. (Assuming you use PeekMessage instead of GetMessage).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It seems to me that your problem here is that you are telling the timer to fire a timer event every millisecond, which will actually mean that the line is rotating so fast you cant actually see it smoothly move.
Try something like:

SetTimer(hwnd,1,1000,NULL);

Which will fire it every second

Share this post


Link to post
Share on other sites
you are right, if the angle were actuly changin every milisecond, it would be moving to fast to see. but it takes 2 minutes for the line to get all the way around the circle. It is not working at 1 khz .so for a one minute timer it would take 6 minutes to go around once and if i set it to do that it does. I will try the other method suggested.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!