请问,如何实现一个窗体一道屏幕边缘一定范围内是自动隐藏,当鼠标移动到屏幕边缘时又自动显示?最好可以给出源代码!!!谢谢]!!!!!

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, {Variants, }Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls, Menus, StdCtrls, ShellAPi, Buttons{, DateUtils };const  ConHeight=20;
           Weeks: array [1..7] of String = ('Sunday', 'Monday', 'Tuesday', 'Wednesda', 'Thursday', 'Friday', 'Saturday');type
      TForm1 = class(TForm)
        Panel1: TPanel;
        Label1: TLabel;
        Label2: TLabel;
        PopupMenu1: TPopupMenu;
        Timer1: TTimer;
        N1: TMenuItem;
        N2: TMenuItem;
        N3: TMenuItem;
        SpeedButton1: TSpeedButton;
        Label3: TLabel;
        Timer2: TTimer;
        procedure FormCreate(Sender: TObject);
        procedure N3Click(Sender: TObject);
        procedure N1Click(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
        procedure SpeedButton1Click(Sender: TObject);
        procedure Timer2Timer(Sender: TObject);
      private
        { Private declarations }
         procedure CMMouseEnter(var Msg: TMessage); message CM_MouseEnter;
         procedure CMMouseLeave(var Msg: TMessage); message CM_MouseLeave;
         procedure HideMyForm();
         procedure ShowMyForm();
      public
        FormWidth: integer;
        { Public declarations }
      end;Const
      conMyMouseEventMessage = Longint(20021022); // Define My mouse event Wparam.
    var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
        form1.Left := Screen.DesktopLeft;
        form1.Top := Screen.DesktopTop;
        form1.Height := 1;
        Form1.Width := 250;
        FormWidth := Form1.Width;    SpeedButton1.Left := Form1.Width - 20;    SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW); //祥珆尨婓昢戲
    end;procedure TForm1.N3Click(Sender: TObject);
    begin
       close;
    end;procedure TForm1.N1Click(Sender: TObject);
    begin
       ShellExecute(handle, '', 'd:\-奀潔', '', '', SW_SHOWNORMAL);
    end;procedure TForm1.Timer1Timer(Sender: TObject);
    begin
        Label1.Caption := DateToStr(now);
        Label2.Caption := TimeTostr(Now);
        Label3.Caption := Weeks[DayOfWeek(Now)];
    end;procedure TForm1.SpeedButton1Click(Sender: TObject);
    begin
       if Speedbutton1.Caption = '>>' then
       begin
         while form1.Width <> screen.Width do
           form1.Width := form1.Width + 1;
         SpeedButton1.Caption := '<<';
         Speedbutton1.Left := Form1.Width -20;
         Label1.Left := form1.Width div 4;
         Label2.Left := form1.Width div 4 + Label1.Left;
         Label3.Left := Form1.Width div 4 + Label2.Left;
       end else
       if Speedbutton1.Caption ='<<' then
       begin
         while form1.Width > FormWidth do
           Form1.Width := Form1.Width - 1;
         Speedbutton1.Caption := '>>';
         Speedbutton1.Left := Form1.Width -20;
         Label1.Left := 16;
         Label2.Left := 110;
         Label3.Left := 176;
       end;
    end;Procedure TForm1.CMMouseEnter(var Msg: TMessage);
    //Note: CM_MouseEnter's wparam alway is 0 until it is my event message.
    begin
      inherited;
      if Msg.wParam = conMyMouseEventMessage then ShowMyForm;
     end;procedure TForm1.CMMouseLeave(var Msg: TMessage);
    //Note: CM_MouseLeave's wparam alway is 0 until it is my event message.
    begin
      inherited;
      if Msg.wParam = conMyMouseEventMessage then HideMyForm;
    end;
    procedure TForm1.Timer2Timer(Sender: TObject);
    var
      pt : TPoint;
    begin
      GetCursorPos(Pt);                              // Get Mouse position.
      pt := ScreenToClient(pt);
      if (pt.x < panel1.Left) or (pt.x > panel1.Left + panel1.width)
        or (pt.y < panel1.top) or (pt.y > panel1.top + panel1.height) then  // Check mouse in form or not.
        Form1.Perform (CM_MOUSELEAVE,conMyMouseEventMessage,0)   // Sent my cm_mouseleave to form;
    //    HideMyForm            // Not in form then hide form.
      else
        Form1.Perform (CM_MOUSEENTER,conMyMouseEventMessage,0);    // Sent my cm_mouseenter to form;
    //    ShowMyForm;           // In form then show form.
    end;procedure TForm1.HideMyForm;
    Var
      I : Integer;
    begin
      if Height >1 then
      begin
         for i:=1 to ConHeight do
         begin
           Height := Height - 1;
           sleep(3);
         end;
      end;
    end;procedure TForm1.ShowMyForm;
    Var
      I : Integer;
    begin
      If Height <= 1 then
      begin
        for i:=1 to ConHeight do
        begin
          Height := Height + 1;
          sleep(3);
        end;
      end;
    end;end.
      

  2.   

    代码我没有delphi的,以前用VC写过一个。但是不是什么好方法,(使用了CTimer控件)可以给你点参考! 去年的程序员合定本中有专门将这个的一片文章!那里面好像讲了2种方法(我没有详细看)