我按照csdn上面一位大哥的文章写了一个托盘的东东,可他对我说message这错,我注释掉以后,不报错了可怎么对着托盘点右键就是没反应啊,请大家帮帮忙,代码如下,现在是没注释的,就报错。
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,ShellAPI, StdCtrls, Menus;
  const WM_NID=WM_USER+1000;
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;
  NotifyIcon:TNotifyIconData;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
//NotifyIcon为全局变量,在程序的开头已经定义了
  with NotifyIcon do
    begin
      cbSize:=SizeOf(TNotifyIconData);
      Wnd:=Handle;   //指向当前窗体Form1的句柄
      uID:=1;
      uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP;
      uCallBackMessage:=WM_NID;
      hIcon:=Application.Icon.Handle;
      szTip:='张家恶少';
    end;
//把设置好的变量NotifyIcon加入到系统中以便处理
    Shell_NotifyIcon(NIM_ADD,@NotifyIcon);
end;procedure WMNID(var msg:TMessage);Message WM_NID;
  begin
    case msg.LParam of
      WM_LBUTTONUp:Form1.Visible:=not Form1.Visible;
      WM_RBUTTONUP:ShowMessage('您点击的是右键');
    End;
End;procedure TForm1.FormDestroy(Sender: TObject);
begin
  Shell_NotifyIcon(NIM_DELETE,@NotifyIcon);
end;end.我在type里面声明以后,他就会说不存在TForm1.WMNID,请帮忙,并告诉我一下,问题出在哪里,我想搞明白,谢谢了

解决方案 »

  1.   

    你在procedure FormDestroy(Sender: TObject);后加上procedure wmnid(var message:tmessage);message wm_nid;
    procedure tform1.WMNID(var msg:TMessage);Message WM_NID;
      begin
        case msg.LParam of
          WM_LBUTTONUp:Form1.Visible:=not Form1.Visible;
          WM_RBUTTONUP:ShowMessage('您点击的是右键');
        End;
    End;应该没问题了;
      

  2.   

    应该能看明白吧先声明,procedure wmnid(var message:tmessage);message wm_nid;
    然后再实现部分写入
    procedure tform1.WMNID(var msg:TMessage);Message WM_NID;
      begin
        case msg.LParam of
          WM_LBUTTONUp:Form1.Visible:=not Form1.Visible;
          WM_RBUTTONUP:ShowMessage('您点击的是右键');
        End;
    End;
      

  3.   

    [Error] Unit1.pas(53): Declaration of 'WMNID' differs from previous declaration
      [Error] Unit1.pas(56): Object or class type required
      [Fatal Error] Project2.dpr(5): Could not compile used unit 'Unit1.pas'
    还是抱错,以上是报错信息
      

  4.   

    53行是:procedure TForm1.WMNID(var msg:TMessage);Message WM_NID;
    56行是:case msg.LParam of
      

  5.   

    把53行的 Message WM_NID;去掉 看来你还刚开始DELPHI 吧
      

  6.   

    恩,我是刚刚开始,呵呵
    不过我把53行的Message WM_NID去掉了他还是一样的错误啊
      

  7.   

    ok,我搞定了,问题出在声明的里面,要把53行的var msg:TMessage改成和声明的一样才可以,vusyal_cjiajia说得也对,把后面那个也要去掉,谢谢各位的解答。
    另外我想问一下,如果我要让她右击托盘的时候出来的不是框而是那种小的菜单是怎么弄的呢?能把代码写一下吗?谢谢了,收到了我就结帖
    在此谢谢大家的解答。