📄 在c++ builder中实现桌布自动更新.htm
字号:
style="mso-spacerun: yes"> </SPAN>{</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes"> </SPAN>delete
Registry;</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes"> </SPAN>}</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman">}</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-tab-count: 1">
</SPAN>//</FONT></SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">设置桌布</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT
face="Times New Roman">SystemParametersInfo(SPI_SETDESKWALLPAPER,
0,FileName.c_str(),SPIF_UPDATEINIFILE |
SPIF_SENDWININICHANGE);</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT
face="Times New Roman"> <o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">在此</SPAN><SPAN
lang=EN-US><FONT face="Times New Roman">,</FONT></SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">我们已经解决了最为关键的问题</SPAN><SPAN
lang=EN-US><FONT face="Times New Roman">,</FONT></SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">剩下的关于设置定时器那就简单了</SPAN><SPAN
lang=EN-US><FONT face="Times New Roman">,</FONT></SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">只需用一个定时器组件即可完成</SPAN><SPAN
lang=EN-US><FONT face="Times New Roman">.</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">代码如下</SPAN><SPAN
lang=EN-US><FONT face="Times New Roman">:</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT
face="Times New Roman"> <o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman">void __fastcall
TForm1::Timer1Timer(TObject *Sender)</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman">{</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes"> </SPAN>if
(ListBox1->Items->Count<=0)</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>{</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>return ;</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>}</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT
face="Times New Roman"> <o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes"> </SPAN>if
(index>=ListBox1->Items->Count)</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>{</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>index=0;</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>}</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>//</FONT></SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">如果是</SPAN><SPAN
lang=EN-US><FONT face="Times New Roman">JPG</FONT></SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">格式就将其转换为</SPAN><SPAN
lang=EN-US><FONT face="Times New Roman">BMP</FONT></SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">格式</SPAN><SPAN
lang=EN-US><FONT face="Times New Roman">,</FONT></SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">将其存到临时文件夹中</SPAN></P>
<P class=MsoBodyTextIndent style="MARGIN: 0cm 0cm 0pt auto"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>if(UpperCase(ListBox1->Items->Strings[index]).Pos(".JPG")||UpperCase(ListBox1->Items->Strings[index]).Pos(".JPEG"))</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>{</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>AnsiString
fileName=ExtractFileName(ListBox1->Items->Strings[index]);</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>int len=fileName.LastDelimiter(".");</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>fileName=fileName.SubString(0,len-1)+".bmp";</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>unsigned int *size=new unsigned int(256);</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>char * buffer=new char[256];</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>GetTempPath(*size,buffer);</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>fileName=AnsiString(buffer)+fileName;</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>JPEGToBMP(ListBox1->Items->Strings[index],fileName);</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>//</FONT></SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">设置桌布</SPAN></P>
<P class=MsoBodyTextIndent2 style="MARGIN: 0cm 0cm 0pt auto"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>SystemParametersInfo(SPI_SETDESKWALLPAPER,0,ListBox1->Items->Strings[index].c_str(),SPIF_UPDATEINIFILE
| SPIF_SENDWININICHANGE);</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>}</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>else</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>{</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT face="Times New Roman"><SPAN
style="mso-spacerun: yes">
</SPAN>//</FONT></SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">设置桌布</SPAN></P>
<P class=MsoNormal
style="M
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -