?? traybaricon.pas
字號:
MouseUp(mbMiddle, Shift, Pt.X, Pt.Y);
end;
WM_LBUTTONDBLCLK:
if FEnabled then
begin
DblClick;
M := nil;
if Assigned(FPopupMenu) then
if (FPopupMenu.AutoPopup) and (not FLeftPopup) then
for I := PopupMenu.Items.Count -1 downto 0 do
begin
if PopupMenu.Items[I].Default then
M := PopupMenu.Items[I];
end;
if M <> nil then
M.Click;
end;
end;
end
else
case Msg.Msg of
WM_QUERYENDSESSION: Msg.Result := 1;
else
Msg.Result := DefWindowProc(IconData.Wnd, Msg.Msg, Msg.wParam, Msg.lParam);
end;
end;
procedure TTrayIcon.SetIcon(Value: TIcon);
begin
// 設置圖標
FIcon.Assign(Value);
ModifyIcon;
end;
procedure TTrayIcon.SetIconVisible(Value: Boolean);
begin
// 設置是否顯示圖標
if Value then
ShowIcon
else
HideIcon;
end;
procedure TTrayIcon.SetDesignPreview(Value: Boolean);
begin
// 設置是否預覽圖標
FDesignPreview := Value;
SettingPreview := True;
SetIconVisible(Value);
SettingPreview := False;
end;
procedure TTrayIcon.SetCycleIcons(Value: Boolean);
begin
// 設置是否動態顯示圖標
FCycleIcons := Value;
if Value then
IconIndex := 0;
CycleTimer.Enabled := Value;
end;
procedure TTrayIcon.SetCycleInterval(Value: Cardinal);
begin
// 設置動態圖標的更換時間間隔
FCycleInterval := Value;
CycleTimer.Interval := FCycleInterval;
end;
procedure TTrayIcon.SetHint(Value: String);
begin
// 設置要顯示的提示信息
FHint := Value;
ModifyIcon;
end;
procedure TTrayIcon.SetShowHint(Value: Boolean);
begin
// 設置是否顯示提示
FShowHint := Value;
ModifyIcon;
end;
function TTrayIcon.InitIcon: Boolean;
var
ok: Boolean;
begin
// 初始化圖標
Result := False;
ok := True;
if (csDesigning in ComponentState) then
begin
if SettingPreview then
ok := True
else
ok := FDesignPreview
end;
if ok then
begin
IconData.hIcon := FIcon.Handle;
if (FHint <> '') and (FShowHint) then
StrLCopy(IconData.szTip, PChar(FHint), SizeOf(IconData.szTip))
else
IconData.szTip := '';
Result := True;
end;
end;
function TTrayIcon.ShowIcon: Boolean;
begin
Result := False;
// 如果沒有設置圖標預覽,則顯示圖標
if not SettingPreview then
FIconVisible := True;
if (csDesigning in ComponentState) then
begin
if SettingPreview then
if InitIcon then
Result := Shell_NotifyIcon(NIM_ADD, @IconData);
end
else
if InitIcon then
Result := Shell_NotifyIcon(NIM_ADD, @IconData);
end;
function TTrayIcon.HideIcon: Boolean;
begin
Result := False;
// 如果沒有設置圖標預覽,則隱藏圖標
if not SettingPreview then
FIconVisible := False;
if (csDesigning in ComponentState)then
begin
if SettingPreview then
if InitIcon then
Result := Shell_NotifyIcon(NIM_DELETE, @IconData);
end
else
if InitIcon then
Result := Shell_NotifyIcon(NIM_DELETE, @IconData);
end;
function TTrayIcon.ModifyIcon: Boolean;
begin
Result := False;
// 設置托盤圖標操作
if InitIcon then
Result := Shell_NotifyIcon(NIM_MODIFY, @IconData);
end;
procedure TTrayIcon.TimerCycle(Sender: TObject);
begin
// 循環更改圖標
if Assigned(FIconList) then
begin
FIconList.GetIcon(IconIndex, FIcon);
CycleIcon;
ModifyIcon;
if IconIndex < FIconList.Count-1 then
Inc(IconIndex)
else
IconIndex := 0;
end;
end;
procedure TTrayIcon.ShowMainForm;
var
I, J: Integer;
begin
// 恢復程序
ShowWindow(Application.Handle, SW_RESTORE);
// 恢復主窗體
ShowWindow(Application.MainForm.Handle, SW_RESTORE);
if not HasShown then
begin
for I := 0 to Application.MainForm.ComponentCount -1 do
if Application.MainForm.Components[I] is TWinControl then
with Application.MainForm.Components[I] as TWinControl do
if Visible then
begin
ShowWindow(Handle, SW_SHOWDEFAULT);
for J := 0 to ComponentCount -1 do
if Components[J] is TWinControl then
ShowWindow((Components[J] as TWinControl).Handle, SW_SHOWDEFAULT);
end;
HasShown := True;
end;
end;
procedure TTrayIcon.HideMainForm;
begin
//顯示程序
ShowWindow(Application.Handle, SW_HIDE);
//顯示主窗體
ShowWindow(Application.MainForm.Handle, SW_HIDE);
end;
procedure TTrayIcon.Refresh;
begin
ModifyIcon;
end;
procedure TTrayIcon.PopupAtCursor;
var
CursorPos: TPoint;
begin
// 如果指定了彈出菜單,則
if Assigned(PopupMenu) then
// 如果是設置了自動彈出,則
if PopupMenu.AutoPopup then
if GetCursorPos(CursorPos) then
begin
// 讓應用程序處理當前的消息
Application.ProcessMessages;
// 設應用程序主窗體為當前焦點窗體
SetForegroundWindow(Application.MainForm.Handle);
PopupMenu.PopupComponent := Self;
// 顯示彈出菜單
PopupMenu.Popup(CursorPos.X, CursorPos.Y);
// 發出消息
PostMessage(Application.MainForm.Handle, WM_NULL, 0, 0);
end;
end;
procedure TTrayIcon.Click;
begin
if Assigned(FOnClick) then
FOnClick(Self);
end;
procedure TTrayIcon.DblClick;
begin
if Assigned(FOnDblClick) then
FOnDblClick(Self);
end;
procedure TTrayIcon.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
begin
if Assigned(FOnMouseDown) then
FOnMouseDown(Self, Button, Shift, X, Y);
end;
procedure TTrayIcon.MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
begin
if Assigned(FOnMouseUp) then
FOnMouseUp(Self, Button, Shift, X, Y);
end;
procedure TTrayIcon.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
if Assigned(FOnMouseMove) then
FOnMouseMove(Self, Shift, X, Y);
end;
procedure TTrayIcon.CycleIcon;
begin
if Assigned(FOnCycle) then
FOnCycle(Self, IconIndex); //顯示下一個圖標
end;
procedure TTrayIcon.DoMinimizeToTray;
begin
// 隱藏主窗體
HideMainForm;
// 顯示圖標
IconVisible := True;
end;
procedure Register;
begin
//注冊到組件庫中
RegisterComponents('Wuqiu', [TTrayIcon]);
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -