![]() |
|
#1
|
|||
|
|||
![]() Здрасте ребята , у меня вопрос о запуске програме в трее , писал тоже на асемблер давно , работает , пишу сейчас на делфи 6 , не хочет , есть проблеми. Помогите , покажите ошибки если не лень.
Вот мои пример с пустой форме : Код:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,ShellApi, Menus,AppEvnts; const WM_ICONTRAY = WM_USER + 1; NIF_INFO = 16; NIF_SHOWTIP = $80; WM_SHELLNOTIFY = WM_USER+5; type TForm1 = class(TForm) PopupMenu1: TPopupMenu; est11: TMenuItem; est21: TMenuItem; procedure FormShow(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure est11Click(Sender: TObject); procedure est21Click(Sender: TObject); private TrayIconData: TNotifyIconData; public procedure TrayMessage(var Msg: TMessage); message WM_ICONTRAY; procedure MySize(var Msg: TMessage); message WM_SIZE; end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormShow(Sender: TObject); begin with TrayIconData do begin cbSize := SizeOf(TrayIconData); Wnd := Handle; uID := 0; uFlags := NIF_MESSAGE+NIF_ICON+NIF_TIP+NIF_INFO+NIF_SHOWTIP; uCallbackMessage := WM_ICONTRAY; //WM_ICONTRAY hIcon := Application.Icon.Handle; StrPCopy(szTip, Application.Title); //uVersion:=NOTIFYICON_VERSION_4; end; Shell_NotifyIcon(NIM_ADD, @TrayIconData); //ShowWindow(Handle,SW_HIDE); //windows.PostMessage(Handle, WM_SYSCOMMAND, SC_MINIMIZE, 0); end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin Shell_NotifyIcon(NIM_DELETE, @TrayIconData); end; procedure TForm1.TrayMessage(var Msg: TMessage); var p : TPoint; begin case Msg.lParam of WM_LBUTTONDOWN: ShowWindow(Handle,SW_RESTORE); WM_LBUTTONDBLCLK: ShowWindow(Handle,SW_RESTORE); WM_RBUTTONDOWN: begin SetForegroundWindow(Handle); GetCursorPos(p); PopUpMenu1.Popup(p.x, p.y); PostMessage(Handle, WM_NULL, 0, 0); end; end; end; procedure TForm1.MySize(var Msg: TMessage); begin IF Msg.lParam=SIZE_MINIMIZED Then begin windows.PostMessage(Handle, WM_SYSCOMMAND, SC_MINIMIZE, 0); //Form1.Hide; end; end; procedure TForm1.est11Click(Sender: TObject); begin //Form1.Show; //ShowWindow(Handle,SW_RESTORE); windows.PostMessage(Handle, WM_SYSCOMMAND, SC_RESTORE, 0); end; procedure TForm1.est21Click(Sender: TObject); begin Shell_NotifyIcon(NIM_DELETE, @TrayIconData); exitprocess(0); end; end. |