D
DJ6674
Unregistered / Unconfirmed
GUEST, unregistred user!
我编译时,提示IconOnClick定义了但没有使用.在托盘图标上单击或者右击时,没有反应.<br>代码如下:<br><br>unit main;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls,setting, ExtCtrls, jpeg, Menus,shellapi;<br><br>type<br> TForm1 = class(TForm)<br> Image1: TImage;<br> Label1: TLabel;<br> Label2: TLabel;<br> PopupMenu1: TPopupMenu;<br> N1: TMenuItem;<br> N2: TMenuItem;<br> N3: TMenuItem;<br> N4: TMenuItem;<br> N5: TMenuItem;<br> N6: TMenuItem;<br> N7: TMenuItem;<br> N8: TMenuItem;<br> N9: TMenuItem;<br> X1: TMenuItem;<br> procedure FormClick(Sender: TObject);<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> procedure FormCreate(Sender: TObject);<br> procedure N7Click(Sender: TObject);<br> procedure X1Click(Sender: TObject);<br> procedure N5Click(Sender: TObject);<br> procedure N3Click(Sender: TObject);<br> procedure N8Click(Sender: TObject);<br> private<br> procedure IconOnClick(var message:TMessage);<br><br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br><br><br>var<br> Form1: TForm1;<br><br><br>implementation<br><br>{$R *.dfm}<br>//程序没有问题,但是下面一个过程应有的功能没有实现<br>procedure TForm1.IconOnClick(var message:Tmessage); //设置左右键功能<br>var p:Tpoint;<br>begin<br> if (message.LParam=WM_LBUTTONDOWN) then<br> begin<br> Form2.Show;<br> end;<br><br> if (message.LParam=WM_RBUTTONDOWN) then<br> begin<br> GetCursorPos(p);<br> PopupMenu1.Popup(p.X,p.Y);<br> end;<br>end;<br><br><br><br> //以下是装载图标的过程<br>procedure InstIcon(ToyIcon:TIcon;WinHandle:THandle;cbMessage:Integer);<br>const ICON_ID=3;<br>var IconData:TNotifyIconData;<br>begin<br> IconData.cbSize:=Sizeof(IconData);<br> IconData.Wnd:=WinHandle;<br> IconData.uID:=ICON_ID;<br> IconData.uFlags:=NIF_MESSAGE or NIF_ICON or NIF_TIP;<br> IconData.uCallbackMessage:=cbMessage;<br> IconData.hIcon:=ToyIcon.Handle;<br> IconData.szTip:='欢迎使用';<br> Shell_NotifyIcon(NIM_ADD,@IconData);<br>end;<br><br>//删除图标<br>procedure DeleIcon(winHandle:THandle);<br>const ICON_ID=3;<br>var IconData:TNotifyIconData;<br>begin<br> IconData.cbSize:=SizeOf(IconData);<br> IconData.Wnd:=winHandle;<br> IconData.uID:=ICON_ID;<br> Shell_NotifyIcon(NIM_DELETE,@IconData);<br>end;<br><br>procedure TForm1.FormClick(Sender: TObject);<br>begin<br>Form1.Hide;<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br>DeleIcon(Handle);<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>const<br>MI_ICONEVENT=WM_USER+1;<br>begin<br>InstIcon(Application.Icon,Application.Handle,MI_ICONEVENT);<br>end;<br><br>procedure TForm1.N7Click(Sender: TObject);<br>begin<br>end;<br><br>procedure TForm1.X1Click(Sender: TObject);<br>begin<br>end;<br><br>procedure TForm1.N5Click(Sender: TObject);<br>begin<br>end;<br><br>procedure TForm1.N3Click(Sender: TObject);<br>begin<br>end;<br><br>procedure TForm1.N8Click(Sender: TObject);<br>begin<br>end;<br><br><br>end.