我用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\
怎么办?
输入代码如下:
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\
怎么办?
解决方案 »
- 求一QReport组件 教程/介绍,找了2天找不到
- 求教:关于在Bitmap上画icon,显示不正常
- 求delphi 7的函数和组件参考大全
- delphi代码问题,请高手指点
- 选择Delphi方向,还是选择C#方向,给小弟指个路。刚刚学习Delphi,但感觉现在公司用C#或JAVA方面的多。谢谢!
- 关于异常处理?
- 如何动态生成一个表?
- adoconnection设置了xaCommitRetaining, xaAbortRetaining两个属性出错
- 求解:回车key=#13,那么小数点的key为多少呢?在线等待!!!
- 请问连接adoconnection的问题?
- 有会编黑白棋程序的请进!! 能帮得上忙的十分感谢!急
- 恭喜老刘版主
1、提示的错误是,Shell_NotifyIcon(NIM_ADD,@Tray); 这一行的问题。
2、把 Shell_NotifyIcon(NIM_ADD,@Tray); 的@Tray去掉前面的@,可以运行,但是系统托盘中没有默认的图标,但是有个空的位置,鼠标放过去有上面给的文字显示'定时关机'。
怎么办?
指针问题?
我新手。
建议使用D7,或D2007及以上