WM_TIMER, CFormView, and SetTimer 
Author Message
 WM_TIMER, CFormView, and SetTimer

I am writing an application with a Single Document Interface.  I
use CFormView because I want to do three things:  allow user
to type text input, allow the user to click a button or press
enter for the application to process what they typed, and view
a running time clock that counts up from zero when they first
launch the application.  

I can do the text input and button, no problem with the CFormView.
However, I cannot figure out how to get Visual C++ 6.0 to handle a timer
on a CFormView.  I can successfully make a timer in my CFrameWnd class,
but then I can't figure out how to get it to talk to my CFormView.

Does anyone know how to display a running time clock from a CFrameWnd
to a CFormView or how to use SetTimer and OnTimer within a CFormView?
Has anyone seen this before?  Anything similar?  I've read the
MSDN Library and it wasn't much help.

Thanks.

_________________________________

Research Faculty
Applied Research Laboratory
The Pennsylvania State University



Tue, 19 Aug 2003 05:22:26 GMT  
 WM_TIMER, CFormView, and SetTimer
You can setup a timer in your view just like any other window.

SetTimer(TIMEID,1000,NULL);
and all you have to do is put ON_WM_TIMER() in your message map and have
function
void OnTimer(int nID) which gets called evertime a timer hits. Or better
yet, use the ClassWizard to add the handler.

Since you are doing a clock keep in mind that WM_TIMER is a low priority
message.

Ali


Quote:
> I am writing an application with a Single Document Interface.  I
> use CFormView because I want to do three things:  allow user
> to type text input, allow the user to click a button or press
> enter for the application to process what they typed, and view
> a running time clock that counts up from zero when they first
> launch the application.

> I can do the text input and button, no problem with the CFormView.
> However, I cannot figure out how to get Visual C++ 6.0 to handle a timer
> on a CFormView.  I can successfully make a timer in my CFrameWnd class,
> but then I can't figure out how to get it to talk to my CFormView.

> Does anyone know how to display a running time clock from a CFrameWnd
> to a CFormView or how to use SetTimer and OnTimer within a CFormView?
> Has anyone seen this before?  Anything similar?  I've read the
> MSDN Library and it wasn't much help.

> Thanks.

> _________________________________

> Research Faculty
> Applied Research Laboratory
> The Pennsylvania State University



Tue, 19 Aug 2003 06:32:12 GMT  
 WM_TIMER, CFormView, and SetTimer
I need a timer with millisecond accuracy .
In outline , how is this achieved ?


Quote:
> You can setup a timer in your view just like any other window.

> SetTimer(TIMEID,1000,NULL);
> and all you have to do is put ON_WM_TIMER() in your message map and have
> function
> void OnTimer(int nID) which gets called evertime a timer hits. Or better
> yet, use the ClassWizard to add the handler.

> Since you are doing a clock keep in mind that WM_TIMER is a low priority
> message.

> Ali



> > I am writing an application with a Single Document Interface.  I
> > use CFormView because I want to do three things:  allow user
> > to type text input, allow the user to click a button or press
> > enter for the application to process what they typed, and view
> > a running time clock that counts up from zero when they first
> > launch the application.

> > I can do the text input and button, no problem with the CFormView.
> > However, I cannot figure out how to get Visual C++ 6.0 to handle a timer
> > on a CFormView.  I can successfully make a timer in my CFrameWnd class,
> > but then I can't figure out how to get it to talk to my CFormView.

> > Does anyone know how to display a running time clock from a CFrameWnd
> > to a CFormView or how to use SetTimer and OnTimer within a CFormView?
> > Has anyone seen this before?  Anything similar?  I've read the
> > MSDN Library and it wasn't much help.

> > Thanks.

> > _________________________________

> > Research Faculty
> > Applied Research Laboratory
> > The Pennsylvania State University



Wed, 01 Oct 2003 22:24:30 GMT  
 WM_TIMER, CFormView, and SetTimer

Quote:
> I need a timer with millisecond accuracy .
> In outline , how is this achieved ?

Several problems.  First the Windows32 operating system
does not have a time "tick" that fine.  Depending on which
OS you have, it might be 10 msec or more.   There are
system clocks that can read time to much finer accuracy,
but tasks are scheduled on the low resolution system clock.

Furthermore, your own thread may be preempted at any
time to execute another task.  You can't count simply on
not running anything simultaneously because the operating
system has its own tasks running.  So your program may
be interrupted for varying amounts of time -- usually no
more than a few msec, but there is no control over this.

A real-time system that requires millisecond accuracy
might be done using a device driver, but generally for
guaranteed millisecond accuracy you either need to
revert back to a single threaded OS like DOS where
you have complete control of the system or use a truly
real-time OS.



Wed, 01 Oct 2003 23:08:41 GMT  
 WM_TIMER, CFormView, and SetTimer
For my system, the QueryPerformanceFrequency function retrieves 1,193,182.
Is that 10 msec or more? I get confused.


Quote:


> > I need a timer with millisecond accuracy .
> > In outline , how is this achieved ?

