Jump to content

Recommended Posts

Posted

Ois

Vou colocar tb aki porque pode alguem no futuro voltar a fazer a mm pergunta e assim so tem de fazer um pesquisar.

Unit Unit1;

Interface

Uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
     Dialogs, StdCtrls, ShellAPI;

Type TForm1 = Class(TForm)
            Button1: TButton;
            Procedure FormCreate(Sender: TObject);
            Procedure Button1Click(Sender: TObject);
     Private
            IconData: TNotifyIconData;
            Procedure CreateTrayIcon;
            Procedure MinimizeToTray;
            Procedure RestoreFromTray;
            Procedure FormDestroy(Sender: TObject);
     public
           procedure WndProc(var Msg : TMessage); override;
     End;

Var Form1: TForm1;

Implementation

{$R *.dfm}

Procedure TForm1.WndProc(Var Msg : TMessage);
Begin
  Case Msg.Msg Of
       WM_USER + 1:
               Case Msg.lParam Of
                    WM_RBUTTONDOWN:;
                    WM_LBUTTONDBLCLK: RestoreFromTray;
               End;
  End;
  Inherited;
end;

Procedure TForm1.CreateTrayIcon;
Begin
     IconData.cbSize := sizeof(IconData);
     IconData.Wnd := Handle;
     IconData.uID := 100;
     IconData.uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP;
     IconData.uCallbackMessage := WM_USER + 1;
     IconData.hIcon := Application.Icon.Handle;
     StrPCopy(IconData.szTip, Application.Title);
End;

Procedure TForm1.MinimizeToTray;
Begin
     Shell_NotifyIcon(NIM_ADD, @IconData);
     Form1.Hide;
     ShowWindow(Application.Handle, SW_HIDE);
End;

Procedure TForm1.RestoreFromTray;
Begin
     Shell_NotifyIcon(NIM_DELETE, @IconData);
     ShowWindow(Application.Handle, SW_SHOW);
     Form1.Show;
     Application.BringToFront;
End;

Procedure TForm1.FormDestroy(Sender: TObject);
Begin
     Shell_NotifyIcon(NIM_DELETE, @IconData);
End;

Procedure TForm1.FormCreate(Sender: TObject);
Begin
     CreateTrayIcon;
End;

Procedure TForm1.Button1Click(Sender: TObject);
Begin
     MinimizeToTray;
End;

End.

Se a vida te voltar as costas aproveita e apalpa-lhe o cu.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.