How to display a message window in the right bottom corner of the active display using Delphi

前端 未结 7 1538
青春惊慌失措
青春惊慌失措 2021-02-04 17:29

These days you see a lot of software displaying message windows in the right bottom corner of the active screen for a few seconds or until a close button is cli

7条回答
  •  粉色の甜心
    2021-02-04 17:45

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.FormCreate(Sender: TObject);
      function TaskBarHeight: integer; // this is just to get the taskbar height to put
      // my form in the correct position
      var
        hTB: HWND;
        TBRect: TRect;
      begin
        hTB := FindWindow('Shell_TrayWnd', '');
        if hTB = 0 then
          Result := 0
        else
        begin
          GetWindowRect(hTB, TBRect);
          Result := TBRect.Bottom - TBRect.Top;
        end;
      end;
    
    begin
      Self.Left := Screen.Width - Self.Width;
      Self.Top := Screen.Height-Self.Height-TaskBarHeight;
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      i: integer;
      TimeSleep: integer;
    begin
      TimeSleep := 5; // the speed you want to show/hide.Increase/descrease this to make it faster or slower
      for i := 1 to Self.Height do
      begin
        Self.Top := Self.Top+1;
        Sleep(TimeSleep);
      end;
      // now let's show it again(use this as code as the show code)
      for i := 1 to Self.Height do
      begin
        Self.Top := Self.Top-1;
        Sleep(TimeSleep);
      end;
    end;
    
    end.
    

    via http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_25043483.html

提交回复
热议问题