> Several problems.  First the Windows32 operating system
> does not have a time "tick" that fine.  Depending on which
> OS you have, it might be 10 msec or more.   There are
> system clocks that can read time to much finer accuracy,
> but tasks are scheduled on the low resolution system clock.

> Furthermore, your own thread may be preempted at any
> time to execute another task.  You can't count simply on
> not running anything simultaneously because the operating
> system has its own tasks running.  So your program may
> be interrupted for varying amounts of time -- usually no
> more than a few msec, but there is no control over this.

> A real-time system that requires millisecond accuracy
> might be done using a device driver, but generally for
> guaranteed millisecond accuracy you either need to
> revert back to a single threaded OS like DOS where
> you have complete control of the system or use a truly
> real-time OS.



Thu, 02 Oct 2003 00:56:37 GMT  
 WM_TIMER, CFormView, and SetTimer
Thanks Richard .
Looks like I'm going to have to forget windows for this .
A pity since I've done a lot of VB work , and would have been comfortable to
cover the MFC enough for my metronome project .
There are lots of metronomes.exe out and about , but none of them has the
accuracy I want .
Nor have they the control form I have imagined etc .... .

I have an old DOS box in the 'workshop' .
But I've never done any programming  for DOS .
What is used .
Would there be a huge ammount to learn ?
Or can I get a C compiler and libraries etc .
I'm betginner/intermediate with C .

How does one do forms/'graphics'pages for DOS .
I should like mouse functionality and some 'buttons' .

Any pointers appreciated .

Thankyou

Chris James .


Quote:


> > I need a timer with millisecond accuracy .
> > In outline , how is this achieved ?

> Several problems.  First the Windows32 operating system
> does not have a time "tick" that fine.  Depending on which
> OS you have, it might be 10 msec or more.   There are
> system clocks that can read time to much finer accuracy,
> but tasks are scheduled on the low resolution system clock.

> Furthermore, your own thread may be preempted at any
> time to execute another task.  You can't count simply on
> not running anything simultaneously because the operating
> system has its own tasks running.  So your program may
> be interrupted for varying amounts of time -- usually no
> more than a few msec, but there is no control over this.

> A real-time system that requires millisecond accuracy
> might be done using a device driver, but generally for
> guaranteed millisecond accuracy you either need to
> revert back to a single threaded OS like DOS where
> you have complete control of the system or use a truly
> real-time OS.



Thu, 02 Oct 2003 02:11:42 GMT  
 WM_TIMER, CFormView, and SetTimer
have a look at Multimedia Timers in MSDN. I have never used these functions
but they may just be what you are looking for! :o)

--
Pete
http://www3.telus.net/pja/


Quote:
> Thanks Richard .
> Looks like I'm going to have to forget windows for this .
> A pity since I've done a lot of VB work , and would have been comfortable
to
> cover the MFC enough for my metronome project .
> There are lots of metronomes.exe out and about , but none of them has the
> accuracy I want .
> Nor have they the control form I have imagined etc .... .

> I have an old DOS box in the 'workshop' .
> But I've never done any programming  for DOS .
> What is used .
> Would there be a huge ammount to learn ?
> Or can I get a C compiler and libraries etc .
> I'm betginner/intermediate with C .

> How does one do forms/'graphics'pages for DOS .
> I should like mouse functionality and some 'buttons' .

> Any pointers appreciated .

> Thankyou

> Chris James .





> > > I need a timer with millisecond accuracy .
> > > In outline , how is this achieved ?

> > Several problems.  First the Windows32 operating system
> > does not have a time "tick" that fine.  Depending on which
> > OS you have, it might be 10 msec or more.   There are
> > system clocks that can read time to much finer accuracy,
> > but tasks are scheduled on the low resolution system clock.

> > Furthermore, your own thread may be preempted at any
> > time to execute another task.  You can't count simply on
> > not running anything simultaneously because the operating
> > system has its own tasks running.  So your program may
> > be interrupted for varying amounts of time -- usually no
> > more than a few msec, but there is no control over this.

> > A real-time system that requires millisecond accuracy
> > might be done using a device driver, but generally for
> > guaranteed millisecond accuracy you either need to
> > revert back to a single threaded OS like DOS where
> > you have complete control of the system or use a truly
> > real-time OS.



Thu, 02 Oct 2003 02:37:19 GMT  
 WM_TIMER, CFormView, and SetTimer
The QueryPerformance functions are the ones I was referring to
when I said you can READ time to a fine accuracy. In your case,
the resolution is bettern then 1 microsecond.  But you still have a
problem trying to execute something with 1 millisecond time resolution.

But your application might be terribly non-critical.  Would it be really
terrible if the metronome tick was occasionally (and rather rarely)
off by a bit?  And why would a metronome need such fine resolution.

You can go into a polling loop querying the performance timer until
it turned over to the right increment.  Just make sure that you include
a Sleep(0) function call in your loop or else you will consume 100%
of CPU time.  Also you will have to check somehow to see whether
you the user has requested to break out of the loop.  And if the timer
tick occasionally fires, then too bad.

