📄 csdn_文档中心_完全控制你的windows桌面.htm
字号:
Controls, Forms, Dialogs,<BR> StdCtrls;</P>
<P>type<BR> TForm1 = class(TForm)<BR>
CheckBox1: TCheckBox;<BR> CheckBox2:
TCheckBox;<BR> CheckBox3:
TCheckBox;<BR> CheckBox4:
TCheckBox;<BR> CheckBox5:
TCheckBox;<BR> CheckBox6:
TCheckBox;<BR> CheckBox7:
TCheckBox;<BR> procedure FormCreate(Sender:
TObject);<BR> private<BR> procedure
CheckButtonClick(Sender:TObject);<BR> { Private
declarations }<BR> public<BR> { Public
declarations }<BR> end;<BR>Const<BR><A
href="file://定/">file://定/</A>义不同窗口的类名<BR>sTrayWindow =
'Shell_TrayWnd';<BR>sTrayNotify = 'TrayNotifyWnd';<BR>sStartButton =
'Button';<BR>sAppSwitchBar = 'ReBarWindow32';<BR>sAppSwitch =
'MSTaskSwWClass';<BR>sAppIcon = 'ToolbarWindow32';<BR>sTrayClock =
'TrayClockWClass';<BR>sDesktopIcon = 'ShellDll_DefView';<BR>sProgman
= 'Progman';</P>
<P>var<BR> Form1: TForm1;<BR> wnd:Integer;</P>
<P>implementation</P>
<P>{$R *.DFM}</P>
<P>procedure TForm1.FormCreate(Sender: TObject);<BR>begin<BR>
CheckBox1.Caption := '隐藏任务栏';<BR> CheckBox1.OnClick :=
CheckButtonClick;<BR> CheckBox2.Caption := '隐藏开始按钮';<BR>
CheckBox2.OnClick := CheckButtonClick;<BR> CheckBox3.Caption
:= '隐藏任务栏图标';<BR> CheckBox3.OnClick :=
CheckButtonClick;<BR> CheckBox4.Caption := '隐藏程序按钮';<BR>
CheckBox4.OnClick := CheckButtonClick;<BR> CheckBox5.Caption
:= '隐藏任务栏时钟';<BR> CheckBox5.OnClick :=
CheckButtonClick;<BR> CheckBox6.Caption := '隐藏桌面图标';<BR>
CheckBox6.OnClick := CheckButtonClick;<BR> CheckBox7.Caption
:= '隐藏快速运行图标';<BR> CheckBox7.OnClick :=
CheckButtonClick;<BR>end;</P>
<P><A
href="file://7/">file://7/</A>个CheckBox控件的Click处理函数<BR>procedure
TForm1.CheckButtonClick(Sender:TObject);<BR>var<BR>
i:Integer;<BR>begin<BR> <A
href="file://找/">file://找/</A>到任务栏窗口的窗口句柄<BR> wnd :=
FindWindow(sTrayWindow, nil);</P>
<P> if (TCheckBox(Sender).Name)= 'CheckBox2'
then<BR> wnd := FindWindowEx(wnd, 0, sStartButton,
nil);</P>
<P> if (TCheckBox(Sender).Name)= 'CheckBox3'
then<BR> wnd := FindWindowEx(wnd, 0, sTrayNotify,
nil);</P>
<P> if (TCheckBox(Sender).Name)= 'CheckBox4' then
begin<BR> wnd := FindWindowEx(wnd, 0,
sAppSwitchBar, nil);<BR> wnd := FindWindowEx(wnd,
0, sAppSwitch, nil);<BR> end;</P>
<P> if (TCheckBox(Sender).Name)= 'CheckBox5' then
begin<BR> wnd := FindWindowEx(wnd, 0, sTrayNotify,
nil);<BR> wnd := FindWindowEx(wnd, 0, sTrayClock,
nil);<BR> end;</P>
<P> if (TCheckBox(Sender).Name)= 'CheckBox6' then
begin<BR> wnd := FindWindow(sProgman,
nil);<BR> wnd := FindWindowEx(wnd, 0,
sDesktopIcon, nil);<BR> end;</P>
<P> if (TCheckBox(Sender).Name)= 'CheckBox7' then
begin<BR> wnd := FindWindowEx(wnd, 0,
sAppSwitchBar, nil);<BR> wnd := FindWindowEx(wnd,
0, sAppIcon, nil);<BR> end;</P>
<P> if TCheckBox(Sender).Checked then<BR>
ShowWindow (wnd, SW_HIDE)<BR> Else<BR>
ShowWindow (wnd, SW_SHOW);<BR>end;<BR>end.</P>
<P> 运行程序,分别点击不同的选择框,可以分别隐藏任务栏或任务栏上的不同部分。</P>
<P>
下面再来介绍如何操控桌面图标。设置图标文本的背景和颜色以及设置图标的排列。通过上面的介绍<BR>上面我们知道,Windows的桌面也是一个窗口,不同的它是一个ListView类窗口,对于ListView类窗口,有<BR>一系列的以LVM_开头的消息,通过Windows
API函数SendMessage向ListView类窗口发送这些消息就可以控<BR>制窗口的一些属性,而且在Delphi中还有一系列的以ListView_开头的函数,这些函数可以代替LVM_类消息。<BR>
具体的范例如下:首先建立一个新的Delphi工程,然后在Form1中加入两个CommandButton控件,然后在<BR>Form1中加入以下的代码:<BR>unit
Unit1;</P>
<P>interface</P>
<P>uses<BR> Windows, Messages, SysUtils, Classes, Graphics,
Controls, Forms, Dialogs,<BR> ComCtrls, StdCtrls,Commctrl;</P>
<P>type<BR> TForm1 = class(TForm)<BR>
Button1: TButton;<BR> Button2:
TButton;<BR> procedure Button1Click(Sender:
TObject);<BR> procedure Button2Click(Sender:
TObject);<BR> procedure FormCreate(Sender:
TObject);<BR> private<BR> { Private
declarations }<BR> public<BR> { Public
declarations }<BR> end;</P>
<P>var<BR> Form1: TForm1;</P>
<P>implementation</P>
<P>{$R *.DFM}<BR>procedure SetDesktopIconColor(Forground,
Background: TColor; Trans: Boolean);<BR>var<BR> Window:
HWND;<BR>begin<BR> Window := FindWindow('Progman', 'Program
Manager');<BR> <A
href="file://找/">file://找/</A>到桌面窗口<BR> Window :=
FindWindowEx(Window, HWND(nil), 'SHELLDLL_DefView', '');<BR>
<A href="file://找/">file://找/</A>到放置桌面图标的ListView窗口<BR> Window
:= FindWindowEx(Window, HWND(nil), 'SysListView32', '');</P>
<P> if Trans
then <A
href="file://设/">file://设/</A>置透明的文字背景色<BR>
ListView_SetTextBkColor(Window, $ffffffff) // back color<BR>
else
<A href="file://设/">file://设/</A>置不透明的文字背景色<BR>
ListView_SetTextBkColor(Window, Background); // back color</P>
<P> ListView_SetTextColor(Window, Forground); // foreground
color<BR> <A href="file://重/">file://重/</A>新绘制桌面图标<BR>
ListView_RedrawItems(Window, 0, ListView_GetItemCount(Window) -
1);<BR> UpdateWindow(Window); <A
href="file://重/">file://重/</A>新绘制窗口<BR>end;</P>
<P>procedure
SetDeskTopIconArr(iWidth,iHeight:Integer);<BR>var<BR> Window:
HWND;<BR> i,i1,i2,iCount:integer;<BR>begin<BR> Window :=
FindWindow('Progman', 'Program Manager');<BR> Window :=
FindWindowEx(Window, HWND(nil), 'SHELLDLL_DefView', '');<BR>
Window := FindWindowEx(Window, HWND(nil), 'SysListView32', '');</P>
<P> <A href="file://设/">file://设/</A>置图标与边界的距离。<BR>
i1:=20;i2:=20;</P>
<P> <A href="file://获/">file://获/</A>得桌面图标的个数<BR>
iCount:=ListView_GetItemCount(Window)-1;<BR> for i:=0 to
iCount do begin<BR> <A
href="file://设/">file://设/</A>置图标位置<BR>
ListView_SetItemPosition(Window,i,i1,i2);<BR>
i1:=i1+iWidth;<BR> if i1>(Screen.Width-32) then
begin<BR>
i1:=20;<BR>
i2:=i2+iHeight;<BR> end;<BR> end;<BR>
ListView_RedrawItems(Window, 0, ListView_GetItemCount(Window) -
1);<BR> UpdateWindow(Window);<BR>end;</P>
<P>procedure SetDefaultIconColors;<BR>var<BR> Kind:
Integer;<BR> Color: TColor;<BR>begin<BR> Kind :=
COLOR_DESKTOP;<BR> Color :=
GetSysColor(COLOR_DESKTOP);<BR> SetSysColors(1, Kind,
Color);<BR>end;</P>
<P>procedure TForm1.Button1Click(Sender:
TObject);<BR>begin<BR> <A
href="file://你/">file://你/</A>可以改变clWhite,clBlack为其它的颜色值看看<BR>
<A href="file://图/">file://图/</A>标文本颜色的变化<BR>
SetDesktopIconColor(clWhite,clBlack,True);<BR>end;</P>
<P>procedure TForm1.Button2Click(Sender:
TObject);<BR>begin<BR> <A
href="file://设/">file://设/</A>置图标的间距为100个像素<BR>
SetDeskTopIconArr(100,100);<BR>end;</P>
<P>procedure TForm1.FormCreate(Sender: TObject);<BR>begin<BR>
Button1.Caption := '设置图标文本颜色';<BR> Button2.Caption :=
'设置图标排列';<BR>end;</P>
<P>end.</P>
<P>
在上面的程序中,函数SetDesktopIconColor设置图标文本的前景色、背景色和透明,参数ForeGround<BR>BackGround分别指定文本的前景色和背景色,参数Trans指定文本的背景是否透明(如果有背景图案的话)。<BR>函数SetDeskTopIconArr排列桌面图标,参数iWidth,iHeight分别指定图标之间的横向纵向距离。如果要使<BR>SetDeskTopIconArr函数生效,就需要将桌面图标的自动排列选项去掉。另外ListView类还有其它的控制消息<BR>利用这些消息可以控制更多的桌面图标选项。有兴趣的朋友可以察看MSDN库。<BR>
以上程序由Delphi5编写,在Windows98 Windows2000下运行通过。</P>
<P> </P><BR></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
<TABLE align=center bgColor=#006699 border=0 cellPadding=0 cellSpacing=0
width=770>
<TBODY>
<TR bgColor=#006699>
<TD align=middle bgColor=#006699 id=white><FONT
color=#ffffff>对该文的评论</FONT></TD>
<TD align=middle>
<SCRIPT src="CSDN_文档中心_完全控制你的Windows桌面.files/readnum.htm"></SCRIPT>
</TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1
width=770>
<TBODY>
<TR>
<TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16
hspace=1 src="CSDN_文档中心_完全控制你的Windows桌面.files/ico_pencil.gif" width=16>
</SPAN> ozx <I>(2001-1-29 4:46:10)</I> </TD></TR>
<TR>
<TD bgColor=#ffffff colSpan=3 width=532><BR>怎么Delphi的跑到VC了?
<BR></TD></TR></TBODY></TABLE><BR>
<DIV align=center>
<TABLE align=center bgColor=#cccccc border=0 cellPadding=2 cellSpacing=1
width=770>
<TBODY>
<TR>
<TH bgColor=#006699 id=white><FONT
color=#ffffff>我要评论</FONT></TH></TR></TBODY></TABLE></DIV>
<DIV align=center>
<TABLE border=0 width=770>
<TBODY>
<TR>
<TD>你没有登陆,无法发表评论。 请先<A
href="http://www.csdn.net/member/login.asp?from=/Develop/read_article.asp?id=3287">登陆</A>
<A
href="http://www.csdn.net/expert/zc.asp">我要注册</A><BR></TD></TR></TBODY></TABLE></DIV><BR>
<HR noShade SIZE=1 width=770>
<TABLE border=0 cellPadding=0 cellSpacing=0 width=500>
<TBODY>
<TR align=middle>
<TD height=10 vAlign=bottom><A
href="http://www.csdn.net/intro/intro.asp?id=2">网站简介</A> - <A
href="http://www.csdn.net/intro/intro.asp?id=5">广告服务</A> - <A
href="http://www.csdn.net/map/map.shtm">网站地图</A> - <A
href="http://www.csdn.net/help/help.asp">帮助信息</A> - <A
href="http://www.csdn.net/intro/intro.asp?id=2">联系方式</A> - <A
href="http://www.csdn.net/english">English</A> </TD>
<TD align=middle rowSpan=3><A
href="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202001032100010"><IMG
border=0 height=48 src="CSDN_文档中心_完全控制你的Windows桌面.files/biaoshi.gif"
width=40></A></TD></TR>
<TR align=middle>
<TD vAlign=top>百联美达美公司 版权所有 京ICP证020026号</TD></TR>
<TR align=middle>
<TD vAlign=top><FONT face=Verdana>Copyright © CSDN.net, Inc. All rights
reserved</FONT></TD></TR>
<TR>
<TD height=15></TD>
<TD></TD></TR></TBODY></TABLE></DIV>
<DIV></DIV><!--内容结束//--><!--结束//--></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -