⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 processing.html

📁 定时器 的源代码 比较简单 简易使用MFC中的定时器
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<meta http-equiv="Content-Type"       content="text/html;       charset=iso-8859-1">
<meta name="GENERATOR" content="/www/htdocs/earthwalkdesigns/cgi-bin/EWDHtml.cgi">
<!--                                                       -->
<!--      *******************************************      -->
<!--      *                                         *      -->
<!--      * EarthWalk Designs Programming Services. *      -->
<!--      *        WWW.EarthWalkDesigns.Com         *      -->
<!--      *                                         *      -->
<!--      *  Jay Wheeler (Jay@EarthWalkDesigns.com) *      -->
<!--      *              December 1997              *      -->
<!--      *                                         *      -->
<!--      *******************************************      -->
<!--                                                       -->
<!-- This page was designed by Jay Wheeler. -->
<title>MFC Timers - A Tutorial</title>
</head>
<body bgcolor="#ffffff" text="#000000" link="#990033" vlink="#333399" alink="#ff0000">
<font size=" 3 " face=" Century Schoolbook ">
<center>
<a href="http://www.earthwalkdesigns.com"><img src="EarthWalk.gif" border="0" align="center" ></a>
<br>
<font size="+2">
<b>MFC Timers - A Tutorial
</b></font>
<br>
<img src="Colorbar.gif" border="0" align="center" ><br>
</center>
<b><u>Processing Timer Events - The <i>OnTimer</i> Method</b></u>
<ul>
<p>
After the timer has been started, the <b>OnTimer</b> event will be called each time
the timer counts down to zero (reaches <i>terminal count</i>) from the requested value.  
This event is <i>asynchronous</i> to the timer - a message is placed in the message 
queue of the calling process and the timer is automatically restarted.
<p>
The timer can be stopped 
(refer to <a href="Stopping.html">Stopping the Timer</a>)
upon entry to the <b>OnTimer</b> routine, or left to run if the event will <b>not</b> 
occur again before processing the <b>OnTimer</b> routine has completed.
<p>
The <b>OnTimer</b> method will be executed each time the timer reaches <i>terminal count</i>.
The code in this method should be short and concise; it should be code which <b>must</b>
be executed each time the timer reaches its <i>terminal count</i>, such as changing the
view of an animated drawing or icon, or setting a flag to process latter, or starting a 
thread to handle the more complex functions.
<p>
<b><u>Example:</u></b>
<p>
<pre>

    void OnTimer (UINT TimerVal)
    {
        //////////////////////////////////////////////
        //
        //    Stop the timer
        //
        //////////////////////////////////////////////

        if (!KillTimer (TimerVal))
        {

        }

        //////////////////////////////////////////////
        //
        //    Process the event
        //
        //////////////////////////////////////////////


        //////////////////////////////////////////////
        //
        //    Restart the timer, if needed, before exiting
        //
        //////////////////////////////////////////////


    }
  </pre>
</ul>
<p>
<b><u>Multiple Timers</u></b>
<p>
<ul>
The <b>OnTimer</b> method is passed an unsigned integer (UINT) to identify the timer
which is interrupting.  The value of this timer may be used to stop the associated
timer.  It can also be used in a multiple timer environment to determine what type of
processing must occur.
<p>
</ul> 
<u><b>Example:</b></u>
<p>
<ul>
  Assumptions:
  <ol>
    <li>The timers are started using the example in the section on
          <a href="Install.html">Installing a Timer</a>.
    <li>The timer values are placed sequentially into the array <b><i>ATimer</i></b>,
          as follows:
    <p>
    <ul>
      <pre>
      ATimer [0] = StartTimer (200);  // a 200 mSec timer
      ATimer [1] = StartTimer (500);  // a 500 mSec timer
      </pre>
    </ul>
    <p>
  </ol>
  <p>
  <pre>
  void OnTimer (UINT TimerVal)
  {
      int      Index;

      /////////////////////////////////////////////////////////////////////////////
      //
      //      Check timer number 0
      //
      ////////////////////////////////////////////////////////////////////////////

      if (TimerVal == ATimer[0])
      {
          //
          //      Process timer 0 message!
          //

          return;
      }

      ////////////////////////////////////////////////////////////////////////////
      //
      //      check timer number 1
      //
      ////////////////////////////////////////////////////////////////////////////

      if (TimerVal == ATimer[1])
      {
          //
          //      Process timer 1 message!
          //

          return;
      }

      ////////////////////////////////////////////////////////////////////////////
      //
      //      Not timer number 0 or 1
      //
      ////////////////////////////////////////////////////////////////////////////

      if (!KillTimer (TimerVal))
      {

      }

      CString Message;
      Message.format("Unkown timer interrupt: %u", TimerVal);
      MessageBox (Message,"OnTimer",MB_OK|MB_SYSTEMMODAL);
      
  } // end OnTimer

</pre>
</ul>

<p>
<center>
<img src="Colorbar.gif" border="0" align="center" ><br>
</center>
<font size="-1">
Copyright (c) 1997,1998. EarthWalk Designs.
<br>
Direct all inquiries to:<a href="mailto:jay@earthwalkdesigns.com">Jay Wheeler</a>
at EarthWalkDesigns.com
</font>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -