📄 [zz]从ap中获取电池和电源信息变更通知的方法_silentmj的个人空间.htm
字号:
<TBODY>
<TR>
<TD class=modtl width=7> </TD>
<TD class=modtc noWrap>
<DIV class=modhead><SPAN class=modtit>查看文章</SPAN></DIV></TD>
<TD class=modtc noWrap align=right></TD>
<TD class=modtr width=7> </TD></TR></TBODY></TABLE>
<DIV class=modbox id=m_blog>
<DIV class=tit>[zz]从AP中获取电池和电源信息变更通知的方法</DIV>
<DIV class=date>2007-11-30 14:04</DIV>
<TABLE style="TABLE-LAYOUT: fixed">
<TBODY>
<TR>
<TD>
<DIV class=cnt><U><FONT color=#800080>从AP中获取电池和电源信息变更通知的方法
</FONT></U> <SPAN title=文章指数:39><IMG
src="[zz]从AP中获取电池和电源信息变更通知的方法_silentmj的个人空间.files/star.gif" border=0><IMG
src="[zz]从AP中获取电池和电源信息变更通知的方法_silentmj的个人空间.files/star_half.gif"
border=0></SPAN> <IMG
title="CSDN Blog推出文章指数概念,文章指数是对Blog文章综合评分后推算出的,综合评分项分别是该文章的点击量,回复次数,被网摘收录数量,文章长度和文章类型;满分100,每月更新一次."
alt="CSDN Blog推出文章指数概念,文章指数是对Blog文章综合评分后推算出的,综合评分项分别是该文章的点击量,回复次数,被网摘收录数量,文章长度和文章类型;满分100,每月更新一次."
src="[zz]从AP中获取电池和电源信息变更通知的方法_silentmj的个人空间.files/ask.gif" border=0>
<DIV class=postText>
<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></DIV></DIV></TD></TR></TBODY></TABLE><BR>
<DIV class=opt><A title=查看该分类中所有文章
href="http://hi.baidu.com/silentmj/blog/category/qǶÈëʽ">类别:q嵌入式</A> | <A
title=将此文章添加到百度搜藏 onclick="return addToFavor();"
href="http://cang.baidu.com/do/add" target=_blank>添加到搜藏</A> | 浏览(<SPAN
id=result></SPAN>) | <A
href="http://hi.baidu.com/silentmj/blog/item/d6339917148177024a90a7b3.html#send">评论</A> (0)
</DIV>
<DIV class=line></DIV>
<SCRIPT language=javascript>
/*<![CDATA[*/
var pre = [true,'[zz]WinCE中的Flash分区和CheckS...', '/silentmj/blog/item/6f0920efe7185315fdfa3cb2.html'];
var post = [true,'[zz]用Visual C++操作INI文件', '/silentmj/blog/item/e1d601189f6b14b74aedbc81.html'];
if(pre[0] || post[0]){
document.write('<div id="in_nav">');
if(pre[0]){
document.write('上一篇:<a href="' + pre[2] + '">' + pre[1] + '</a> ');
}
if(post[0]){
document.write('下一篇:<a href="' + post[2] + '">' + post[1] + '</a>');
}
document.write('</div>');
document.write('<div class="line"> </div>');
}
/*]]>*/
</SCRIPT>
<DIV id=in_reader>
<DIV class=tit>最近读者:</DIV>
<SCRIPT>
var g_spAnnony=true;
var g_read=[
{}
];
g_read.length=g_read.length-1;
var _rh1="";
var _rh2="";
function wrreader(){
_rh1 += '<table width="100%" ><tr>';
_rh2+='<tr>';
if(g_spAnnony){
_rh1+='<td align="center" width="10%" ><img border="0" width="55" height="55" src="http://img.baidu.com/hi/img/portraitn.jpg"></td>';
_rh2+='<td> </td>';
if(g_read.length>0){
_rh1+='<td align="left" width="12%">';
}else{
_rh1+='<td align="left" width="100%">';
}
_rh1+="<a href='http://passport.baidu.com/?login&tpl=sp&tpl_reg=sp&u="+myref+"' target='_self'>登录</a>后,您就出现在这里。</td>";
_rh2+='<td> </td>'
}
if(g_read.length==0){
if(!g_spAnnony){
_rh1+='<td align=left width="100%">最近还没有登录用户看过这篇文章……</td>';
_rh2+='<td> </td>';
}
}else{
for(i=0,len=g_read.length;i<len;i++){
_rh1+='<td align="center" valign="bottom" width="10%" class="user"><a href="/'+g_read[i][0]+'" target="_blank"><img border="0" src="http://himg.baidu.com/sys/portraitn/item/'+g_read[i][1]+'.jpg"></a></td>';
_rh2+='<td align="center" valign="top" class="user"><a href="/'+g_read[i][0]+'" target="_blank">'+g_read[i][2]+'</a></td>';
}
}
_rh1+='<td width="100%"></td></tr>';
_rh2+='<td></td></tr></table>';
document.write(_rh1+_rh2);
}
wrreader();
</SCRIPT>
</DIV>
<DIV class=line></DIV>
<SCRIPT language=JavaScript>
allkey=allkey+"24a2d2fbab34c4166c22ebfb_d6339917148177024a90a7b3_";
</SCRIPT>
<DIV id=in_comment><A name=comment></A>
<DIV class=tit>网友评论:</DIV>
<SCRIPT>
function writecmt(type,id,cmtname,cmturl,portraitId){
var html1="";
if(type==1){
html1="<a name='"+id+"' href='"+cmturl+"' target='_blank' title='"+cmturl+"'><img border='0' src='http://himg.baidu.com/sys/portraitn/item/"+portraitId+".jpg'><br>"+cmtname+"</a>";
}else{
if(cmtname=="" || cmtname=="匿名网友"){
if(cmturl==""){
html1="<a name='"+id+"'>匿名网友</a>";
}else{
html1="<a name='"+id+"' href='"+cmturl+"' target='_blank' title='"+cmturl+"'>"+cmtname+"</a>";
}
}else{
if(cmturl==""){
html1="<div class='f14' style='display:inline'>网友:<a name='"+id+"'>"+cmtname+"</a></div>";
}else{
html1="<div class='f14' style='display:inline'>网友:<a name='"+id+"' href='"+cmturl+"' target='_blank' title='"+cmturl+"'>"+cmtname+"</a></div>";
}
}
}
document.write(html1);
}
</SCRIPT>
<DIV id=page></DIV></DIV>
<DIV id=in_send><A name=send></A>
<FORM id=popFormSubmit name=form1 onsubmit="return checkcmtform()"
action=/silentmj/commit method=post><INPUT type=hidden value=8 name=ct> <INPUT
type=hidden value=1 name=cm> <INPUT type=hidden value=d6339917148177024a90a7b3
name=spBlogID>
<SCRIPT language=JavaScript>
document.write("<input type='hidden' name='spRefURL' value='"+window.location.href+"'>");
</SCRIPT>
<DIV class=tit>发表评论:</DIV>
<TABLE cellSpacing=5 cellPadding=0 width=620 border=0>
<TBODY>
<TR>
<TD class=f14>姓 名:</TD>
<TD><INPUT id=spBlogCmtor style="WIDTH: 220px" onfocus=hidErr(1);
tabIndex=1 maxLength=49 onchange="checkname('spBlogCmtor')"
name=spBlogCmtor>
<SCRIPT>
document.write(" <a href='http://passport.baidu.com/?reg&tpl=sp&return_method=get&skip_ok=1&u=http://hi.baidu.com/sys/reg/' target='_blank'>注册</a>");
document.write(" | <a href='http://passport.baidu.com/?login&tpl=sp&tpl_reg=sp&u="+myref+"'>登录</a>");
</SCRIPT>
<DIV id=nmerror style="DISPLAY: none">*姓名最长为50字节</DIV></TD></TR>
<TR id=1_err style="DISPLAY: none">
<TD> </TD>
<TD>
<DIV class=error id=1_err_con></DIV></TD></TR>
<TR>
<TD class=f14>网址或邮箱:</TD>
<TD><INPUT id=spBlogCmtURL style="WIDTH: 360px" onfocus=hidErr(2);
tabIndex=2 maxLength=128 onchange="checkeandu('spBlogCmtURL')"
name=spBlogCmtURL> (选填)</TD>
<SCRIPT>
G("spBlogCmtor").value="";
G("spBlogCmtURL").value="";
</SCRIPT>
</TR>
<TR id=2_err style="DISPLAY: none">
<TD> </TD>
<TD>
<DIV class=error id=2_err_con></DIV></TD></TR>
<TR>
<TD class=f14 vAlign=top>内 容:</TD>
<TD><TEXTAREA id=spBlogCmtText style="WIDTH: 520px; HEIGHT: 155px" onfocus=hidErr(3); tabIndex=3 name=spBlogCmtText></TEXTAREA>
<SCRIPT>
G("spBlogCmtor").value=G("spBlogCmtor").defaultValue;
G("spBlogCmtText").value="";
</SCRIPT>
</TD></TR>
<TR id=3_err style="DISPLAY: none">
<TD> </TD>
<TD>
<DIV class=error id=3_err_con></DIV></TD></TR>
<TR id=vercode>
<TD class=f14 vAlign=top>验证码:</TD>
<TD vAlign=top><INPUT type=hidden
value=AE0F2029771D8B2A7F1A639F8A8547657D5974F3CB3E6AEA1B71720189DFDE3D276E0A523782F99233035F36007EDA27FF5C478E6BFCECD25E44E3CC69622A55
name=spVcode> <INPUT id=spVerifyKey tabIndex=4 maxLength=4 size=6
name=spVerifyKey autocomplete="off">请输入下图中的四位验证码,字母不区分大小写。<BR>
<SCRIPT language=JavaScript>
var imgsrc="http://post.baidu.com/cgi-bin/genimg?AE0F2029771D8B2A7F1A639F8A8547657D5974F3CB3E6AEA1B71720189DFDE3D276E0A523782F99233035F36007EDA27FF5C478E6BFCECD25E44E3CC69622A55";
document.write("<img id='verifypic' src='"+imgsrc+"' width='120' height='40'>");
function newverifypic(){
document.getElementById("verifypic").src = imgsrc +"&t="+ Math.random();
}
</SCRIPT>
<A title=看不清左边的字符 href="javascript:newverifypic();">看不清?</A> </TD></TR>
<TR>
<TD class=f14 vAlign=top> </TD>
<TD class=f14 vAlign=top><INPUT id=btn_ok tabIndex=5 type=submit value=发表评论 name=btn_ok></TD></TR></TBODY></TABLE></FORM></DIV><BR></DIV>
<TABLE height=8 cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD class=modbl width=7> </TD>
<TD class=modbc> </TD>
<TD class=modbr width=7> </TD></TR></TBODY></TABLE></DIV></DIV></DIV></DIV>
<SCRIPT language=javascript>
<!--
var hstr="/silentmj/brwstat?key1=1";
document.write("<script src='"+hstr+"&key2="+allkey+"'><\/script>");
//-->
</SCRIPT>
<BR>
<CENTER>
<DIV id=ft>©2007 Baidu</DIV></CENTER>
<SCRIPT>
if(document.getElementById("m_blog"))
{
var imgarray = document.getElementById("m_blog").getElementsByTagName('img');
var imgw = document.getElementById("m_blog").offsetWidth;
imgw =imgw-40;
for(var i=0; i<imgarray.length; i++){
if(imgarray[i].className=="blogimg" && imgarray[i].width>=imgw) imgarray[i].width=imgw;
}
}
</SCRIPT>
</CENTER><IMG style="DISPLAY: none" src=""> </BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -