程序(界面是一个长条)启动后停靠在桌面最上方,怎么让我的电脑等图标自动往下移动?((100分)

  • 主题发起人 主题发起人 fangheling
  • 开始时间 开始时间
估计用API吧,我也不会,顶。
 
看看这文章你也许就明白了.<br><br>首先要对付的是桌面图标那一个个难看的、带有背景色的文字,不仅看上去别扭,还遮住了漂亮的墙纸,一定要去掉它,把它变成透明。其次就是图标的位置,只会傻傻地呆在屏幕的左边,还得我们一个个去拖,真累!给它来点新花样,Please &nbsp;Follow &nbsp;Me!<br><br>1、 &nbsp;新建一工程,在 uses 中加入 CommCtrl 单元,窗体上加一个按钮;<br><br>2、 &nbsp;声明一个取得桌面句柄的函数:<br><br>function TForm1.GetDesktopHand: THandle;<br><br>begin<br><br>&nbsp; Result:=FindWindow('progman',nil);<br><br>&nbsp; Result:=GetWindow(Result,GW_Child);<br><br>&nbsp; Result:=GetWindow(Result,GW_Child);<br><br>end;<br><br>3、 &nbsp;声明一个设置图标文字颜色的过程:<br><br>procedure TForm1.SetTextColor(ForeClr, BackClr: TColor);<br><br>var Hand: THandle;<br><br>begin<br><br>&nbsp; Hand:= GetDesktopHand;<br><br>&nbsp; Listview_SetTextColor(Hand,ForeClr); &nbsp; // 设置文字前景色;<br><br>&nbsp; Listview_SetTextBkColor(Hand,BackClr); &nbsp;// 设置文字背景色,crNone 为透明;<br><br>&nbsp; Listview_RedrawItems(Hand,0,Listview_GetItemCount(Hand)); &nbsp;// &nbsp;重画;<br><br>end;<br><br>&nbsp;<br><br>有了上面的两个方法,你已经可以对桌面动小手术了。下面介绍图标的排列方式。<br><br>&nbsp;<br><br>4、 &nbsp;以屏幕的中心为圆点作圆形排列:<br><br>procedure TForm1.Circle(r: integer); &nbsp; // 形参 r 为半径;<br><br>var<br><br>&nbsp; i, Count, CenterX, CenterY, TempR :integer;<br><br>&nbsp; Hand: THandle;<br><br>&nbsp; Radian: double;<br><br>&nbsp; TempRect: TRect;<br><br>&nbsp; DesktopHeight,DesktopWidth :integer;<br><br>&nbsp; X, Y : Word;<br><br>begin<br><br>&nbsp; Hand:=GetDesktopHand;<br><br>&nbsp; SystemParametersInfo(SPI_GetWorkArea,0,@TempRect,0); &nbsp;// 取得工作区域;<br><br>&nbsp; DesktopWidth:=TempRect.Right - TempRect.Left; &nbsp;// 工作区的宽(即屏幕的宽);<br><br>&nbsp; DesktopHeight:= TempRect.Bottom - TempRect.Top; &nbsp;// 工作区的高(即屏幕的高);<br><br>&nbsp; CenterX:=DesktopWidth div 2; &nbsp;// 取得圆心 X 坐标;<br><br>&nbsp; CenterY:=DesktopHeight div 2; // 圆心 Y 坐标;<br><br>&nbsp; if CenterX&gt;CenterY then<br><br>&nbsp; &nbsp; TempR:=CenterY<br><br>&nbsp; else<br><br>&nbsp; &nbsp; TempR:=CenterX; &nbsp;<br><br>&nbsp; if r&gt;TempR then r:=TempR; &nbsp;// 半径不能超过屏幕中心点到四边的最短距离;<br><br>&nbsp; Count:=Listview_GetItemCount(Hand); &nbsp;// 桌面上图标个数;<br><br>&nbsp; Radian:=2*3.14159/Count; &nbsp;// &nbsp;相邻图标间的弧度;<br><br>&nbsp; for i:=0 to Count-1 do<br><br>begin<br><br>&nbsp; // 第一个图标排在正上方;<br><br>&nbsp; &nbsp; &nbsp; X:=Integer(CenterX+Trunc(r*Sin(i*Radian))); &nbsp;// 图标的X坐标; <br><br>&nbsp; &nbsp; &nbsp; Y:=Integer(CenterY+Trunc(r*Cos(i*Radian))); &nbsp;// 图标的Y坐标;<br><br>&nbsp; &nbsp; &nbsp; SendMessage(Hand,LVM_SetItemPosition,i,MakeLparam(X, y)); &nbsp;// 设置坐标;<br><br>&nbsp; &nbsp; end;<br><br>end;<br><br>&nbsp;<br><br>5、 &nbsp;图标右对齐:<br><br>procedure AlignRight(Rec: Integer); // 形参 Rec 为一个图标所占区域大小,一般为77;<br><br>var Hand: THandle;<br><br>&nbsp; &nbsp;h, I, j, DesktopHight, DesktopWidth :integer;<br><br>&nbsp; &nbsp;TempRect : TRect;<br><br>Begin<br><br>Hand:=GetDesktopHand;<br><br>&nbsp; SystemParametersInfo(SPI_GetWorkArea,0,@TempRect,0); &nbsp;// 取得工作区域;<br><br>&nbsp; DesktopWidth:=TempRect.Right - TempRect.Left; &nbsp;// 工作区的宽(即屏幕的宽);<br><br>&nbsp; DesktopHeight:= TempRect.Bottom - TempRect.Top; &nbsp;// 工作区的高(即屏幕的高);<br><br>&nbsp; I:=0; &nbsp;// 图标所排的列数<br><br>&nbsp; J:=0; <br><br>&nbsp; For h:=0 to Listview_GetItemCount(Hand)-1 do<br><br>Begin<br><br>&nbsp; Inc(j);<br><br>&nbsp; If &nbsp;j*rec&gt;DesktopHeight &nbsp;then &nbsp;// 排完一列;<br><br>&nbsp; &nbsp; Begin<br><br>&nbsp; &nbsp; &nbsp; Inc(i); &nbsp;// 换列<br><br>&nbsp; &nbsp; &nbsp; J:=1;<br><br>&nbsp; &nbsp; End;<br><br>&nbsp; SendMessage(Hand,LVM_SetItemPosition,h,<br><br>MakeLparam(DesktopWidth-Rec*(I+1),Rec*(j-1));<br><br>End; // &nbsp;for 循环结束;<br><br>End;<br><br>&nbsp;<br><br>6、 &nbsp;在按钮的单击事件中加入代码:<br><br>procedure TForm1.Button1Click(Sender: TObject);<br><br>begin<br><br>&nbsp; SetTextColor(clBlack,crNone); // 设置图标文字颜色;<br><br>&nbsp; Circle(200); &nbsp;// 把图标排列成半径为200的圆;<br><br>&nbsp; // AlignRight(77); // 右对齐;<br><br>end;<br><br>&nbsp;<br><br>编译运行,单击按钮。哇塞!太棒了!你还可发挥你的想象力,对程序稍加改进,把图标排成蛇形、椭圆形、环形等等。以上程序在 Win98+Delphi5下运行通过。<br>
 
我说个办法,成不成不一定啊,只是个想法。<br><br>通过改写桌面窗口的窗口函数,让窗口高度变小,这样就留出一块空间让你的程序独占了吗?我觉得应该能行。说起来简单,但实现起来应该很麻烦。
 
不仅仅是要桌面让出位置,而且是要全部的程序运行后都要让出位置,<br>也就是说我的程序是置顶的,其它的程序最大化后只能是夹在任务栏跟我的程序中间一样<br>唉,简单一点,就是相当于另一个任务栏一样
 
找到桌面那个窗口句柄,然后MoveWindow,不知道行不行,试试吧
 
Desktop WordArea,API:SystemParametersInfo(SPI_SETWORKAREA)
 
procedure TForm1.FormCreate(Sender: TObject);<br>var<br>&nbsp; R : TRect;<br>begin<br>&nbsp; OldRect := Screen.WorkAreaRect;<br>&nbsp; R := OldRect;<br>&nbsp; FormStyle := fsStayOnTop;<br>&nbsp; Height := 30;<br>&nbsp; R.Top := R.Top + ClientHeight;<br>&nbsp; SystemParametersInfo(SPI_SETWORKAREA, 0, @R, SPIF_SENDCHANGE);<br>&nbsp; Top := 0;<br>&nbsp; Left :=0;<br>&nbsp; Width := Screen.Width;<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br>&nbsp; SystemParametersInfo(SPI_SETWORKAREA, 0, @OldRect, SPIF_SENDCHANGE);<br>end;<br>
 
就是不要重叠,不是浮在上面的,是要跟当前活的空体并排<br>跟下面的任务栏一样<br>能行吗?
 
ok,结!!!谢谢kingro
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部