我定义了一个过程procedure WMNID(var msg:TMessage); message WM_NID; 
编译的时候说,Unknown directive: 'message',请问这个是什么问题?
WM_NID 我已经定义了  const WM_NID=WM_USER+1000;

解决方案 »

  1.   


    const WM_NID=WM_USER+1000;
    放在
    procedure WMNID(var msg:TMessage); message WM_NID;
    的前面
      

  2.   

    我是把
    const WM_NID=WM_USER+1000;
    放在
    procedure WMNID(var msg:TMessage); message WM_NID;
    的前面
    可是报错
      

  3.   

    呵呵。。肯定是单元文件中没有增加对 Messages的引用。
      

  4.   

    有把messages加到uses里面的。
    还是报错。
    名字换了也一样
    郁闷啊
      

  5.   

    在其上面Ctrl+Shift+c,生成其代码框架;随便输入些东西进去再编译看还会不会
      

  6.   

    你这种代码应该没有问题不过你有没有在procedure form1.WMNID(var msg:TMessage); message WM_NID;
    里写东西啊 
      

  7.   

    写了呀。
    我把我的源码贴出来。
    大家帮忙看看吧unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, shellapi;
      
    const WM_NID=WM_USER+1000;type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    procedure WMNID(var msg:TMessage); message WM_NID; //这里message报错
    var
      Form1: TForm1;
      Extendedstyle:integer;
      NotifyIcon:TNotifyIconData;
    implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
    Extendedstyle := GetWindowLong (Application.Handle, GWL_EXstyle);
    SetWindowLong(Application.Handle, GWL_EXstyle, Extendedstyle OR WS_EX_TOOLWINDOW
    AND NOT WS_EX_APPWINDOW);    //用于隐藏任务栏上的程序      With NotifyIcon do
          begin
            cbSize:=SizeOf(TNotifyIconData);
            Wnd:=Handle;
            uID:=1;
        uFlags:=NIM_ICON or NIM_MESSAGE or NIM_TIP;  //这里的三个参数也报错,说是Undeclared identifier
            uCallBackMessage:=WM_NID;
            hIcon:=Application.Icon.Handle;
            szTip:='我是老大';
          end;
        Shell_NotifyIcon(NIM_ADD,@NotifyIcon);
    end;procedure WMNID(var msg:TMessage); message WM_NID; //这里的message也有问题
    begin
       case msg.LParam of
          WM_LBUTTONUp: Form1.Visible:=not Form1.Visible;
          WM_RBUTTONUP: ShowMessage('right');
       End;
    End;
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
      Shell_NotifyIcon(NIM_DELETE,@NotifyIcon);
    end;end.
      

  8.   

    private
        { Private declarations }
        NotifyIcon: TNotifyIconData;
        procedure IconOnClick(var Msg: TMessage); message WM_NID;
    //把它放在private声明中去,再试试看
      

  9.   

    明显错误,既然要注册成窗口的消息,就一定要把过程放到窗体里下面为修改过的的代码:unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, shellapi;
      
    const WM_NID=WM_USER+1000;type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      private
        { Private declarations }
      public
        procedure WMNID(var msg:TMessage); message WM_NID; //这里message报错
        { Public declarations }
      end;
    var
      Form1: TForm1;
      Extendedstyle:integer;
      NotifyIcon:TNotifyIconData;
    implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
    Extendedstyle := GetWindowLong (Application.Handle, GWL_EXstyle);
    SetWindowLong(Application.Handle, GWL_EXstyle, Extendedstyle OR WS_EX_TOOLWINDOW
    AND NOT WS_EX_APPWINDOW);    //用于隐藏任务栏上的程序      With NotifyIcon do
          begin
            cbSize:=SizeOf(TNotifyIconData);
            Wnd:=Handle;
            uID:=1;
        uFlags:=NIM_ICON or NIM_MESSAGE or NIM_TIP;  //这里的三个参数也报错,说是Undeclared identifier
            uCallBackMessage:=WM_NID;
            hIcon:=Application.Icon.Handle;
            szTip:='我是老大';
          end;
        Shell_NotifyIcon(NIM_ADD,@NotifyIcon);
    end;procedure TForm1.WMNID(var msg:TMessage); message WM_NID; //这里的message也有问题
    begin
       case msg.LParam of
          WM_LBUTTONUp: Form1.Visible:=not Form1.Visible;
          WM_RBUTTONUP: ShowMessage('right');
       End;
    End;
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
      Shell_NotifyIcon(NIM_DELETE,@NotifyIcon);
    end;end.
      

  10.   

    哦了
    procedure TForm1.WMNID(var msg:TMessage); message WM_NID; //这里的message也有问
    你现在是实现函数,后面不用跟消息了。
    改成
    procedure TForm1.WMNID(var msg:TMessage);至于其他的。 uFlags:=NIM_ICON or NIM_MESSAGE or NIM_TIP;  //这里的三个参数也报错,说是Undeclared identifier去看看他们是哪个单元定义的常量,引用那个单元了。。我忘记了!
      

  11.   

    建议养成函数声明完成后用Ctrl+Shift+c 完成框架功能,免的在这些小问题是纠缠!
      

  12.   

    谢谢各位帮助,问题已经解决了。
    我把procedure WMNID(var msg:TMessage); message WM_NID; 放到 public 里
    WMNID过程中的message WM_NID;去掉就可以通过了。
    至于那个uFlags:=NIM_ICON or NIM_MESSAGE or NIM_TIP;我很是纳闷。
    代码重新复制粘贴一遍就没有错了。
    真是奇怪。