📄 443-446.html
字号:
<td><img src="/images/white.gif" width="5" height="1" alt="" border="0"></td>
<!-- end of ITK left NAV -->
<!-- begin main content -->
<td width="100%" valign="top" align="left">
<!-- END SUB HEADER -->
<!--Begin Content Column -->
<FONT FACE="Arial,Helvetica" SIZE="-1">
To access the contents, click the chapter and section titles.
</FONT>
<P>
<B>Essential Windows CE Application Programming</B>
<FONT SIZE="-1">
<BR>
<I>(Publisher: John Wiley & Sons, Inc.)</I>
<BR>
Author(s): Robert Burdick
<BR>
ISBN: 0471327476
<BR>
Publication Date: 03/01/99
</FONT>
<P>
<form name="Search" method="GET" action="http://search.earthweb.com/search97/search_redir.cgi">
<INPUT TYPE="hidden" NAME="Action" VALUE="Search">
<INPUT TYPE="hidden" NAME="SearchPage" VALUE="http://search.earthweb.com/search97/samples/forms/srchdemo.htm">
<INPUT TYPE="hidden" NAME="Collection" VALUE="ITK">
<INPUT TYPE="hidden" NAME="ResultTemplate" VALUE="itk-simple-intrabook.hts">
<INPUT TYPE="hidden" NAME="ViewTemplate" VALUE="view.hts">
<font face="arial, helvetica" size=2><b>Search this book:</b></font><br>
<INPUT NAME="queryText" size=50 VALUE=""> <input type="submit" name="submitbutton" value="Go!">
<INPUT type=hidden NAME="section_on" VALUE="on">
<INPUT type=hidden NAME="section" VALUE="http://www.itknowledge.com/reference/standard/0471327476/">
</form>
<!-- Empty Reference Subhead -->
<!--ISBN=0471327476//-->
<!--TITLE=Essential Windows CE Application Programming//-->
<!--AUTHOR=Robert Burdick//-->
<!--PUBLISHER=John Wiley & Sons, Inc.//-->
<!--IMPRINT=Wiley Computer Publishing//-->
<!--CHAPTER=16//-->
<!--PAGES=443-446//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="439-443.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="../ewtoc.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P>Windows CE also defines a low and critical memory state. These states are entered as available RAM drops below certain thresholds. For systems with 1 KB page sizes, the low memory state is triggered when available RAM drops below 64 KB. For 4 KB page systems, the threshold is 96 KB. The critical memory state is triggered if available RAM drops below 16 KB for 1 KB page systems, and if available RAM drops below 48 KB for 4 KB page systems.
</P>
<P>In these memory states, Windows CE limits the amount of memory that applications can allocate in an attempt to equally share remaining memory resources across all active applications.</P>
<P>In the low memory state, <I>VirtualAlloc</I> calls are limited to allocating 16 KB of memory. In the critical memory state, this limit drops to 8 KB.</P>
<H3><A NAME="Heading7"></A><FONT COLOR="#000077">The GetSystemPowerStatusEx Function</FONT></H3>
<P>We close this chapter with a brief look at Windows CE power issues.
</P>
<P>Windows CE supports the function <I>GetSystemPowerStatusEx</I>. This function provides information about such things as the main and backup battery levels of a Windows CE device. <I>GetSystemPowerStatusEx</I> also indicates whether the device is currently running on AC or battery power.</P>
<!-- CODE SNIP //-->
<PRE>
GetSystemPowerStatusEx(pSystemPowerStatusEx, fUpdate);
</PRE>
<!-- END CODE SNIP //-->
<P>The first parameter is a pointer to a SYSTEM_POWER_STATUS_EX structure. This structure contains members that are filled by Windows CE to report remaining battery life, whether the device is running on AC power, and the like.
</P>
<P><I>fUpdate</I> is a BOOL specifying where the function gets the power information. If TRUE, the function gets the latest power information directly from the device driver. If <I>fUpdate</I> is FALSE, the information returned is cached information that may be a few seconds out of date.</P>
<P>One use of <I>GetSystemPowerStatusEx</I> is to drive user interfaces that report battery charge status. The sample application MEMORY.EXE includes a simple demonstration of this function’s use. Selecting the Power Status option from the Power menu displays the dialog box shown in Figure 16.6.</P>
<P><A NAME="Fig6"></A><A HREF="javascript:displayWindow('images/16-06.jpg',654,245 )"><IMG SRC="images/16-06t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/16-06.jpg',654,245)"><FONT COLOR="#000077"><B>Figure 16.6</B></FONT></A> The MEMORY.EXE Power Status dialog box.</P>
<P>The small icon in the lower left of the dialog indicates if the device is powered by battery or AC. (In Figure 16.6, the indicator shows that the device is running on battery power.) The two progress bars indicate the current power level of the main batteries and the backup battery. The code for displaying this information is straightforward. The pertinent parts of the power dialog’s dialog procedure are shown as follows:
</P>
<!-- CODE //-->
<PRE>
#define IDT_TIMER 128
BOOL CALLBACK PowerStatusDlgProc(
HWND hwndDlg,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
SYSTEM_POWER_STATUS_EX sps;
HWND hwndBatteryLife; //Main battery power progress bar
HWND hwndBackupLife; //Backup battery power progess bar
HWND hwndStatic; //Power source bitmap static control
UINT nID;
HBITMAP hBmp;
switch(message)
{
//Other dialog messages
//...
case WM_INITDIALOG:
GetSystemPowerStatusEx(&sps, TRUE);
nID = (sps.ACLineStatus) ? IDB_ONLINE : IDB_OFFLINE;
hBmp = LoadBitmap(ghInst, MAKEINTRESOURCE(nID));
hwndStatic = GetDlgItem(hwndDlg, IDC_AC_POWER);
SendMessage(hwndStatic, STM_SETIMAGE,
IMAGE_BITMAP, (LPARAM)hBmp);
SetTimer(hwndDlg, IDT_TIMER, 1000, NULL);
return (TRUE);
case WM_TIMER:
GetSystemPowerStatusEx(&sps, TRUE);
if (sps.ACLineStatus == 0)
{
hwndBatteryLife = GetDlgItem(hwndDlg,
IDC_BATTERY_LIFE);
SendMessage(hwndBatteryLife, PBM_SETPOS,
(WPARAM)sps.BatteryLifePercent, 0);
hwndBackupLife = GetDlgItem(hwndDlg,
IDC_BACKUP_BATTERY_LIFE);
SendMessage(hwndBackupLife, PBM_SETPOS,
(WPARAM)sps.BackupBatteryLifePercent, 0);
}
return (0);
default:
return (FALSE);
} //End of switch(message) statement
}
</PRE>
<!-- END CODE //-->
<P>The WM_INITDIALOG message handler sets the bitmap in an SS_BITMAP-style static control. The handler calls <I>GetSystemPowerStatusEx</I>, and assigns the UINT <I>nID</I> to the identifier of a bitmap resource according to the AC power status of the Windows CE device. Next, it starts a timer identified by IDT_TIMER.</P>
<P>Every time the timer fires, the WM_TIMER message handler updates the progress bars, which report the device battery status. The <I>BatteryLifePercent</I> and <I>BackupBatteryLifePercent</I> member of the SYSTEM_POWER_STATUS_EX structure contain, respectively, the percentage of main and backup battery charge remaining.</P>
<H3><A NAME="Heading8"></A><FONT COLOR="#000077">Concluding Remarks</FONT></H3>
<P>In this chapter, we have examined various Windows CE memory management techniques. We discussed basic features of Windows CE memory organization, such as the operating system and application address spaces. We looked at how to use application and custom heaps to allocate memory on an as-needed basis. We also looked at how to use memory mapped files for inter-process communication.
</P>
<P>This chapter also introduced the WM_HIBERNATE message, which is used to report low memory conditions on Windows CE devices. The chapter concluded with a brief look at Windows CE power management issues.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="439-443.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="../ewtoc.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<!-- all of the reference materials (books) have the footer and subfoot reveresed -->
<!-- reference_subfoot = footer -->
<!-- reference_footer = subfoot -->
<!-- BEGIN SUB FOOTER -->
<br><br>
</TD>
</TR>
</TABLE>
<table width="640" border=0 cellpadding=0 cellspacing=0>
<tr>
<td align="left" width=135><img src="/images/white.gif" width=100 height="1" alt="" border="0"></td>
<!-- END SUB FOOTER -->
<!-- all of the books have the footer and subfoot reveresed -->
<!-- reference_subfoot = footer -->
<!-- reference_footer = subfoot -->
<!-- FOOTER -->
<td width="515" align="left" bgcolor="#FFFFFF">
<font face="arial, helvetica" size="1"><b><a href="/products.html"><font color="#006666">Products</font></a> | <a href="/contactus.html"><font color="#006666">Contact Us</font></a> | <a href="/aboutus.html"><font color="#006666">About Us</font></a> | <a href="http://www.earthweb.com/corporate/privacy.html" target="_blank"><font color="#006666">Privacy</font></a> | <a href="http://www.itmarketer.com/" target="_blank"><font color="#006666">Ad Info</font></a> | <a href="/"><font color="#006666">Home</font></a></b>
<br><br>
Use of this site is subject to certain <a href="/agreement.html">Terms & Conditions</a>, <a href="/copyright.html">Copyright © 1996-1999 EarthWeb Inc.</a><br>
All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.</font><p>
</td>
</tr>
</table>
</BODY>
</HTML>
<!-- END FOOTER -->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -