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

📄 应用文--_net技术库--从ap中获取电池和电源信息变更通知的方法.htm

📁 wince 电池电源管理文件集 wince 电池电源管理文件集
💻 HTM
📖 第 1 页 / 共 3 页
字号:
  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 
&lt;Pm.h&gt;<BR>#define&nbsp; QUEUE_ENTRIES&nbsp;&nbsp;&nbsp; 3&nbsp; 
<BR>#define&nbsp; MAX_NAMELEN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 200&nbsp; 
<BR>#define&nbsp; QUEUE_SIZE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
(QUEUE_ENTRIES&nbsp; *&nbsp; (sizeof(POWER_BROADCAST)&nbsp; +&nbsp; 
MAX_NAMELEN))&nbsp; <BR>HANDLE hMsgQ;<BR>DWORD WINAPI PowerChangeListen(void * 
temp_p)<BR>{<BR>&nbsp;UCHAR&nbsp; buf[QUEUE_SIZE];&nbsp; <BR>&nbsp;unsigned long 
nRead = 0, flags = 0, res = 0;<BR>&nbsp;while(1)<BR>&nbsp;{<BR>&nbsp;&nbsp;DWORD 
dwRes = 
WaitForSingleObject(hMsgQ,INFINITE);<BR>&nbsp;&nbsp;if(dwRes==WAIT_OBJECT_0)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;memset(&amp;buf,&nbsp; 
0,&nbsp; QUEUE_SIZE);&nbsp; <BR>&nbsp;&nbsp;&nbsp;if (ReadMsgQueue(hMsgQ, 
&amp;buf, QUEUE_SIZE, &amp;nRead, INFINITE, 
&amp;flags))<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;PPOWER_BROADCAST&nbsp; 
pB&nbsp; =&nbsp; (PPOWER_BROADCAST)&amp;buf; 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;PPOWER_BROADCAST_POWER_INFO&nbsp; ppbpi&nbsp; 
=&nbsp; (PPOWER_BROADCAST_POWER_INFO)&nbsp; pB-&gt;SystemPowerState;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;if(pB-&gt;Message==PBT_POWERINFOCHANGE)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//在这里处理一些电池信息相关数据改变的事情<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;MessageBox(NULL,L"Battery 
info 
change",NULL,NULL);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NKDbgPrintfW(L"[Fred]Battery 
info change 
BatteryLifePercent=%d\r\n",ppbpi-&gt;bBatteryLifePercent);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;if(pB-&gt;Message==PBT_POWERSTATUSCHANGE)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//在这里处理一些电源输入状态改变 
(AC/Battery)的事情<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //MessageBox(NULL,L"Power 
input 
change",NULL,NULL);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NKDbgPrintfW(L"[Fred]Power 
input change 
ACIN=%d\r\n",ppbpi-&gt;bACLineStatus);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}<BR>&nbsp;}<BR>&nbsp;}</P>
<P>}</P>
<P>void 
Init_PowerNotify()<BR>{<BR>&nbsp;NKDbgPrintfW(L"[Fred]Init_PowerNotify++\r\n");<BR>&nbsp;MSGQUEUEOPTIONS&nbsp; 
options&nbsp; =&nbsp; {0}; <BR>&nbsp;DWORD dwErr;<BR>&nbsp;&nbsp; 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; options.dwSize&nbsp; 
=&nbsp; sizeof(MSGQUEUEOPTIONS);&nbsp; 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; options.dwFlags&nbsp; 
=&nbsp; 0;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
options.dwMaxMessages&nbsp; =&nbsp; QUEUE_ENTRIES;&nbsp; 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
options.cbMaxMessage&nbsp; =&nbsp; sizeof(POWER_BROADCAST)&nbsp; +&nbsp; 
MAX_NAMELEN;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
options.bReadAccess&nbsp; =&nbsp; TRUE;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hMsgQ&nbsp; 
=&nbsp; CreateMsgQueue(NULL,&nbsp; &amp;options);&nbsp; </P>
<P>&nbsp;if(!hMsgQ)<BR>&nbsp;{<BR>&nbsp;&nbsp;dwErr=GetLastError();<BR>&nbsp;&nbsp;NKDbgPrintfW(L"[Fred]CreateMsgQueue 
failed\r\n");<BR>&nbsp;&nbsp;&nbsp;&nbsp; RETAILMSG(1,&nbsp; 
(TEXT("[Fred]CreateMessageQueue&nbsp; ERROR:%d\n"),&nbsp; dwErr));&nbsp; 
<BR>&nbsp;&nbsp;return;&nbsp;&nbsp;<BR>&nbsp;}</P>
<P>&nbsp;HANDLE hNotifications&nbsp; =&nbsp; RequestPowerNotifications(hMsgQ, 
POWER_NOTIFY_ALL);&nbsp; //&nbsp; Flags&nbsp; 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if&nbsp; 
(!hNotifications)&nbsp; {&nbsp; 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
dwErr&nbsp; =&nbsp; GetLastError();&nbsp; 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
RETAILMSG(1,&nbsp; (TEXT("[Fred]RequestPowerNotifications&nbsp; 
ERROR:%d\n"),&nbsp; dwErr));&nbsp; 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;StopPowerNotifications(hMsgQ);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
return;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp; 
<BR>&nbsp;CreateThread(NULL, 0, PowerChangeListen, NULL, 0, NULL);</P>
<P>&nbsp;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ÖлñÈ¡µç³ØºÍµçÔ´ÐÅÏ¢±ä¸ü֪ͨµÄ·½·¨&amp;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&amp;noui&amp;jump=close&amp;url=http://epasser.aydc.com.cn/article/adp/2-10-1/从AP中获取电池和电源信息变更通知的方法_-_13241.html&amp;title=从AP中获取电池和电源信息变更通知的方法&amp;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)+'&amp;uri='+encodeURIComponent(document.location.href)+'&amp;jumpback=2&amp;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)+'&amp;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 &nbsp; | &nbsp; 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 + -