我用delphi8.0学习系统托盘代码,新建立了一个VCL form appliction
输入代码如下:
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Shellapi,
  Dialogs;type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;
  Tray:NOTIFYICONDATA;
implementation{$R *.nfm}procedure TForm1.FormCreate(Sender: TObject);
begin
Tray.cbSize:=sizeof(Tray);
Tray.Wnd:=Self.Handle;
Tray.uID:=9998;
Tray.uFlags:=NIF_ICON+NIF_MESSAGE+NIF_TIP;
Tray.uCallbackMessage:=WM_USER;
Tray.hIcon:=application.Icon.Handle ;
Tray.szTip:='定时关机';
Shell_NotifyIcon(NIM_ADD,@Tray);
end;end.
运行时提示:[error] unsafe code only allowed unsafe procedure\
怎么办?

解决方案 »

  1.   

    发现:
    1、提示的错误是,Shell_NotifyIcon(NIM_ADD,@Tray); 这一行的问题。
    2、把 Shell_NotifyIcon(NIM_ADD,@Tray); 的@Tray去掉前面的@,可以运行,但是系统托盘中没有默认的图标,但是有个空的位置,鼠标放过去有上面给的文字显示'定时关机'。
    怎么办?
    指针问题?
    我新手。 
      

  2.   

    D8 只有 for .net 版本,而且是一个不成熟的产品
    建议使用D7,或D2007及以上
      

  3.   

    如果要用.NET版本,还是D2006吧
      

  4.   

    http://download.csdn.net/source/1469205