1.如何做到窗口最小化后,应用程序象QQ一样隐藏在右下角的时间栏里,有事件提醒时,栏中的图标会闪烁提醒?
2.如何实现Active Skin效果的button等等?

解决方案 »

  1.   

    定时闪烁:
    procedure TForm1.TrayShow(Sender: TObject);
    //当点击托盘图标时显示或隐含主窗体
    begin
      PopupMenu1.AutoPopup:=False;
      //设定 TNotifyIconData 的记录长度
      MyTrayIcon.cbSize :=SizeOf(tnotifyicondata);
      //确定调用程序的窗体句柄
      MyTrayIcon.Wnd :=Handle;
      //确定图标的 uID
      MyTrayIcon.uID :=1;   ////???我不知道这应该是多少!!!
      //设定显示标记
      MyTrayIcon.uFlags :=NIF_ICON or NIF_TIP or NIF_MESSAGE;
      //用户自定义消息
      MyTrayIcon.uCallbackMessage := WM_MYTRAYICONCALLBACK;
      //托盘图标的句柄
      //MyTrayIcon.hIcon := Application.Icon.Handle;
      MyTrayIcon.hIcon := LoadIcon(0, IDI_WINLOGO);
      //托盘图标的提示信息
      MyTrayIcon.szTip :='定时导数据程序';
      //向托盘中添加图标
      Shell_NotifyIcon(NIM_ADD,@mytrayicon);end;procedure TForm1.WMMyTrayIconCallBack(var Msg: TMessage);
    //处理点击托盘图标的事件,根据 WM_MOUSEMOVE 消息的不同情况产生不同的回应
    var
      CursorPos : TPoint;
    begin
      PopupMenu1.AutoPopup:=False;
      case Msg.lParam of
        //左键按下
        WM_LBUTTONDOWN : begin
                           application.MainForm.BringToFront;   //窗体置前
                         end;
        //左键双击
        WM_LBUTTONDBLCLK : begin                                //窗体隐含或显示
                             Application.MainForm.Visible := not Application.MainForm.Visible;
                             SetForegroundWindow(Application.Handle);
                           end;
        //右键按下
        WM_RBUTTONDOWN :   begin                                //显示弹出菜单
                             GetCursorPos(CursorPos);
                             PopupMenu1.Popup(CursorPos.x,CursorPos.y);
                           end;
       end//case
    end;
    procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
       Shell_NotifyIcon(NIM_DELETE, @MyTrayIcon);//删除托盘图标
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
       SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);//程序不在任务栏上显示
       TrayShow(Application.MainForm);//显示图标
       flag:=0;
    end;procedure TForm1.n_MainFromDispOrHideClick(Sender: TObject);
    begin
       if Application.MainForm.Visible then
      begin
         Application.MainForm.Hide;
        end
      else
      begin
        Application.MainForm.Show;
        n_MainFromDispOrHide.Caption :='隐藏主窗体';
      end;end;procedure TForm1.Timer1Timer(Sender: TObject);
    var
      ic:TICON;
    begin if flag=0 then flag:=1
     else flag:=0; ic:=TICON.Create;
     ImageList1.GetIcon(flag,ic);
     with MyTrayIcon do
      begin
        cbSize := SizeOf(tnotifyicondata);
        uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE;
        uID := 0;                    ///该是多少啊?
        Wnd := Handle;
        uCallbackMessage := WM_MYTRAYICONCALLBACK;
       // hIcon  :=Application.Icon.Handle ;]
       hicon:=ic.Handle;
       end; Shell_NotifyIcon(NIM_MODIFY,@MyTrayIcon);    ///没有任何效果!
     Application.MainForm.Hide;
     ic.Free;
    end;end.
      

  2.   

    2、
    直接看Active Skin Control的PAS源程序就可以了,
    下载地址:
    www.51delphi.com
    www.playicq.com
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages,shellapi, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Menus;
    const 
      ICON_ID=1; 
      //ICON的ID标志 
      MI_ICONEVENT=WM_USER+1; 
      //自定义ICON事件消息
    type
      TForm1 = class(TForm)
        PopupMenu1: TPopupMenu;
        add1: TMenuItem;
        enable1: TMenuItem;
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure FormCreate(Sender: TObject);
        procedure FormActivate(Sender: TObject);
        procedure add1Click(Sender: TObject);
        procedure enable1Click(Sender: TObject);
      private
        { Private declarations }
          { Private declarations } 
        NormalIcon,DisabledIcon:TIcon;
        //正常和失效两种情况下的图标 
        Status:Boolean; 
        //标志"允许使用"还是"禁止使用" 
        procedure InstallIcon;
        procedure ChangeIcon(s:Boolean); 
        procedure UnInstallIcon; 
        procedure IconOnClick(var message:TMessage); message MI_ICONEVENT;
      //捕捉自定义消息MI_ICONEVENT的过程IconOnClick的声明   public
        { Public declarations }
      end;var
      Form1: TForm1;implementationuses Unit2;{$R *.dfm}procedure TForm1.ChangeIcon(s:Boolean); 
    //自定义过程ChangeIcon,改变本程序在指示状态栏的图标 
    var 
      IconData:TNotifyIconData; 
    begin 
      IconData.cbSize:=SizeOf(IconData); 
      IconData.Wnd:=Handle; 
      IconData.uID:=ICON_ID; 
      if s=False then //禁止使用 
      begin 
        IconData.hIcon:=DisabledIcon.Handle; 
        Status:=False;   end 
      else //允许使用 
      begin 
        IconData.hIcon:=Normalicon.Handle; 
        Status:=True;  end; 
      IconData.uFlags:=NIF_ICON; 
      Shell_NotifyIcon(NIM_MODIFY,@IconData); 
    end; 
    procedure TForm1.IconOnClick(var message:TMessage); 
    //处理鼠标在指示状态栏对应的图标上的单击事件 
    var 
      p:TPoint; 
    begin 
      //如果按下的是鼠标左键,并且允许显示,则显示Form2 
      if((message.lParam=WM_LBUTTONDOWN) and (Status=True)) then 
        Form2.Show; 
      //如果按下的是鼠标右键,则显示弹出菜单 
      if(message.lParam=WM_RBUTTONDOWN)then 
      begin 
        GetCursorPos(p); 
        PopupMenu1.Popup(p.x,p.y); 
      end; 
    end; 
    procedure TForm1.InstallIcon; 
    //安装图标 
    var 
      IconData:TNotifyIconData; 
    begin 
      NormalIcon:=TIcon.Create; 
      DisabledIcon:=TIcon.Create; 
      NormalIcon.LoadFromFile('normal.ico'); 
    //允许使用状态下的图标 
      DisabledIcon.LoadFromFile('disable.ico');
    //禁止使用状态下的图标
      IconData.cbSize:=SizeOf(IconData);
      IconData.Wnd:=Handle; 
      IconData.uID:=ICON_ID; 
      IconData.uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP;
      IconData.uCallBackMessage:=MI_ICONEVENT; 
      IconData.hIcon:=NormalIcon.Handle; 
      IconData.szTip:='给指示状态栏加图标的例程'; 
      //鼠标悬在状态指示栏对应的图标上时的提示信息 
      Shell_NotifyIcon(NIM_ADD,@IconData); 
    end; 
    procedure TForm1.UnInstallIcon; 
    //卸载图标 
    var 
      IconData:TNotifyIconData; 
    begin 
      IconData.cbSize:=SizeOf(IconData); 
      IconData.Wnd:=Handle; 
      IconData.uID:=ICON_ID; 
      Shell_NotifyIcon(NIM_DELETE,@IconData);
    end;
    procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin 
      UnInstallIcon; 
      //卸载图标 
      NormalIcon.Free; 
      DisabledIcon.Free; 
      //释放两个图标资源
    end; procedure TForm1.FormCreate(Sender: TObject);
    begin 
      Status:=True; 
      InstallIcon; 
      //安装图标 
      ChangeIcon(True); 
     //改变图标为normal状态 
      ShowWindow(Application.Handle,SW_HIDE); 
    //隐藏主窗体 
      SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW); 
     //在切换状态栏上不显示程序图标
    end; procedure TForm1.FormActivate(Sender: TObject);
    begin 
      Form1.width:=0; 
      Form1.Height:=0; 
      ShowWindow(Application.Handle,SW_HIDE); 
      //隐藏Form1
    end; procedure TForm1.add1Click(Sender: TObject);
    begin 
      Form2.Show; 
     //显示主窗体
    end; procedure TForm1.enable1Click(Sender: TObject);
    begin 
      if (Status=True) then 
      //根据状态更改菜单项标题 
      begin 
        ChangeIcon(False);   end
      else 
      begin 
        ChangeIcon(True);   end; 
    end; 
    end.
      

  4.   

    送给你一个有关托盘的Component
    //===============================================================
    //
    //       This Component used in setting the Application thread
    //       into the windows TaskBar.
    //
    //---------------------------------------------------------------
    //
    //      Copyrigth (C) TradeLink on 21 March 2001
    //      Author: Wally 
    //
    //===============================================================unit TrayNotifyIcon;interfaceuses
      Windows, Messages, SysUtils, ShellAPI, Classes, Menus, Graphics, Extctrls, StdCtrls, Controls, Forms, Dialogs;type
      ENotifyIconError = class(Exception);
      TTrayNotifyIcon = class(TComponent)
      private
         FDefaultIcon: THandle;
         FIcon: TIcon;
         FHideTask: Boolean;
         FHint: String;
         FIconVisible: Boolean;
         FPopupMenu: TPopupMenu;
         FOnClick: TNotifyEvent;
         FOnDblClick: TNotifyEvent;
         FNoShowClick: Boolean;
         FTimer: TTimer;
         Tnd: TNotifyIconData;
         procedure SetIcon(Value: TIcon);
         procedure SetHideTask(Value: Boolean);
         procedure SetHint(Value: String);
         procedure SetIconVisible(Value: Boolean);
         procedure SetPopupMenu(Value: TPopupMenu);
         procedure SendTrayMessage(Msg: DWORD; Flags: UINT);
         Function ActiveIconHandle: THandle;
         procedure OnButtonTimer(Sender: TObject);
        { Private declarations }
      protected
         procedure Loaded; override;
         procedure LoadDefaultIcon; virtual;
         procedure Notification(AComponent: TComponent; Operation: TOperation);override;
        { Protected declarations }
      public
         constructor Create(AOwner: TComponent);override;
         destructor Destroy; override;
        { Public declarations }
      published
          property Icon: TIcon read FIcon write SetIcon;
          property HideTask: Boolean read FHideTask write SetHideTask default False;
          property Hint: String read FHint write SetHint;
          property IconVisible: Boolean read FIconVisible write SetIconVisible default False;
          property PopupMenu: TpopupMenu read FPopupMenu write SetPopupMenu;
          property OnClick: TNotifyEvent read FOnClick write FOnClick;
          property OnDblClick: TNotifyEvent read FOnDblClick write FOnDblClick;    { Published declarations }
      end;procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('Tradelink', [TTrayNotifyIcon]);
    end;{TIconManager}
    //begin Handler the Tray Icon message (IconMgr)
    type
        TIconManager = class
        private
             FHWindow: HWnd;
             procedure TrayWndProc(var Message: TMessage);
        public
             constructor Create;
             destructor Destroy; override;
             property HWindow: HWnd read FHWindow write FHWindow;
        end;
    var
        IconMgr: TIconManager;
        DDGM_TRAYICON: Integer;constructor TIconManager.Create;
    begin
      FHWindow := AllocateHWnd(TrayWndProc);
    end;destructor TIconManager.Destroy;
    begin
      if FHWindow <> 0 then DeallocateHWnd(FHWindow);
      inherited Destroy;
    end;
    {************************************************************
    This procedure is handle the Tray Icon message active.The work
    principle as follows: if click the icon, the TTimer is active
    if doubleclick the icon, the doubleclick event as active
    if rightclick the icon, the popupmenu is active
    *************************************************************}
    procedure TIconManager.TrayWndProc(var Message: TMessage);
    var
      Pt: TPoint;
      TheIcon: TTrayNotifyIcon;
    begin
      with Message do
      begin
        if (Msg = DDGM_TRAYICON) then
        begin
          TheIcon := TTrayNotifyIcon(WParam);
          case lParam of
               WM_LBUTTONDOWN:   TheIcon.FTimer.Enabled := True;
               WM_LBUTTONDBLCLK:  begin
                                    TheIcon.FNoShowClick := True;
                                    if Assigned(TheIcon.FOnDblClick) then TheIcon.FOnDblClick(Self);
                                 end;
               WM_RBUTTONDOWN:   begin
                                    if Assigned(TheIcon.FPopupMenu) then
                                    begin
                                      SetForegroundWindow(IconMgr.HWindow);
                                      GetCursorPos(Pt);
                                      TheIcon.FPopupMenu.Popup(Pt.x, Pt.y);
                                      PostMessage(IconMgr.HWindow, WM_USER, 0, 0);
                                    end;
                                 end;
          end;
        end
        else
          Result := DefWindowProc(FHWindow, Msg, wParam, lParam);
      end;
    end;
    //end Handler the Tray Icon message (IconMgr){TTrayNotifyIcon}
    function TTrayNotifyIcon.ActiveIconHandle: THandle;
    {Return handle of active icon}
    begin
      if (FIcon.Handle <> 0) then
        Result := FIcon.Handle
      else
        Result := FDefaultIcon;
    end;
    constructor TTrayNotifyIcon.Create(AOwner: TComponent);
    begin
      inherited Create(AOwner);
      FIcon := TIcon.Create;
      FTimer := TTimer.Create(Self);
      with FTimer do
      begin
        Enabled := False;
        Interval := GetDoubleClickTime;
        OnTimer := OnButtonTimer;
      end;
      {Keep default windows icon handy...}
      LoadDefaultIcon;
    end;destructor TTrayNotifyIcon.Destroy;
    begin
      if FIconVisible then SetIconVisible(False);
      FIcon.Free;
      FTimer.Free;
      inherited Destroy;
    end;procedure TTrayNotifyIcon.LoadDefaultIcon;
    begin
      FDefaultIcon := LoadIcon(0, IDI_WINlOGO);
    end;procedure TTrayNotifyIcon.Loaded;
    begin
      inherited Loaded;
      if FIconVisible then
        SendTrayMessage(NIM_ADD, NIF_MESSAGE or NIF_ICON or NIF_TIP);
    end;procedure TTrayNotifyIcon.Notification(AComponent: TComponent;
      Operation: TOperation);
    begin
      inherited Notification(AComponent, Operation);
      if (Operation = opRemove) and (AComponent = PopupMenu) then
        PopupMenu := nil;
    end;procedure TTrayNotifyIcon.OnButtonTimer(Sender: TObject);
    begin
      FTimer.Enabled := False;
      if (not FNoShowClick) and Assigned(FOnClick) then
        FOnClick(Self);
      FNoShowClick := False;
    end;procedure TTrayNotifyIcon.SendTrayMessage(Msg: DWORD; Flags: UINT);
    begin
      with Tnd do
      begin
        cbSize := SizeOf(Tnd);
        StrPlCopy(szTip, PChar(FHint), SizeOf(szTip));
        uFlags := Flags;
        uID := UINT(Self);
        Wnd := IconMgr.HWindow;
        uCallbackMessage := DDGM_TRAYICON;
        hIcon := ActiveIconHandle;
      end;
      Shell_NotifyIcon(Msg, @Tnd);
    end;procedure TTrayNotifyIcon.SetHideTask(Value: Boolean);
    const
      ShowArray: array[Boolean] of integer = (sw_ShowNormal, sw_Hide);
    begin
       if FHideTask <> Value then
       begin
         FHideTask := Value;
         if not (csDesigning in ComponentState) then
               ShowWindow(Application.Handle, ShowArray[FHideTask]);
       end;
    end;procedure TTrayNotifyIcon.SetHint(Value: String);
    begin
       if FHint <> Value then
       begin
         FHint := Value;
         if FIconVisible then
           SendTrayMessage(NIM_MODIFY, NIF_TIP);
       end;
    end;procedure TTrayNotifyIcon.SetIcon(Value: TIcon);
    begin
      FIcon.Assign(Value);          //Set new icon
      if FIconVisible then SendTrayMessage(NIM_MODIFY, NIF_ICON);
    end;procedure TTrayNotifyIcon.SetIconVisible(Value: Boolean);
    const
      MsgArray: array[Boolean] of DWORD = (NIM_DELETE, NIM_ADD);
    begin
      if FIconVisible <> Value then
      begin
        FIconVisible := Value;
        SendTrayMessage(MsgArray[Value], NIF_MESSAGE or NIF_ICON or NIF_TIP);
      end;
    end;procedure TTrayNotifyIcon.SetPopupMenu(Value: TPopupMenu);
    begin
      FPopupMenu := Value;
      if Value <> nil then Value.FreeNotification(Self);
    end;const
    {String to identify registered window message}
        TrayMsgStr = 'YOULOVEME';initialization
    {Get a unique windows message ID for tray callback}
        DDGM_TRAYICON := RegisterwindowMessage(TrayMsgStr);
        IconMgr := TIconManager.Create;
    finalization
        IconMgr.Free;
    end.