Tray İcon Yardım!
-
Delphi’ye yeni başladım.Kaynak kodlu programları inceleyerek öğrenmeye çalışıyorum.Tray icon yapmak için aşağıdaki kodu buldum fakat çalıştıramadım.proje halinde olmadıgı için buton vs eklerken hata yapıyorum galiba.Bu şekilde bulduğum kodları uygularken ne yapmak gerek , Aşağıdaki kodu proje halinde çalışır vaziyete getirirseniz memnun olurum..
Unit SysTray; Interface Uses Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,ShellApi,Menus, StdCtrls; Type TForm1 = Class(TForm) menu : TPopupMenu; menuHakkinda : TMenuItem; menuAc : TMenuItem; menuCikis : TMenuItem; AcilisNotu : TMemo; ButonTamam : TButton; ButonCik : TButton; Procedure FormCreate(Sender: TObject); Procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer); Procedure menuHakkindaClick(Sender: TObject); Procedure menuCikisClick(Sender: TObject); Procedure menuAcClick(Sender: TObject); Procedure FormDestroy(Sender: TObject); Procedure ButonTamamClick(Sender: TObject); Procedure ButonCikClick(Sender: TObject); Private TrayIcon : TNotifyIconData; Procedure FormuGizle(Sender: TObject); Procedure FormuGoster; Procedure MenuyuGoster; Public End; Var Form1 : TForm1; Implementation {$R *.dfm} Procedure TForm1.FormuGizle(Sender: TObject); Begin Shell_NotifyIcon(NIM_ADD,@TrayIcon); // System Tray'e yeni bir Icon ekle Form1.Visible:=False; // Formu gizle End; Procedure TForm1.MenuyuGoster; Var FareninKonumu : TPoint; Begin GetCursorPos(FareninKonumu); // Mouse'un pozisyonunu öğren menu.Popup(FareninKonumu.X,FareninKonumu.Y); // PopUp menüyü o pozisyona aç PostMessage(Self.Handle,WM_NULL,0,0); // Systeme Herhangibir Mesaj Gönderme End; Procedure TForm1.FormCreate(Sender: TObject); Begin // TrayIcon'ın parametreleri aşağıda ayarlanıyor. With TrayIcon Do Begin cbsize := SizeOf(TrayIcon); wnd := Self.Handle; hicon := Application.Icon.Handle; uID := 0; sztip := 'Mouse icon üzerindeyken görünecek mesaj.'; uflags := NIF_ICON Or NIF_TIP Or NIF_MESSAGE; uCallBackMessage := WM_MOUSEMOVE; End; Application.OnMinimize:=FormuGizle; // Form minimize edilince çalışacak procedure End; Procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer); Begin // $201 Sol Tuş Basıldı // $202 Sol Tuş Bırakıldı // $203 Sol Tuş Çift Tıklandı // $204 Sağ Tuş Basıldı // $205 Sağ Tuş Bırakıldı // $206 Sağ Tuş Çift Tıklandı If (x=$203) Then FormuGoster Else If (x=$205) Then MenuyuGoster; End; Procedure TForm1.FormuGoster; Begin Form1.Visible:=True; // Formu göster Application.BringToFront; // Formu öne al Application.Restore; // Uygulamayı tekrar başlat Shell_NotifyIcon(NIM_DELETE,@TrayIcon); // System Tray'deki iconu sil End; Procedure TForm1.menuHakkindaClick(Sender: TObject); Begin ShowMessage('System Tary Denemesi'+#13+ 'Copyright (C) 2002 Hakan HAMURCU'+#13+ 'hakan@hamurcu.com'); End; Procedure TForm1.menuCikisClick(Sender: TObject); Begin Application.Terminate; // Uygulamayı bitir End; Procedure TForm1.FormDestroy(Sender: TObject); // Form hafızadan atıldığı zaman Begin Shell_NotifyIcon(NIM_DELETE,@TrayIcon); // System Tray'deki iconu sil End; Procedure TForm1.menuAcClick(Sender: TObject); Begin FormuGoster; End; Procedure TForm1.ButonTamamClick(Sender: TObject); Begin FormuGizle(Sender); End; Procedure TForm1.ButonCikClick(Sender: TObject); Begin Application.Terminate; // Uygulamayı bitir End; End.
Toplam Hit: 2240 Toplam Mesaj: 1