However, if you can't accept the occasional mistiming, you have to
do the drastic measures I originally specified.  And 1 msec timing
in DOS still requires some intimate knowledge of hardware and
timing loops.


Quote:
> For my system, the QueryPerformanceFrequency function retrieves 1,193,182.
> Is that 10 msec or more? I get confused.





> > > I need a timer with millisecond accuracy .
> > > In outline , how is this achieved ?

> > Several problems.  First the Windows32 operating system
> > does not have a time "tick" that fine.  Depending on which
> > OS you have, it might be 10 msec or more.   There are
> > system clocks that can read time to much finer accuracy,
> > but tasks are scheduled on the low resolution system clock.

> > Furthermore, your own thread may be preempted at any
> > time to execute another task.  You can't count simply on
> > not running anything simultaneously because the operating
> > system has its own tasks running.  So your program may
> > be interrupted for varying amounts of time -- usually no
> > more than a few msec, but there is no control over this.

> > A real-time system that requires millisecond accuracy
> > might be done using a device driver, but generally for
> > guaranteed millisecond accuracy you either need to
> > revert back to a single threaded OS like DOS where
> > you have complete control of the system or use a truly
> > real-time OS.



Thu, 02 Oct 2003 05:30:04 GMT  
 WM_TIMER, CFormView, and SetTimer
I just was curious about whether "the Windows32 operating system does not
have a time 'tick'" as fine as a millisecond. So I am just not sure whether
you are saying it does or does not have a timer capable of that resolution.

I am not the person asking the original question, so I don't want Chris to
be "blamed" for anything I said. I understand what you are saying and agree
with you about the Windows operating systems not being a real-time operating
system. Actually I think that Microsoft is offering a real-time version of
Windows but anyone familiar with it would understand the importantance of it
for this context. The important thing is that in most cases Windows cannot
be relied on to execute something when we want it to. A device driver can
help but as far as I understand things device drivers are also not entirely
reliable.


Quote:
> The QueryPerformance functions are the ones I was referring to
> when I said you can READ time to a fine accuracy. In your case,
> the resolution is bettern then 1 microsecond.  But you still have a
> problem trying to execute something with 1 millisecond time resolution.

> But your application might be terribly non-critical.  Would it be really
> terrible if the metronome tick was occasionally (and rather rarely)
> off by a bit?  And why would a metronome need such fine resolution.

> You can go into a polling loop querying the performance timer until
> it turned over to the right increment.  Just make sure that you include
> a Sleep(0) function call in your loop or else you will consume 100%
> of CPU time.  Also you will have to check somehow to see whether
> you the user has requested to break out of the loop.  And if the timer
> tick occasionally fires, then too bad.

> However, if you can't accept the occasional mistiming, you have to
> do the drastic measures I originally specified.  And 1 msec timing
> in DOS still requires some intimate knowledge of hardware and
> timing loops.



> > For my system, the QueryPerformanceFrequency function retrieves
1,193,182.
> > Is that 10 msec or more? I get confused.




message

> > > > I need a timer with millisecond accuracy .
> > > > In outline , how is this achieved ?

> > > Several problems.  First the Windows32 operating system
> > > does not have a time "tick" that fine.  Depending on which
> > > OS you have, it might be 10 msec or more.   There are
> > > system clocks that can read time to much finer accuracy,
> > > but tasks are scheduled on the low resolution system clock.

> > > Furthermore, your own thread may be preempted at any
> > > time to execute another task.  You can't count simply on
> > > not running anything simultaneously because the operating
> > > system has its own tasks running.  So your program may
> > > be interrupted for varying amounts of time -- usually no
> > > more than a few msec, but there is no control over this.

> > > A real-time system that requires millisecond accuracy
> > > might be done using a device driver, but generally for
> > > guaranteed millisecond accuracy you either need to
> > > revert back to a single threaded OS like DOS where
> > > you have complete control of the system or use a truly
> > > real-time OS.



Thu, 02 Oct 2003 07:51:17 GMT  
 WM_TIMER, CFormView, and SetTimer
With greater thread priority and other added prioritization over
previous Win versions, does W2K offer anything closer to real-time
control? I suppose you might need to create a real-time clock with the
DDK and use interrupts that can trigger real-time critical events in the
O/S.

If not than QNX or some real-time versions of Linux with the GNOME GUI
front end platform I would guess. From brief readings, it appears GNOME
is similar to MFC (but in C) for win type ui's.



Fri, 03 Oct 2003 07:20:41 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. WM_TIMER, CFormView, and SetTimer

2. How to use SetTimer()/WM_TIMER

3. SetTimer on a CFormView

4. Help with SetTimer or CWnd::SetTimer

5. CFormView within a CFormView error

6. CFormView on CFormView?

7. Closing a CFormView window from another CFormView window

8. Problems with CFormView inside CFormView (mnemonic keys)

9. Appwizard CFormView Assertion Error (also no or blank dialog (CFormView)) VS6.0 and VSNETBETA2

10. How to insert a CFormView in a CFormView?

11. WM_TIMER with IWebBrowser2

12. ATL activex and WM_TIMER

 

 
Powered by phpBB® Forum Software