出200分,问如何用自己的程序替换掉任务栏中的时间文字(hh:ss)(200分)

  • 主题发起人 主题发起人 YaoChangLi
  • 开始时间 开始时间
Y

YaoChangLi

Unregistered / Unconfirmed
GUEST, unregistred user!
任务栏中的时间文字,好象和其他的东西不一样,不是一个图标,
如何才能用自己的程序替将他替换掉?
 
你在程序中加以按钮,该按钮的ONCLICK事件中写下如下代码。看看你的时间文字还在没在?
procedure TForm1.Button1Click(Sender: TObject);
var
wnd:thandle;
begin
wnd:=findwindow('Shell_TrayWnd',nil);
wnd:=findwindowex(wnd,hwnd(0),'TrayNotifyWnd',nil);
wnd:=findwindowex(wnd,hwnd(0),'TrayClockWClass',nil);
if wnd<>0 then showwindow(wnd,SW_HIDE);
end;
 
try these code:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
StaticText1: TStaticText;
procedure Button1Click(Sender: TObject);
procedure StaticText1Click(Sender: TObject);
procedure ReplaceSystemClock;
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
ReplaceSystemClock;
end;

procedure TForm1.ReplaceSystemClock;
var
Rect: TRect; // We need this for calc'ing the size of the System Tray Window
TaskbarHwnd, TrayHwnd: HWND;
begin
// First we'll find the taskbar
TaskbarHwnd := FindWindow('Shell_TrayWnd',nil);
// Next the Tray Window
TrayHwnd := FindWindowEx(TaskbarHwnd,0,'TrayNotifyWnd',nil);
{ Now we need the Rect. of the Tray window so we can position the TStatictext
somewhat accurately }
GetWindowRect(TrayHwnd,Rect);
// Right Justify is recommended because the text will otherwise extend beyond the TrayWindow bounds
StaticText1.Alignment := taRightJustify;
// Change the borderstyle to single so we can see if its positioned properly
StaticText1.BorderStyle := sbsSingle;
// Reposition it so it covers the System Clock
StaticText1.Left := (Rect.Right - Rect.Left) - StaticText1.Width - 3;
StaticText1.Top := 2;
StaticText1.Font.Name := 'Tahoma';
// Disable this, or StaticText1 will move around when you change the text
StaticText1.AutoSize := FALSE;
// Now comes the interesting part: we shift the Statictext1's parent to the Traywindow
Windows.SetParent(StaticText1.Handle,TrayHwnd);
{ Even though Statictext1 changed owner, we can still manipulate it
like it were in our own form! Which is a great advantage. }
StaticText1.Caption := 'Test';
end;

procedure TForm1.StaticText1Click(Sender: TObject);
const
ClickTest: array[0..3] of string = ('this','is','a','test');
begin
{ Your events will work just as if they were on your form }
StaticText1.Caption := ClickTest[StaticText1.Tag];
if StaticText1.Tag < 3 then
StaticText1.Tag := StaticText1.Tag + 1
else StaticText1.Tag := 0;
end;

end.

wellcome to vcl.xilubbs.com
 
多人接受答案了。
 
关注就可以得80分? 以后还是“关注”吧!
 
后退
顶部