?? unit1.pas
字號:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, Buttons, Menus, shellapi;
const
mousemsg=wm_user+1;
iid=100;
type
TForm1 = class(TForm)
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure N1Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure N3Click(Sender: TObject);
private
{ Private declarations }
procedure mousemessage(var message: tmessage); message mousemsg;
procedure DoVisible;
procedure DoInvisible;
public
{ Public declarations }
end;
var
Form1: TForm1;
FullRgn, ClientRgn, CtlRgn : THandle;
F2:Boolean;
ntida: TNotifyIcondataA;
implementation
{$R *.DFM}
uses unit2,unit3,unit4;
procedure TForm1.mousemessage(var message: tmessage);
var
mousept: TPoint; //鼠標點擊位置
begin
inherited;
if message.LParam = wm_rbuttonup then begin //用鼠標右鍵點擊圖標
getcursorpos(mousept); //獲取光標位置
popupmenu1.popup(mousept.x, mousept.y);
//在光標位置彈出選單
end;
if message.LParam = wm_lbuttonup then begin //用鼠標左鍵點擊圖標
//顯示應用程序窗口
ShowWindow(Handle, SW_SHOW);
//在任務欄上顯示應用程序窗口
ShowWindow(Application.handle, SW_SHOW);
SetWindowLong(Application.Handle, GWL_EXSTYLE,
not (GetWindowLong(Application.handle, GWL_EXSTYLE)
or WS_EX_TOOLWINDOW AND NOT WS_EX_APPWINDOW));
end;
message.Result := 0;
end;
procedure TForm1.DoVisible;
begin
//To restore complete visibility:
FullRgn := CreateRectRgn(0, 0, Width, Height);
CombineRgn(FullRgn, FullRgn, FullRgn, RGN_COPY);
SetWindowRgn(Handle, FullRgn, TRUE);
end;
procedure TForm1.DoInvisible;
var
AControl : TControl;
A, Margin, X, Y, CtlX, CtlY : Integer;
begin
Margin := ( Width - ClientWidth ) div 2;
//First, get form region
FullRgn := CreateRectRgn(0, 0, Width, Height);
//Find client area region
X := Margin;
Y := Height - ClientHeight - Margin;
ClientRgn := CreateRectRgn( X, Y, X + ClientWidth, Y + ClientHeight );
//'Mask' out all but non-client areas
CombineRgn( FullRgn, FullRgn, ClientRgn, RGN_DIFF );
//Now, walk through all the controls on the form and 'OR' them
// into the existing Full region.
for A := 0 to ControlCount - 1 do begin
AControl := Controls[A];
if ( AControl is TWinControl ) or ( AControl is TGraphicControl )
then with AControl do begin
if Visible then begin
CtlX := X + Left;
CtlY := Y + Top;
CtlRgn := CreateRectRgn( CtlX, CtlY, CtlX + Width, CtlY + Height );
CombineRgn( FullRgn, FullRgn, CtlRgn, RGN_OR );
end;
end;
end;
//When the region is all ready, put it into effect:
SetWindowRgn(Handle, FullRgn, TRUE);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
//Clean up the regions we created
DeleteObject(ClientRgn);
DeleteObject(FullRgn);
DeleteObject(CtlRgn);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
devicehandle:thandle;
begin
//We start out as a transparent form....
form1.Top:=screen.Height-66;
form1.Left:=screen.Width-60;
setlength(cdir,144);
if getcurrentdirectory(144,pchar(cdir))<>0 then
begin
setlength(cdir,strlen(pchar(cdir)));
cdir:=cdir+'\SHULUWENZI.txt';
if not FileExists(cdir) then
begin
DeviceHandle := CreateFile(PChar(cdir), GENERIC_WRITE, FILE_SHARE_READ, nil,CREATE_ALWAYS, 0, 0);
closehandle(DeviceHandle);
end;
end;
f2:=false;
ntida.cbSize := sizeof(tnotifyicondataa); //指定ntida的長度
ntida.Wnd := handle; //取應用程序主窗體的句柄
ntida.uID := iid; //用戶自定義的一個數值,在uCallbackMessage參數指定的消息中使
ntida.uFlags := nif_icon + nif_tip + nif_message;//指定在該結構中uCallbackMessage、hIcon和szTip參數都有效
ntida.uCallbackMessage := mousemsg;
//指定的窗口消息
ntida.hIcon := Application.Icon.handle;
//指定系統狀態欄顯示應用程序的圖標句柄
ntida.szTip := 'Icon';
//當鼠標停留在系統狀態欄該圖標上時,出現該提示信息
shell_notifyicona(NIM_ADD, @ntida);
//在系統狀態欄增加一個新圖標
Doinvisible;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
if f2 then form2.close;
f2:=false;
ShowWindow(Handle, SW_HIDE); //隱藏主窗體
//隱藏應用程序窗口在任務欄上的顯示
ShowWindow(Application.Handle, SW_HIDE);
SetWindowLong(Application.Handle, GWL_EXSTYLE,
GetWindowLong(Application.handle, GWL_EXSTYLE)or WS_EX_TOOLWINDOW AND NOT WS_EX_APPWINDOW);
form1.Close;
end;
procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
if f2 then
begin
form2.close;
f2:=false;
n4.Caption:='畫板';
end
else begin
application.CreateForm(tform2,form2);
//form2.show;
f2:=true;
n4.Caption:='關閉';
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caNone; //不對窗體進行任何操作
ShowWindow(Handle, SW_HIDE); //隱藏主窗體
//隱藏應用程序窗口在任務欄上的顯示
ShowWindow(Application.Handle, SW_HIDE);
SetWindowLong(Application.Handle, GWL_EXSTYLE,
GetWindowLong(Application.handle, GWL_EXSTYLE)
or WS_EX_TOOLWINDOW AND NOT WS_EX_APPWINDOW);
end;
procedure TForm1.N1Click(Sender: TObject);
begin
ntida.cbSize := sizeof(tnotifyicondataa);
ntida.wnd := handle;
ntida.uID := iid;
ntida.uFlags := nif_icon + nif_tip + nif_message;
ntida.uCallbackMessage := mousemsg;
ntida.hIcon := Application.Icon.handle;
ntida.szTip := 'Icon';
shell_notifyicona(NIM_DELETE, @ntida);
//刪除已有的應用程序圖標
Application.Terminate;
//中斷應用程序運行,退出應用程序
end;
procedure TForm1.N2Click(Sender: TObject);
begin
Aboutbox.show;
end;
procedure TForm1.N3Click(Sender: TObject);
begin
form4.Show;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -