NOTIFYICONDATA

  做一个按钮,它的作用是按下去后,窗口最小化在任务栏的最右边(即是在声音的小图标那里)  
  请高手写这个程序出看看!!!

 

 unit   Unit1;  
   
  interface  
   
  uses  
      Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,  
      Dialogs,   StdCtrls,shellapi;  
  const  
      MY_MESSAGE=WM_USER+100;  
      Type   TZoomDirection   =   (ZoomFormOpen,ZoomFormClosed);//枚举类型  
  type  
      TForm1   =   class(TForm)  
          Button1:   TButton;  
          procedure   FormCreate(Sender:   TObject);  
          procedure   FormClose(Sender:   TObject;   var   Action:   TCloseAction);  
          procedure   Button1Click(Sender:   TObject);  
      private  
            Procedure   FrmZoomToTray(Frm:TForm;Direction:TZoomDirection);//这里是动太的缩放,很经典的,我弄了好久的东西:)  
            //添加消息处理函数  
          procedure   OnIconNotify(var   message:TMessage);  
          message   MY_MESSAGE;  
          {   Private   declarations   }  
      public  
          {   Public   declarations   }  
      end;  
   
  var  
      Form1:   TForm1;  
   
  implementation  
   
  {$R   *.dfm}  
  //从系统工作区中进入或出来的动态效果  
  Procedure   TForm1.FrmZoomToTray(Frm:TForm;Direction:TZoomDirection);  
  Var  
        TrayWnd:   HWND;  
        sClassName:   Array[0..255]   Of   Char;  
        xFrom,xTo:   TRect;  
  Begin  
        If   (Direction   =   ZoomFormClosed)   And   (Frm.Visible   =   False)   Then  
              Exit;  
        If   (Direction   =   ZoomFormOpen)   And   (Frm.Visible   =   True)   Then  
              Exit;  
        TrayWnd   :=   FindWindow('Shell_TrayWnd',Nil);  
        TrayWnd   :=   GetWindow(TrayWnd,GW_CHILD);  
        Repeat  
              GetClassName(TrayWnd,@sClassName,255);  
              If   StrPas(sClassName)   =   'TrayNotifyWnd'   Then  
                    Break;  
              TrayWnd   :=   GetWindow(TrayWnd,GW_HWNDNEXT);  
        Until   TrayWnd   =   0;  
        Case   Direction   Of  
              ZoomFormOpen:  
                    Begin  
                          GetWindowRect(TrayWnd,xFrom);  
                          xFrom.Left   :=   (xFrom.Right   -   (xFrom.Right   -   xFrom.Left)   Div   2);  
                          xFrom.Right   :=   xFrom.Left   +   1;  
                          GetWindowRect(Frm.Handle,xTo);  
                          DrawAnimatedRects(Frm.Handle,IDANI_OPEN   Or   IDANI_CAPTION   ,xFrom   ,xTo);  
                    End;  
              ZoomFormClosed:  
                    Begin  
                          GetWindowRect(Frm.Handle,xFrom);  
                          GetWindowRect(TrayWnd,xTo);  
                          xTo.Left   :=   (xTo.Right   -   (xto.Right   -   xTo.Left)   Div   2);  
                          xTo.Right   :=   xTo.Left   +   1;  
                          DrawAnimatedRects(Frm.Handle,IDANI_CLOSE   Or   IDANI_CAPTION,xFrom,xTo);  
                    End;  
        End;  
  End;  
   
   
   
  procedure   TForm1.OnIconNotify(var   message:Tmessage);   //   下面的菜单表示我省掉了  
  //var  
  //   mousept:   TPoint;   //鼠标点击位置  
  begin  
    inherited;  
  if   message.LParam   =   wm_rbuttonup   then   begin   //用鼠标右键点击图标  
  //   getcursorpos(mousept);   //获取光标位置  
  //   popupmenu2.popup(mousept.x,   mousept.y);   //在光标位置弹出菜单  
  end;  
  if   message.LParam   =   wm_lbuttonup   then   begin   //用鼠标左键点击图标  
    //显示应用程序窗口  
      if   form1.Visible   then  
            begin  
            FrmZoomToTray(Form1,ZoomFormClosed);  
            form1.Hide;  
            end  
      else  
            begin  
            FrmZoomToTray(Form1,ZoomFormOpen);  
            form1.Show;  
            end;  
    //ShowWindow(Handle,   SW_SHOW);  
    //在任务栏上显示应用程序窗口  
    //ShowWindow(Application.handle,   SW_HIDE);  
   
    {SetWindowLong(Application.Handle,   GWL_EXSTYLE,  
    not   (GetWindowLong(Application.handle,   GWL_EXSTYLE)  
    or   WS_EX_TOOLWINDOW   AND   NOT   WS_EX_APPWINDOW));}  
  end;  
  end;  
   
  procedure   TForm1.FormCreate(Sender:   TObject);  
  var  
  //定义一个TNotifyIconData类型的变量  
  {NotifyIconData结构中各成员的意义  
      cbSize     设定NotifyIconData   变量的字节数  
      hWnd         设定与系统信息区图标相对应的应用程序主窗口句柄  
      uID           设定内部标识  
      uFlags     指明NotifyIconData   的哪些字段是有效的  
      hIcon       设定在系统信息区显示的图标句柄  
      uCallbackMessage   设定回调函数的消息  
      szTip[64]     设定当鼠标悬停在图标上时显示的提示字符串}  
  NotifyIconData:TNotifyIconData;  
  begin  
  //SetWindowLong   任务栏上不出现按钮  
  setWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);  
  //系统信息栏  
  NotifyIconData.cbSize:=sizeof(NotifyIconData);  
  NotifyIconData.Wnd:=Handle;  
  NotifyIconData.uID:=1000;  
  NotifyIconData.hIcon:=Application.Icon.Handle;  
  NotifyIconData.szTip:='任务栏系统信息区示例程序';  
  NotifyIconData.uCallbackMessage:=MY_MESSAGE;  
  NotifyIconData.uFlags:=NIF_ICON   OR   NIF_TIP   OR   NIF_MESSAGE;  
  //向系统信息区添加图标  
  if   not   Shell_notifyIcon(NIM_ADD,@NotifyIconData)then  
  begin  
    showMessage('Failed!');  
    Application.Terminate;  
  end;  
  end;  
   
  procedure   TForm1.FormClose(Sender:   TObject;   var   Action:   TCloseAction);  
  var  
    //定义一个TnotifyIconData类型退出时删除图标  
    notifyIconData:TnotifyIconData;  
  begin  
      notifyIcondata.cbSize:=sizeof(notifyIcondata);  
      notifyIcondata.uID   :=1000;  
      notifyIcondata.Wnd   :=handle;  
      shell_notifyIcon(NIM_DELETE,@NotifyIconData);  
  end;  
   
  procedure   TForm1.Button1Click(Sender:   TObject);  
  begin  
  FrmZoomToTray(Form1,ZoomFormClosed);  
  form1.Hide;  
  end;  
   
  end.  

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值