?? rxshell.pas
字號(hào):
FIcon := nil;
FIconList.Free;
FIconList := nil;
inherited Destroy;
end;
procedure TRxTrayIcon.Loaded;
begin
inherited Loaded;
if FActive and not (csDesigning in ComponentState) then Activate;
end;
procedure TRxTrayIcon.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (AComponent = PopupMenu) and (Operation = opRemove) then
PopupMenu := nil;
end;
procedure TRxTrayIcon.SetPopupMenu(Value: TPopupMenu);
begin
FPopupMenu := Value;
{$IFDEF WIN32}
if Value <> nil then Value.FreeNotification(Self);
{$ENDIF}
end;
procedure TRxTrayIcon.SendCancelMode;
var
F: TForm;
begin
if not (csDestroying in ComponentState) then begin
F := Screen.ActiveForm;
if F = nil then F := Application.MainForm;
if F <> nil then F.SendCancelMode(nil);
end;
end;
function TRxTrayIcon.CheckMenuPopup(X, Y: Integer): Boolean;
begin
Result := False;
if not (csDesigning in ComponentState) and Active and
(PopupMenu <> nil) and PopupMenu.AutoPopup then
begin
PopupMenu.PopupComponent := Self;
SendCancelMode;
SwitchToWindow(FHandle, False);
Application.ProcessMessages;
try
PopupMenu.Popup(X, Y);
finally
{$IFDEF WIN32}
SwitchToWindow(FHandle, False);
{$ENDIF}
end;
Result := True;
end;
end;
function TRxTrayIcon.CheckDefaultMenuItem: Boolean;
{$IFDEF WIN32}
var
Item: TMenuItem;
I: Integer;
{$ENDIF}
begin
Result := False;
{$IFDEF WIN32}
if not (csDesigning in ComponentState) and Active and
(PopupMenu <> nil) and (PopupMenu.Items <> nil) then
begin
I := 0;
while (I < PopupMenu.Items.Count) do begin
Item := PopupMenu.Items[I];
if Item.Default and Item.Enabled then begin
Item.Click;
Result := True;
Break;
end;
Inc(I);
end;
end;
{$ENDIF}
end;
procedure TRxTrayIcon.SetIcon(Value: TIcon);
begin
FIcon.Assign(Value);
end;
procedure TRxTrayIcon.SetIconList(Value: TIconList);
begin
FIconList.Assign(Value);
end;
function TRxTrayIcon.GetActiveIcon: TIcon;
begin
Result := FIcon;
if (FIconList <> nil) and (FIconList.Count > 0) and Animated then
Result := FIconList[Max(Min(FIconIndex, FIconList.Count - 1), 0)];
end;
function TRxTrayIcon.GetAnimated: Boolean;
begin
Result := FAnimated;
end;
procedure TRxTrayIcon.SetAnimated(Value: Boolean);
begin
Value := Value and Assigned(FIconList) and (FIconList.Count > 0);
if Value <> Animated then begin
if Value then begin
{$IFDEF USE_TIMER}
FTimer := TTimer.Create(Self);
FTimer.Enabled := FAdded;
FTimer.Interval := FInterval;
FTimer.OnTimer := Timer;
{$ELSE}
FTimer := TTimerThread.Create(Self, not FAdded);
{$ENDIF}
FAnimated := True;
end
else begin
FAnimated := False;
{$IFDEF USE_TIMER}
FTimer.Free;
FTimer := nil;
{$ELSE}
TTimerThread(FTimer).FOwnerTray := nil;
while FTimer.Suspended do FTimer.Resume;
FTimer.Terminate;
{$ENDIF}
end;
FIconIndex := 0;
ChangeIcon;
end;
end;
procedure TRxTrayIcon.SetActive(Value: Boolean);
begin
if (Value <> FActive) then begin
FActive := Value;
if not (csDesigning in ComponentState) then
if Value then Activate else Deactivate;
end;
end;
procedure TRxTrayIcon.Show;
begin
Active := True;
end;
procedure TRxTrayIcon.Hide;
begin
Active := False;
end;
procedure TRxTrayIcon.SetShowDesign(Value: Boolean);
begin
if (csDesigning in ComponentState) then begin
if Value then Activate else Deactivate;
FShowDesign := FAdded;
end;
end;
procedure TRxTrayIcon.SetInterval(Value: Word);
begin
if FInterval <> Value then begin
FInterval := Value;
{$IFDEF USE_TIMER}
if Animated then FTimer.Interval := FInterval;
{$ENDIF}
end;
end;
{$IFDEF USE_TIMER}
procedure TRxTrayIcon.Timer(Sender: TObject);
{$ELSE}
procedure TRxTrayIcon.Timer;
{$ENDIF}
begin
if not (csDestroying in ComponentState) and Animated then begin
Inc(FIconIndex);
if (FIconList = nil) or (FIconIndex >= FIconList.Count) then
FIconIndex := 0;
ChangeIcon;
end;
end;
procedure TRxTrayIcon.IconChanged(Sender: TObject);
begin
ChangeIcon;
end;
procedure TRxTrayIcon.SetHint(const Value: string);
begin
if FHint <> Value then begin
FHint := Value;
ChangeIcon;
end;
end;
procedure TRxTrayIcon.UpdateNotifyData;
var
Ico: TIcon;
begin
with FIconData do begin
cbSize := SizeOf(TNotifyIconData);
Wnd := FHandle;
Ico := GetActiveIcon;
if Ico <> nil then hIcon := Ico.Handle
{$IFDEF WIN32}
else hIcon := INVALID_HANDLE_VALUE;
{$ELSE}
else hIcon := 0;
{$ENDIF}
StrPLCopy(szTip, GetShortHint(FHint), SizeOf(szTip) - 1);
uCallbackMessage := CM_TRAYICON;
uID := 0;
end;
end;
procedure TRxTrayIcon.Activate;
var
Ico: TIcon;
begin
Deactivate;
Ico := GetActiveIcon;
if (Ico <> nil) and not Ico.Empty then begin
FClicked := [];
UpdateNotifyData;
FAdded := Shell_NotifyIcon(NIM_ADD, @FIconData);
if (GetShortHint(FHint) = '') and FAdded then
Shell_NotifyIcon(NIM_MODIFY, @FIconData);
{$IFDEF USE_TIMER}
if Animated then FTimer.Enabled := True;
{$ELSE}
if Animated then
while FTimer.Suspended do FTimer.Resume;
{$ENDIF}
end;
end;
procedure TRxTrayIcon.Deactivate;
begin
Shell_NotifyIcon(NIM_DELETE, @FIconData);
FAdded := False;
FClicked := [];
{$IFDEF USE_TIMER}
if Animated then FTimer.Enabled := False;
{$ELSE}
if Animated and not FTimer.Suspended then FTimer.Suspend;
{$ENDIF}
end;
procedure TRxTrayIcon.ChangeIcon;
var
Ico: TIcon;
begin
if (FIconList = nil) or (FIconList.Count = 0) then SetAnimated(False);
if FAdded then begin
Ico := GetActiveIcon;
if (Ico <> nil) and not Ico.Empty then begin
UpdateNotifyData;
Shell_NotifyIcon(NIM_MODIFY, @FIconData);
end
else Deactivate;
end
else begin
if ((csDesigning in ComponentState) and FShowDesign) or
(not (csDesigning in ComponentState) and FActive) then Activate;
end;
end;
procedure TRxTrayIcon.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
if Assigned(FOnMouseMove) then FOnMouseMove(Self, Shift, X, Y);
end;
procedure TRxTrayIcon.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Assigned(FOnMouseDown) then FOnMouseDown(Self, Button, Shift, X, Y);
end;
procedure TRxTrayIcon.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Assigned(FOnMouseUp) then FOnMouseUp(Self, Button, Shift, X, Y);
end;
procedure TRxTrayIcon.DblClick;
begin
if not CheckDefaultMenuItem and Assigned(FOnDblClick) then
FOnDblClick(Self);
end;
procedure TRxTrayIcon.DoClick(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
begin
if (Button = mbRight) and CheckMenuPopup(X, Y) then Exit;
if Assigned(FOnClick) then FOnClick(Self, Button, Shift, X, Y);
end;
procedure TRxTrayIcon.WndProc(var Message: TMessage);
function GetShiftState: TShiftState;
begin
Result := [];
if GetKeyState(VK_SHIFT) < 0 then Include(Result, ssShift);
if GetKeyState(VK_CONTROL) < 0 then Include(Result, ssCtrl);
if GetKeyState(VK_MENU) < 0 then Include(Result, ssAlt);
end;
var
P: TPoint;
Shift: TShiftState;
begin
try
with Message do
if (Msg = CM_TRAYICON) and Self.FEnabled then begin
case lParam of
WM_LBUTTONDBLCLK:
begin
DblClick;
GetCursorPos(P);
MouseDown(mbLeft, GetShiftState + [ssDouble], P.X, P.Y);
end;
WM_RBUTTONDBLCLK:
begin
GetCursorPos(P);
MouseDown(mbRight, GetShiftState + [ssDouble], P.X, P.Y);
end;
WM_MBUTTONDBLCLK:
begin
GetCursorPos(P);
MouseDown(mbMiddle, GetShiftState + [ssDouble], P.X, P.Y);
end;
WM_MOUSEMOVE:
begin
GetCursorPos(P);
MouseMove(GetShiftState, P.X, P.Y);
end;
WM_LBUTTONDOWN:
begin
GetCursorPos(P);
MouseDown(mbLeft, GetShiftState + [ssLeft], P.X, P.Y);
Include(FClicked, mbLeft);
end;
WM_LBUTTONUP:
begin
Shift := GetShiftState + [ssLeft];
GetCursorPos(P);
if mbLeft in FClicked then begin
Exclude(FClicked, mbLeft);
DoClick(mbLeft, Shift, P.X, P.Y);
end;
MouseUp(mbLeft, Shift, P.X, P.Y);
end;
WM_RBUTTONDOWN:
begin
GetCursorPos(P);
MouseDown(mbRight, GetShiftState + [ssRight], P.X, P.Y);
Include(FClicked, mbRight);
end;
WM_RBUTTONUP:
begin
Shift := GetShiftState + [ssRight];
GetCursorPos(P);
if mbRight in FClicked then begin
Exclude(FClicked, mbRight);
DoClick(mbRight, Shift, P.X, P.Y);
end;
MouseUp(mbRight, Shift, P.X, P.Y);
end;
WM_MBUTTONDOWN:
begin
GetCursorPos(P);
MouseDown(mbMiddle, GetShiftState + [ssMiddle], P.X, P.Y);
end;
WM_MBUTTONUP:
begin
GetCursorPos(P);
MouseUp(mbMiddle, GetShiftState + [ssMiddle], P.X, P.Y);
end;
end;
end
else Result := DefWindowProc(FHandle, Msg, wParam, lParam);
except
Application.HandleException(Self);
end;
end;
end.
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -