?? program.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//earcgi/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>
<p>
<center>
<img src="IconMover.jpg">
</center>
<p>
<b><u>IconMover - Timer Application</u></b>
<p>
<b>IconMover</b> is a sample application embodying a timer which signals the program
at regular intervals. When the program is signaled, the icon being displayed is changed,
leading to a crude animation of the icon.
<p>
<ul>
<a href="#ProgramFlow"><b><u>Program Flow</u></b></a>
<br>
<a href="#MethodsVars"><b><u>Methods and Variables</u></b></a>
<br>
<ul>
<a href="#Methods"><b><u>Methods</u></b></a>
<br>
<a href="#Variables"><b><u>Variables</u></b></a>
<br>
</ul>
</ul>
<p>
<center>
<hr width="50%">
</center>
<p>
<a name="ProgramFlow"><b><u>Program Flow</u></b></a>
<p>
We start by adding a line to the dialogs' <b><i>OnInitDialog</i></b> method to
set the value of IconTimer to NULL, indicating that the timer has not yet been
assigned.
<p>
The dialog window is initialized containing a default icon and 3 buttons:
<b>Start</b>,
<b>Stop</b>
and
<b>Exit</b>,
corresponding to the
<a href="#OnStart"><b><i>OnStart</i></b></a>,
<a href="#OnStop"><b><i>OnStop</b></i></a>
and
<a href="#OnOK"><b><i>OnOK</i></b></a>
methods, respectively. The <b>Start</b> button starts the timer, if one is not
already running, the <b>Stop</b> button stops the timer, and the <b>Exit</b>
button stops the running timer, if one is running, and exits the dialog.
<p>
When the <b>Start</b> button has been activated, a timer is started with the default
timer interval, 500 mSec., causing a timer message to be generated every 1/2 second.
<p>
The <a href="#OnTimer"><b><i>OnTimer</i></b></a>
method is invoked to process each timer generated message. The <b>IconState</b>
modulus 4, a number between 0 and 3, inclusive, is used as an index in a select statement
to choose the icon to display next. Once the icon is selected (<b>IconId</b>),
<b>IconState</b> is incremented for the next timer message. Finally, the
<a href="#SetCurrentIcon"><b><i>SetCurrentIcon</i></b></a> method
is passed the value in <b>IconId</b> to display the indicated icon in the dialog.
<p>
The timer will run until the <b>Stop</b> button is pressed. After stopping the timer,
the <b><i>OnStop</i></b> method passes the default icon setting, 0, to the
<b><i>SetCurrentIcon</i></b> method.
<p>
The <b>Exit</b> button is used to stop the timer, if it is running, and exit the
dialog when you are through with the application.
<p>
</ul>
<center>
<hr width="50%">
</center>
<p>
<a name="MethodsVars"><b><u>Methods and Variables</u></b></a>
<p>
<ul>
<b>IconMover</b> is a sample application embodying a timer which signals the program
at regular intervals. When the program is signaled, the icon being displayed is changed,
leading to a crude animation of the icon.
<p>
The program implements the methods discussed elsewhere in this tutorial:
<p>
<ul>
<b>
<a href="#OnTimer">OnTimer</a>
<br>
<a href="#StartTimer">StartTimer</a>
<br>
<a href="#StopTimer">StopTimer</a>
<br>
<p>
</b>
</ul>
<p>
As well as several new methods:
<p>
<ul>
<b>
<a href="#OnOK">OnOK</a>
<br>
<a href="#OnStart">OnStart</a>
<br>
<a href="#OnStop">OnStop</a>
<br>
<a href="#SetCurrentIcon">SetCurrentIcon</a>
<br>
</b>
</ul>
<p>
And two public variables:
<p>
<ul>
<b>
<a href="#IconState">IconState</a>
<br>
<a href="#IconTimer">IconTimer</a>
<br>
</b>
</ul>
<p>
</ul>
<center>
<hr width="50%">
</center>
<p>
<a name="Methods"><b><u>Methods</u></b></a>
<p>
<b>UINT <a name="StartTimer">StartTimer</a>
(UINT TimerDuration)
</b>
<ul>
<p>
<li>Associates a timer event with the current process and sets its duration, in mSec.
<br>
<li>Returns the system timer assigned to process the event, or 0 if an error occurs.
</ul>
<p>
<center>
<hr width="50%">
<p>
</center>
<b>BOOL <a name="StopTimer">StopTimer</a>
(UINT TimerVal)
</b>
<ul>
<p>
<li>Stops system timer event <b>TimerVal</b>.
<br>
<li>Returns TRUE if successful.
</ul>
<p>
<center>
<hr width="50%">
<p>
</center>
<b>void <a name="OnTimer">OnTimer</a>
(UINT TimerVal)
</b>
<ul>
<p>
<li>Processes the system timer <b>TimerVal</b>.
<br>
<li>Does not stop the timer.
<br>
<li>Displays the icon associated with the value in <b>IconState</b> modulus 4 (a
number between 0 and 3, inclusive).
</ul>
<p>
<center>
<hr width="50%">
<p>
</center>
<b>void <a name="OnOK">OnOK</a> ( )</b>
<ul>
<p>
<li>Processes the <b>EXIT</b> button
<br>
<li>Stops the timer, if one is active, and exits the dialog
</ul>
<p>
<center>
<hr width="50%">
<p>
</center>
<b>void <a name="OnStart">OnStart</a> ( )</b>
<ul>
<p>
<li>Processes the <b>Start</b> button
<br>
<li>Starts a system timer event and stores the value of the timer in <b>IconTimer</b>
</ul>
<p>
<center>
<hr width="50%">
<p>
</center>
<b>void <a name="OnStop">OnStop</a> ( )</b>
<ul>
<p>
<li>Processes the <b>Stop</b> button
<br>
<li>Stops the system timer event <b>IconTimer</b>
</ul>
<p>
<center>
<hr width="50%">
<p>
</center>
<b>void <a name="SetCurrentIcon">SetCurrentIcon</a> (int IconId)</b>
<ul>
<p>
<li>Sets the current icon being displayed.
</ul>
<p>
<center>
<hr width="50%">
<p>
</center>
<p>
<a name="Variables"><b><u>Variables</u></b></a>
<p>
<ul>
<table border=1>
<tr>
<td width=100><b><a name="IconState">IconState</a></b>
<td>Contains the value of the next icon to display on the dialog windows.
</tr>
<tr>
<td width=100><b><a name="IconTimer">IconTimer</a></b>
<td>Contains the value of the system assigned timer. Invalid when NULL.
</tr>
</table>
</ul>
<p>
</ul>
<center>
<hr width="50%">
<p>
</center>
<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>
</p><br></font></body>
</html>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -