📄 应用文--_net技术库--从ap中获取电池和电源信息变更通知的方法.htm
字号:
href="http://epasser.aydc.com.cn/article/search.jsp?searchString=ap">ap</A>
</LI>
<LI><A
href="http://epasser.aydc.com.cn/article/search.jsp?searchString=获取">获取</A>
</LI>
<LI><A
href="http://epasser.aydc.com.cn/article/search.jsp?searchString=电池">电池</A>
</LI>
<LI><A
href="http://epasser.aydc.com.cn/article/search.jsp?searchString=电源">电源</A>
</LI>
<LI><A
href="http://epasser.aydc.com.cn/article/search.jsp?searchString=信息">信息</A>
</LI>
<LI><A
href="http://epasser.aydc.com.cn/article/search.jsp?searchString=变更">变更</A>
</LI>
<LI><A
href="http://epasser.aydc.com.cn/article/search.jsp?searchString=通知">通知</A>
</LI>
<LI><A
href="http://epasser.aydc.com.cn/article/search.jsp?searchString=方法">方法</A>
</LI></UL></DIV>
<DIV id=detail>
<DIV id=google_adsense_336_280>
<SCRIPT type=text/javascript><!--
google_ad_client = "pub-4084980245200521";
google_ad_width = 336;
google_ad_height = 280;
google_ad_format = "336x280_as";
google_ad_type = "text_image";
//2007-02-15: 文章详细
google_ad_channel = "3537650081";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "0000FF";
google_color_text = "000000";
google_color_url = "0000FF";
//--></SCRIPT>
<SCRIPT src="应用文--_Net技术库--从AP中获取电池和电源信息变更通知的方法.files/show_ads.js"
type=text/javascript>
</SCRIPT>
</DIV>
<DIV class=con_sample>
<P>在WinCE的项目开发过程中经常要编写AP来获取电池的电量和电源的来源等信息,本文实现了使用WinCE电源管理内部的消息提醒服务来实现对电池信息变更的判断以提高效率。</P></DIV>
<DIV class=con_all>
<P>
<P>在WinCE的项目开发过程中经常要编写AP来获取电池的电量和电源的来源等信息,由于WinCE底层的电池驱动一般以查询的方式得到电池的状态然后更新到一个结构体中,AP可以调用GetSystemPowerStatusEx2来得到这个结构体的数值,为了实时的更新电池的信息AP必须频繁的调用函数去得到数据更新。</P>
<P>其实WinCE的电源管理中已经集成了一种notify机制,会在电池信息发生变化时发出提醒。</P>
<P>RequestPowerNotifications函数可以被AP用来请求接收这种提醒服务。</P>
<P>AP在调用这个API之前必须创建一个消息队列,可以用CreateMsgQueue来实现。</P>
<P>接受提醒的方式是使用WaitForSingleObject来实现,该函数会一直等待直到收到电源管理发来的提醒,然后AP可以去读取消息队列中的数据来判定具体电源系统发生了哪些变化,然后做相关的事情比如更新UI的显示等。</P>
<P>参考源代码:</P>
<P>//#################################################################<BR>#include
<Pm.h><BR>#define QUEUE_ENTRIES 3
<BR>#define MAX_NAMELEN 200
<BR>#define QUEUE_SIZE
(QUEUE_ENTRIES * (sizeof(POWER_BROADCAST) +
MAX_NAMELEN)) <BR>HANDLE hMsgQ;<BR>DWORD WINAPI PowerChangeListen(void *
temp_p)<BR>{<BR> UCHAR buf[QUEUE_SIZE]; <BR> unsigned long
nRead = 0, flags = 0, res = 0;<BR> while(1)<BR> {<BR> DWORD
dwRes =
WaitForSingleObject(hMsgQ,INFINITE);<BR> if(dwRes==WAIT_OBJECT_0)<BR> {<BR> <BR> memset(&buf,
0, QUEUE_SIZE); <BR> if (ReadMsgQueue(hMsgQ,
&buf, QUEUE_SIZE, &nRead, INFINITE,
&flags))<BR> {<BR> PPOWER_BROADCAST
pB = (PPOWER_BROADCAST)&buf;
<BR> PPOWER_BROADCAST_POWER_INFO ppbpi
= (PPOWER_BROADCAST_POWER_INFO) pB->SystemPowerState; </P>
<P> if(pB->Message==PBT_POWERINFOCHANGE)<BR> {<BR> //在这里处理一些电池信息相关数据改变的事情<BR> // MessageBox(NULL,L"Battery
info
change",NULL,NULL);<BR> NKDbgPrintfW(L"[Fred]Battery
info change
BatteryLifePercent=%d\r\n",ppbpi->bBatteryLifePercent);<BR> }</P>
<P> if(pB->Message==PBT_POWERSTATUSCHANGE)<BR> {<BR> //在这里处理一些电源输入状态改变
(AC/Battery)的事情<BR> //MessageBox(NULL,L"Power
input
change",NULL,NULL);<BR> NKDbgPrintfW(L"[Fred]Power
input change
ACIN=%d\r\n",ppbpi->bACLineStatus);<BR> }<BR> }<BR> }<BR> }</P>
<P>}</P>
<P>void
Init_PowerNotify()<BR>{<BR> NKDbgPrintfW(L"[Fred]Init_PowerNotify++\r\n");<BR> MSGQUEUEOPTIONS
options = {0}; <BR> DWORD dwErr;<BR>
<BR> options.dwSize
= sizeof(MSGQUEUEOPTIONS);
<BR> options.dwFlags
= 0; <BR>
options.dwMaxMessages = QUEUE_ENTRIES;
<BR>
options.cbMaxMessage = sizeof(POWER_BROADCAST) +
MAX_NAMELEN; <BR>
options.bReadAccess = TRUE; <BR>
<BR> hMsgQ
= CreateMsgQueue(NULL, &options); </P>
<P> if(!hMsgQ)<BR> {<BR> dwErr=GetLastError();<BR> NKDbgPrintfW(L"[Fred]CreateMsgQueue
failed\r\n");<BR> RETAILMSG(1,
(TEXT("[Fred]CreateMessageQueue ERROR:%d\n"), dwErr));
<BR> return; <BR> }</P>
<P> HANDLE hNotifications = RequestPowerNotifications(hMsgQ,
POWER_NOTIFY_ALL); // Flags
<BR> if
(!hNotifications) {
<BR>
dwErr = GetLastError();
<BR>
RETAILMSG(1, (TEXT("[Fred]RequestPowerNotifications
ERROR:%d\n"), dwErr));
<BR>
StopPowerNotifications(hMsgQ);<BR>
return;<BR> }
<BR> CreateThread(NULL, 0, PowerChangeListen, NULL, 0, NULL);</P>
<P> NKDbgPrintfW(L"[Fred]Init_PowerNotify--\r\n");<BR>}<BR>//###############################################################################################</P>
<P>AP可以把上面的代码全部复制到自己的源码中,然后在初始化的时候调用一次Init_PowerNotify,之后就可以等待消息的发生(中文注释部分)</P>
<P></P></DIV><BR><A
href="http://epasser.aydc.com.cn/article/adp/2-10-1/从AP中获取电池和电源信息变更通知的方法_-_13241.html">引用链接</A>
</DIV>
<DIV class=width986 id=favorite>
<UL>
<LI><A
href="mailto:?Subject=°ÑÕâÆªÎÄÕÂÍÆ¼ö¸øÄã:´ÓAPÖлñÈ¡µç³ØºÍµçÔ´ÐÅÏ¢±ä¸ü֪ͨµÄ·½·¨&body=´ÓAPÖлñÈ¡µç³ØºÍµçÔ´ÐÅÏ¢±ä¸ü֪ͨµÄ·½·¨ÎÄÕµØÖ·:http://epasser.aydc.com.cn/article/adp/2-10-1/content13241.html"><IMG
title=推荐给朋友 alt=推荐给朋友
src="应用文--_Net技术库--从AP中获取电池和电源信息变更通知的方法.files/email_friend.jpg"
align=absBottom border=0> 推荐给朋友</A>
<LI><A
href="http://del.icio.us/post?v=4&noui&jump=close&url=http://epasser.aydc.com.cn/article/adp/2-10-1/从AP中获取电池和电源信息变更通知的方法_-_13241.html&title=从AP中获取电池和电源信息变更通知的方法&notes=从AP中获取电池和电源信息变更通知的方法"
target=_blank><IMG
src="应用文--_Net技术库--从AP中获取电池和电源信息变更通知的方法.files/delicious.png"
border=0>Del.icio.us</A>
<LI><A
href="javascript:window.open('http://shuqian.qq.com/post?title='+encodeURIComponent(document.title)+'&uri='+encodeURIComponent(document.location.href)+'&jumpback=2&noui=1','favit','width=960,height=600,left=50,top=50,toolbar=no,menubar=no,location=no,scrollbars=yes,status=yes,resizable=yes');void(0)"><IMG
style="MARGIN-RIGHT: 2px" alt=收藏到QQ书签
src="应用文--_Net技术库--从AP中获取电池和电源信息变更通知的方法.files/add.gif" align=absMiddle
border=0>收藏到QQ书签</A>
<LI><A
onclick="window.open('http://myweb.cn.yahoo.com/popadd.html?url='+encodeURIComponent(document.location.href)+'&title='+encodeURIComponent(document.title), 'Yahoo','scrollbars=yes,width=780,height=550,left=80,top=80,status=yes,resizable=yes');"
href="http://epasser.aydc.com.cn/article/adp/2/content13241.html#"><IMG
src="应用文--_Net技术库--从AP中获取电池和电源信息变更通知的方法.files/add2myweb.gif"
border=0>添加到雅虎收藏</A> </LI></UL></DIV>
<DIV id=article_googleinfo>
<DIV align=center>::::::本文的相关评价及说明信息:::::: </DIV><BR><BR><FONT size=-1><FONT
color=#cc0033>从AP中获取电池和电源信息变更通知的方法</FONT>. 在WinCE的项目开发过程中经常要编写<FONT
color=#cc0033>AP</FONT>来<FONT color=#cc0033>获取电池</FONT>的电量和<FONT
color=#cc0033>电源</FONT>的来源等<FONT color=#cc0033>信息</FONT>,由于WinCE底层的<FONT
color=#cc0033>电池</FONT>驱动一般以查询的方式得到<FONT
color=#cc0033>电池</FONT>的状态然后更新到一个结构体中,<FONT
color=#cc0033>AP</FONT>可以调用GetSystemPowerStatusEx2来得到这个结构
<B>...</B><BR><BR><FONT
size=-1>唯一下载软件下载,软件,下载,共享,共享软件,免费,免费软件,汉化,汉化补丁,游戏,游戏下载,软件教程,软件新闻,软件资讯,操作系统,邮件.<BR><BR><FONT
size=-1><FONT color=#cc0033>从AP中获取电池和电源信息变更通知的方法</FONT>.
在WinCE的项目开发过程中经常要编写<FONT color=#cc0033>AP</FONT>来<FONT
color=#cc0033>获取电池</FONT>的电量和<FONT color=#cc0033>电源</FONT>的来源等<FONT
color=#cc0033>信息</FONT>,本文实现了使用WinCE<FONT
color=#cc0033>电源</FONT>管理内部的消息提醒服务来实现对<FONT color=#cc0033>电池信息变更</FONT>的判断以提高效率。
u c J#s6z s b%A)g智手移动中文网 8X4M7g;`)Q <B>...</B><BR><BR><FONT
size=-1>在WinCE的项目开发过程中经常要编写<FONT color=#cc0033>AP</FONT>来<FONT
color=#cc0033>获取电池</FONT>的电量和<FONT color=#cc0033>电源</FONT>的来源等<FONT
color=#cc0033>信息</FONT>,由于WinCE底层的<FONT color=#cc0033>电池</FONT>驱动一般以查询的方式得到<FONT
color=#cc0033>电池</FONT>的状态然后更新到一个结构体中,<FONT
color=#cc0033>AP</FONT>可以调用GetSystemPowerStatusEx2来得到这个结构体的数值,为了实时的更新<FONT
color=#cc0033>电池</FONT>的<FONT color=#cc0033>信息AP</FONT>必须
<B>...</B><BR><BR><FONT size=-1><FONT
color=#cc0033>从AP中获取电池和电源信息变更通知的方法</FONT>,讯旗网-<FONT
color=#cc0033>信息</FONT>时代的领航者.<BR><BR><FONT size=-1><FONT
color=#cc0033>从AP中获取电池和电源信息变更通知的方法</FONT>,.NET专栏,程序开发,技术部落.<BR><BR><FONT
size=-1><FONT color=#cc0033>从AP中获取电池和电源信息变更通知的方法</FONT>. 作者:佚名文章来源:不详点击数:
更新时间:2007-5-26 0:46:21. 在WinCE的项目开发过程中经常要编写<FONT color=#cc0033>AP</FONT>来<FONT
color=#cc0033>获取电池</FONT>的电量和<FONT color=#cc0033>电源</FONT>的来源等<FONT
color=#cc0033>信息</FONT>,本文实现了使用WinCE<FONT
color=#cc0033>电源</FONT>管理内部的消息提醒服务来实现对<FONT color=#cc0033>电池信息</FONT>
<B>...</B><BR><BR><FONT
size=-1>ASP,ASP.NET,PHP,AJAX,CSS+DIV,VB,DELPHI,C/C++,MSSQL,MYSQL技术文档.<BR><BR><FONT
size=-1>网络大杂烩(edzh.com) -<FONT color=#cc0033>从AP中获取电池和电源信息变更通知的方法</FONT>.
<B>...</B> 在WinCE的项目开发过程中经常要编写<FONT color=#cc0033>AP</FONT>来<FONT
color=#cc0033>获取电池</FONT>的电量和<FONT color=#cc0033>电源</FONT>的来源等<FONT
color=#cc0033>信息</FONT>,由于WinCE底层的<FONT color=#cc0033>电池</FONT>驱动一般以查询的方式得到<FONT
color=#cc0033>电池</FONT>的状态然后更新到一个结构体中,<FONT color=#cc0033>AP</FONT>可以
<B>...</B><BR><BR></DIV></DIV></DIV>
<DIV id=piede>
<DIV class=bottomleft>
<DIV class=contenuto>
<P>© 1997-2007 ePasser .LTD | P.Iva: 03485378035</P>
<UL>
<LI><A href="http://epasser.aydc.com.cn/">电子书 @ ePasser</A> </LI>
<LI><A href="http://epasser.aydc.com.cn/ebook/blbfwd/index.html">图文目录</A>
</LI>
<LI><A href="http://epasser.aydc.com.cn/article/albf/2-1/0/index.html">范文</A>
</LI>
<LI><A href="http://epasser.aydc.com.cn/hot.jsp">Hot...</A> </LI>
<LI><A href="http://epasser.aydc.com.cn/ebook/feed/?categoryId=1"><IMG
height=14 alt="Feed RSS di HTML.it"
src="应用文--_Net技术库--从AP中获取电池和电源信息变更通知的方法.files/rss.gif" width=41></A> </LI>
<LI><A href="http://epasser.aydc.com.cn/firefox/index.htm"
alt="firefox 浏览器 下载"><IMG
src="应用文--_Net技术库--从AP中获取电池和电源信息变更通知的方法.files/blank1_1.gif" border=0></A>
</LI></UL></DIV></DIV></DIV></DIV></DIV>
<SCRIPT src="应用文--_Net技术库--从AP中获取电池和电源信息变更通知的方法.files/urchin.js"
type=text/javascript>
</SCRIPT>
<SCRIPT type=text/javascript>
_uacct = "UA-867646-1";
urchinTracker();
</SCRIPT>
</FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></FONT></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -