程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> TNotifyIcon控件1.01

TNotifyIcon控件1.01

編輯:Delphi

TNotifyIcon 控件1.01 (Build use Delphi 3.0) 說明:
作用:
 往通知區加圖標,並可顯示,隱藏,修改這個圖標.
 

屬性(properties):
 NotifyIcon:TIcon  欲加在通知區的圖標
 IsVisible:boolean NotifyIcon是否顯示的屬性
 Title:string  通知區圖標上的提示(最多64個字符)
 PopupMenu:TPopupMenu 點擊通知區圖標彈出的菜單
 PopupStyle:TPopupStyle 彈出菜單的方式            
  TPopupStyle=Set of
(Left_Click,Right_Click,Left_DbClick,Right_DbClick);
方法(methods):  
   ShowIcon  將圖標顯示在通知區上
   HideIcon  將通知區上的圖標隱藏
   ModifyIcon 修改通知區上的圖標(若IsVisible=false,則不顯示出來)
   Create(AOwner: TComponent); override; 構造方法
   Destroy; override; 析構方法
事件(Events):
    OnIconMouseDown:
      procedure(Sender:TObject;x,y:Word;WhoButton:TWhoButton) of
Object;
      (
       在Mouse點擊通知區上的圖標時發生,x,y為Mouse在屏幕上的坐標,
       WhoButton=b_Left為點擊左鍵,WhoButton=b_Right為點擊右鍵,
      )
    OnIconDoubleClick:
      procedure(Sender:TObject;x,y:Word;WhoButton:TWhoButton) of
Object;
     (
      在Mouse雙擊通知區上的圖標時發生,x,y為Mouse在屏幕上的坐標,
      WhoButton=b_Left為雙擊左鍵,WhoButton=b_Right為雙擊右鍵,
     )
關於Demo:
   這個演示程序給出了TNotifyIcon的基本用法.

包含文件:
 NotifyIcon.dcr
 NotifyIcon.pas
 DemoUnit.pas
 DemoUnit.dfm
 PopUnit.pas
 PopUnit.dfm
 Demo.dpr
 Readme.txt

聲明:
TNotifyIcon 控件 V 1.01
1.這是一個免費控件.
2.如果你使用它,請發一個E-Mail給作者,謝謝.
3我在Delphi3.0 & 4.0 上使用成功
4.若要傳播它,請完全分發上述8個文件

     作者  南昌大學計算系95(1)  付昱綱 1998.8.17  21:50
     E-mail   [email protected] 

unit NotifyIcon;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
  DsgnIntf,ShellApi,ExtCtrls,Menus;

const
      WM_MY_Notify=WM_USER+100;
type

  TPopupStyle=Set of
(Left_Click,Right_Click,Left_DbClick,Right_DbClick);
  TWhoButton=(b_Left,b_Right);
  TMouseEvent=
  procedure(Sender:TObject;x,y:Word;WhoButton:TWhoButton)
      of Object;

//---------class TNotifyIcon---------
  TNotifyIcon = class(TCustomControl)
  private
    { Private declarations }
    FIcon:TIcon;
    FPda:PNOTIFYICONDATA;
    FTitle:string;
    FIconVisible:boolean;
    FPopupMenu:TPopupMenu;
    FPopupStyle:TPopupStyle;
    FOnIconMouseDown:TMouseEvent;
    FOnIconDoubleClick:TMouseEvent;
    procedure SetIcon(Icon:TICON);
    procedure SetTitle(NewTitle:string);
    function IsShowing:boolean;
    procedure ShowIt(Accept:boolean);
    procedure NotifyIconClick(var msg : TMessage);
      Message WM_My_Notify;
  protected
    { Protected declarations }
   public
    { Public declarations }
   property IsVisible:boolean read IsShowing write ShowIt;
   constructor Create(AOwner: TComponent); override;
   procedure ShowIcon;
   procedure HideIcon;
   destructor Destroy; override;
   procedure ModifyIcon(NewIcon:TIcon);
   procedure Paint;override;
  published
    { Published declarations }
    property Height default 33;
    property Width  default 33;
    property NotifyIcon:TIcon read FIcon  write SetIcon;
    property Title:string read FTitle write SetTitle ;
    property OnIconDoubleClick:TMouseEvent
      read FOnIconDoubleClick write FOnIconDoubleClick;
    property OnIconMouseDown:TMouseEvent
      read FOnIconMouseDown write FOnIconMouseDown;
    property PopupMenu:TPopupMenu read FPopupMenu write FPopupMenu;
    property PopupStyle:TPopupStyle read FPopupStyle
                write FPopupStyle default [];
 end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents(MyControl, [TNotifyIcon]);
end;

procedure TNotifyIcon.ShowIt(Accept:boolean);
begin
  if  Accept=true then ShowIcon
  else HideIcon;
end;

procedure TNotifyIcon.Paint;
begin
if (csDesigning in ComponentState) then
begin
 Width:=33;
 Height:=33;
 With Canvas do
 begin
  Brush.Color:=clInfoBk;
  Ellipse(0,0,Self.Width,Self.Height);
  Font.Color:=clBlue;
  Brush.Style:=bsClear;
  FloodFill(5,5,clInfoBk,fsBorder);
  Brush.Color:=clInfoBk;
  TextOut(3,Self.Height div 2-6,Notify);
 end
end;
end;

procedure TNotifyIcon.NotifyIconClick(var msg : TMessage);
 var p:TPoint;
begin
 try
     case msg.LParam of
      WM_LBUTTONDOWN:
        begin
         GetCursorPos(p);
         if Left_Click in FPopupStyle then
         begin
           SetForegroundWindow(ParentWindow);
           FPopupMenu.Popup(p.x,p.y);
         end;
         if Assigned(FOnIconMouseDown) then
         begin
           FOnIconMouseDown(Self,p.x,p.y,b_Left);
         end;
        end;
      WM_RBUTTONDOWN:
        begin
         GetCursorPos(p);
         if Right_Click in  FPopupStyle then
         begin
           SetForegroundWindow(ParentWindow);
           FPopupMenu.Popup(p.x,p.y);
         end;
         if Assigned(FOnIconMouseDown) then
         begin
           FOnIconMouseDown(Self,p.x,p.y,b_Right);
         end;
        end;
      WM_LBUTTONDBLCLK:
        begin<

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved