托盘程序中这个函数怎么老是报错 [Error] Unit1.pas(32): Unknown directive: 'message',请大家出手相助 (50分

  • 主题发起人 主题发起人 jiafei528
  • 开始时间 开始时间
J

jiafei528

Unregistered / Unconfirmed
GUEST, unregistred user!
托盘程序中这个函数怎么老是报错 [Error] Unit1.pas(32): Unknown directive: 'message',请大家出手相助 (50分)<br />托盘程序中这个函数怎么老是报错 [Error] Unit1.pas(32): Unknown directive: 'message',请大家出手相助 <br>procedure WMNID(var msg:TMessage); message WM_NID;<br>begin<br>&nbsp; &nbsp; case msg.LParam of<br>&nbsp; &nbsp; &nbsp; WM_LBUTTONUp; Form1.Visible:=not Form1.Visible;<br>&nbsp; &nbsp; &nbsp; WM_RBUTTONUP: ShowMessage(&amp;iexcl;&amp;reg;&amp;Auml;ú&amp;micro;&amp;atilde;&amp;raquo;÷&amp;micro;&amp;Auml;&amp;Ecirc;&amp;Ccedil;&amp;Oacute;&amp;Ograve;&amp;frac14;ü&amp;iexcl;&amp;macr;);<br>&nbsp; &nbsp; End;<br>End; &nbsp;<br>
 
2、TNotifyIcon 控件1.01 (Build use Delphi 3.0) 说明:<br>作用:<br>&nbsp;往通知区加图标,并可显示,隐藏,修改这个图标.<br>&nbsp; <br><br>属性(properties):<br>&nbsp;NotifyIcon:TIcon &nbsp;欲加在通知区的图标<br>&nbsp;IsVisible:boolean NotifyIcon是否显示的属性<br>&nbsp;Title:string &nbsp;通知区图标上的提示(最多64个字符)<br>&nbsp;PopupMenu:TPopupMenu 点击通知区图标弹出的菜单 <br>&nbsp;PopupStyle:TPopupStyle 弹出菜单的方式 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; TPopupStyle=Set of (Left_Click,Right_Click,Left_DbClick,Right_DbClick);<br>方法(methods): &nbsp; <br>&nbsp; &nbsp;ShowIcon &nbsp;将图标显示在通知区上<br>&nbsp; &nbsp;HideIcon &nbsp;将通知区上的图标隐藏<br>&nbsp; &nbsp;ModifyIcon 修改通知区上的图标(若IsVisible=false,则不显示出来)<br>&nbsp; &nbsp;Create(AOwner: TComponent); override; 构造方法<br>&nbsp; &nbsp;Destroy; override; 析构方法<br>事件(Events):<br>&nbsp; &nbsp; OnIconMouseDown: <br>&nbsp; &nbsp; &nbsp; procedure(Sender:TObject;x,y:Word;WhoButton:TWhoButton) of Object;<br>&nbsp; &nbsp; &nbsp; (<br>&nbsp; &nbsp; &nbsp; &nbsp;在Mouse点击通知区上的图标时发生,x,y为Mouse在屏幕上的坐标,<br>&nbsp; &nbsp; &nbsp; &nbsp;WhoButton=b_Left为点击左键,WhoButton=b_Right为点击右键,<br>&nbsp; &nbsp; &nbsp; )<br>&nbsp; &nbsp; OnIconDoubleClick: <br>&nbsp; &nbsp; &nbsp; procedure(Sender:TObject;x,y:Word;WhoButton:TWhoButton) of Object;<br>&nbsp; &nbsp; &nbsp;(<br>&nbsp; &nbsp; &nbsp; 在Mouse双击通知区上的图标时发生,x,y为Mouse在屏幕上的坐标,<br>&nbsp; &nbsp; &nbsp; WhoButton=b_Left为双击左键,WhoButton=b_Right为双击右键,<br>&nbsp; &nbsp; &nbsp;)<br>关于Demo:<br>&nbsp; &nbsp;这个演示程序给出了TNotifyIcon的基本用法.<br><br>包含文件:<br>&nbsp;NotifyIcon.dcr<br>&nbsp;NotifyIcon.pas<br>&nbsp;DemoUnit.pas<br>&nbsp;DemoUnit.dfm<br>&nbsp;PopUnit.pas<br>&nbsp;PopUnit.dfm<br>&nbsp;Demo.dpr<br>&nbsp;Readme.txt<br><br>声明:<br>&nbsp; &nbsp; &nbsp;TNotifyIcon 控件 V 1.01<br>1.这是一个免费控件.<br>2.如果你使用它,请发一个E-Mail给作者,谢谢.<br>3我在Delphi3.0 &amp; 4.0 上使用成功<br>4.若要传播它,请完全分发上述8个文件<br><br>&nbsp; &nbsp; &nbsp;作者 &nbsp;南昌大学计算系95(1) &nbsp;付昱纲 1998.8.17 &nbsp;21:50<br>&nbsp; &nbsp; &nbsp;E-mail &nbsp; fyg@163.net &nbsp;<br><br>unit NotifyIcon;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; DsgnIntf,ShellApi,ExtCtrls,Menus;<br><br>const<br>&nbsp; &nbsp; &nbsp; WM_MY_Notify=WM_USER+100;<br>type<br><br>&nbsp; TPopupStyle=Set of (Left_Click,Right_Click,Left_DbClick,Right_DbClick);<br>&nbsp; TWhoButton=(b_Left,b_Right);<br>&nbsp; TMouseEvent=<br>&nbsp; procedure(Sender:TObject;x,y:Word;WhoButton:TWhoButton)<br>&nbsp; &nbsp; &nbsp; of Object;<br><br>//---------class TNotifyIcon---------<br>&nbsp; TNotifyIcon = class(TCustomControl)<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; FIcon:TIcon;<br>&nbsp; &nbsp; FPda:PNOTIFYICONDATA;<br>&nbsp; &nbsp; FTitle:string;<br>&nbsp; &nbsp; FIconVisible:boolean;<br>&nbsp; &nbsp; FPopupMenu:TPopupMenu;<br>&nbsp; &nbsp; FPopupStyle:TPopupStyle;<br>&nbsp; &nbsp; FOnIconMouseDown:TMouseEvent;<br>&nbsp; &nbsp; FOnIconDoubleClick:TMouseEvent;<br>&nbsp; &nbsp; procedure SetIcon(Icon:TICON);<br>&nbsp; &nbsp; procedure SetTitle(NewTitle:string);<br>&nbsp; &nbsp; function IsShowing:boolean;<br>&nbsp; &nbsp; procedure ShowIt(Accept:boolean);<br>&nbsp; &nbsp; procedure NotifyIconClick(var msg : TMessage);<br>&nbsp; &nbsp; &nbsp; Message WM_My_Notify;<br>&nbsp; protected<br>&nbsp; &nbsp; { Protected declarations }<br>&nbsp; &nbsp;public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; &nbsp;property IsVisible:boolean read IsShowing write ShowIt;<br>&nbsp; &nbsp;constructor Create(AOwner: TComponent); override;<br>&nbsp; &nbsp;procedure ShowIcon;<br>&nbsp; &nbsp;procedure HideIcon;<br>&nbsp; &nbsp;destructor Destroy; override;<br>&nbsp; &nbsp;procedure ModifyIcon(NewIcon:TIcon);<br>&nbsp; &nbsp;procedure Paint;override;<br>&nbsp; published<br>&nbsp; &nbsp; { Published declarations }<br>&nbsp; &nbsp; property Height default 33;<br>&nbsp; &nbsp; property Width &nbsp;default 33;<br>&nbsp; &nbsp; property NotifyIcon:TIcon read FIcon &nbsp;write SetIcon;<br>&nbsp; &nbsp; property Title:string read FTitle write SetTitle ;<br>&nbsp; &nbsp; property OnIconDoubleClick:TMouseEvent<br>&nbsp; &nbsp; &nbsp; read FOnIconDoubleClick write FOnIconDoubleClick;<br>&nbsp; &nbsp; property OnIconMouseDown:TMouseEvent<br>&nbsp; &nbsp; &nbsp; read FOnIconMouseDown write FOnIconMouseDown;<br>&nbsp; &nbsp; property PopupMenu:TPopupMenu read FPopupMenu write FPopupMenu;<br>&nbsp; &nbsp; property PopupStyle:TPopupStyle read FPopupStyle<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; write FPopupStyle default [];<br>&nbsp;end;<br><br>procedure Register;<br><br>implementation<br><br>procedure Register;<br>begin<br>&nbsp; RegisterComponents('MyControl', [TNotifyIcon]);<br>end;<br><br>procedure TNotifyIcon.ShowIt(Accept:boolean);<br>begin<br>&nbsp; if &nbsp;Accept=true then ShowIcon<br>&nbsp; else HideIcon;<br>end;<br><br>procedure TNotifyIcon.Paint;<br>begin<br>if (csDesigning in ComponentState) then<br>begin<br>&nbsp;Width:=33;<br>&nbsp;Height:=33;<br>&nbsp;With Canvas do<br>&nbsp;begin<br>&nbsp; Brush.Color:=clInfoBk;<br>&nbsp; Ellipse(0,0,Self.Width,Self.Height);<br>&nbsp; Font.Color:=clBlue;<br>&nbsp; Brush.Style:=bsClear;<br>&nbsp; FloodFill(5,5,clInfoBk,fsBorder);<br>&nbsp; Brush.Color:=clInfoBk;<br>&nbsp; TextOut(3,Self.Height div 2-6,'Notify');<br>&nbsp;end<br>end;<br>end;<br><br>procedure TNotifyIcon.NotifyIconClick(var msg : TMessage);<br>&nbsp;var p:TPoint;<br>begin<br>&nbsp;try<br>&nbsp; &nbsp; &nbsp;case msg.LParam of<br>&nbsp; &nbsp; &nbsp; WM_LBUTTONDOWN:<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GetCursorPos(p);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if Left_Click in FPopupStyle then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SetForegroundWindow(ParentWindow);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FPopupMenu.Popup(p.x,p.y);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if Assigned(FOnIconMouseDown) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FOnIconMouseDown(Self,p.x,p.y,b_Left);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; WM_RBUTTONDOWN:<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GetCursorPos(p);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if Right_Click in &nbsp;FPopupStyle then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SetForegroundWindow(ParentWindow);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FPopupMenu.Popup(p.x,p.y);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if Assigned(FOnIconMouseDown) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FOnIconMouseDown(Self,p.x,p.y,b_Right);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; WM_LBUTTONDBLCLK:<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GetCursorPos(p);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if Left_DbClick in FPopupStyle then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SetForegroundWindow(ParentWindow);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FPopupMenu.Popup(p.x,p.y);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if Assigned(FOnIconDoubleClick) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FOnIconDoubleClick(Self,p.x,p.y,b_Left);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; WM_RBUTTONDBLCLk:<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GetCursorPos(p);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if Right_Click in FPopupStyle then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SetForegroundWindow(ParentWindow);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FPopupMenu.Popup(p.x,p.y);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if Assigned(FOnIconDoubleClick) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FOnIconDoubleClick(Self,p.x,p.y,b_Right);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp;except<br>&nbsp;end;<br>end;<br><br>function MAKELANGID(p, s:word):Cardinal;<br>begin<br>&nbsp; result:= (((s)shl 10) or(p));<br>end;<br><br>constructor TNotifyIcon.Create(AOwner: TComponent);<br>begin<br>try<br>&nbsp;inherited Create(AOwner);<br>&nbsp;FIcon:=TIcon.Create;<br>&nbsp;Height:=36;<br>&nbsp;Width:=36;<br>&nbsp;Visible:=false;<br>&nbsp;FTitle:='Welcome';<br>&nbsp;FIconVisible:=false;<br>&nbsp;//-------------set tray info---------<br>&nbsp;ParentWindow:=TWinControl(AOwner).Handle;<br>&nbsp;New(Fpda);<br>&nbsp; With FPda^ do<br>&nbsp; begin<br>&nbsp; &nbsp; uCallbackMessage:=WM_MY_Notify;<br>&nbsp; &nbsp; cbsize:=SizeOf(FPda^);<br>&nbsp; &nbsp; uID:=200;<br>&nbsp; &nbsp; wnd:=Handle;<br>&nbsp; &nbsp; uFlags:=NIF_ICON+NIF_Tip+NIF_MESSAGE;<br>&nbsp; &nbsp;end;<br><br>if (csDesigning in ComponentState) then<br>begin<br>&nbsp;if GetUserDefaultLCID = MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED) then<br>&nbsp; &nbsp; &nbsp; Application.MessageBox(<br>&nbsp; &nbsp; 'Write by 南昌大学 付昱纲'#13#13'E-mail:fyg@163.net'#13#13' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1998.8.17',<br>&nbsp; &nbsp; 'TNotifyIcon 控件 V 1.01',MB_OK+ MB_ICONINFORMATION)<br>&nbsp;else<br>&nbsp; &nbsp; &nbsp; Application.MessageBox(<br>&nbsp; &nbsp; 'Write by NanChang University &nbsp;FuYuGang'#13#13'E-mail:fyg@163.net'#13#13' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1998.8.17',<br>&nbsp; &nbsp; 'TNotifyIcon Component V 1.01',MB_OK+ MB_ICONINFORMATION);<br>end;<br>&nbsp;except<br>&nbsp; ShowMessage('TNotifyIcon Create error');<br>&nbsp;end;<br>end;<br><br>procedure TNotifyIcon.SetIcon(Icon:TICON);<br>begin<br>&nbsp;FIcon.Assign(Icon);<br>end;<br><br>procedure TNotifyIcon.ShowIcon;<br>begin<br>try<br>&nbsp;if FIcon.Handle=0 then<br>&nbsp;begin<br>&nbsp; &nbsp; Exit;<br>&nbsp;end;<br>&nbsp;if FIcon.Handle&lt;&gt;FPda^.hIcon then<br>&nbsp; &nbsp; &nbsp; &nbsp;HideIcon;<br>&nbsp;if FIconVisible=false then<br>&nbsp;begin<br>&nbsp; FPda^.hIcon:=FIcon.handle;<br>&nbsp; FIconVisible:=true;<br>&nbsp; &nbsp;Shell_NotifyIcon(NiM_ADD,FPda);<br>&nbsp;end;<br>except<br>&nbsp;ShowMessage('TNotifyIcon Show Error ');<br>end;<br>end;<br><br>procedure TNotifyIcon.HideIcon;<br>begin<br>try<br>&nbsp;if FIconVisible then<br>&nbsp;begin<br>&nbsp; FIconVisible:=false;<br>&nbsp; Shell_NotifyIcon(NiM_DELETE,FPda);<br>&nbsp;end;<br>except<br>&nbsp;ShowMessage('TNotifyIcon Hide Error');<br>end;<br>end;<br><br>procedure TNotifyIcon.SetTitle(NewTitle:string);<br>begin<br>&nbsp;FTitle:=NewTitle;<br>&nbsp;StrCopy(FPda^.szTip,PChar(FTitle));<br>&nbsp;if FIconVisible then<br>&nbsp;begin<br>&nbsp; &nbsp;HideIcon;<br>&nbsp; &nbsp;ShowIcon;<br>&nbsp;end;<br>end;<br><br>destructor TNotifyIcon.Destroy;<br>begin<br>try<br>&nbsp; HideIcon;<br>&nbsp; Dispose(FPda);<br>&nbsp; FIcon.Free;<br>&nbsp;inherited Destroy;<br>except<br>&nbsp;ShowMessage('TNotifyIcon Destroy Error');<br>end;<br>end;<br><br>procedure TNotifyIcon.ModifyIcon(NewIcon:TIcon);<br>begin<br>try<br>&nbsp;SetIcon(NewIcon);<br>&nbsp;FPda^.hIcon:=FIcon.handle;<br>&nbsp;if FIconVisible &nbsp;then<br>&nbsp; &nbsp;Shell_NotifyIcon(NiM_Modify,FPda);<br>except<br>&nbsp;ShowMessage('TNotifyIcon Modify Error');<br>end;<br>end;<br><br>function TNotifyIcon.IsShowing:boolean;<br>begin<br>&nbsp; Result:=FIconVisible;<br>end;<br><br>end.<br><br><br>--回复得分 0 --<br>Firing_sky 说得很详细了,但是要做通知栏的图标也很简单,应用几个函数(自己写),<br>InstallIcon,UnInstallIcon,IconClick.<br>下面是他们的简单实例:<br>安装图表:<br>procedure TForm1.InstallIcon;<br>var<br>&nbsp; &nbsp;CDIcon:TNotifyICondata;<br>begin<br>&nbsp; &nbsp;normalIcon:=TIcon.Create;<br>&nbsp; &nbsp;normalIcon:=form1.Icon;<br>&nbsp; &nbsp;CDIcon.cbSize:=sizeof(CDIcon);<br>&nbsp; &nbsp;CDIcon.Wnd:=handle;<br>&nbsp; &nbsp;CDIcon.uID:=ICON_ID;<br>&nbsp; &nbsp;CDIcon.uFlags:= NIF_ICON or NIF_MESSAGE or NIF_TIP;<br>&nbsp; &nbsp;CDIcon.uCallbackMessage:=MI_ICONEVENT;<br>&nbsp; &nbsp;CDIcon.hIcon:=normalicon.Handle;<br>&nbsp; &nbsp;CDIcon.szTip:='光驱控制';<br>&nbsp; &nbsp;Shell_NotifyIcon(NIM_ADD,@CDIcon);<br>end;<br><br>卸载图标:<br>procedure TForm1.UnInstallIcon;<br>var<br>&nbsp; &nbsp;CDIcon:TNotifyIconData;<br>begin<br>&nbsp; &nbsp;CDIcon.cbSize:=sizeof(CDIcon);<br>&nbsp; &nbsp;CDIcon.Wnd:=Handle;<br>&nbsp; &nbsp;CDIcon.uID:=ICON_ID;<br>&nbsp; &nbsp;Shell_NotifyIcon(NIM_DELETE,@CDIcon);<br>// &nbsp; normalIcon.Free;<br>end;<br><br>响应click事件:<br>procedure TForm1.IconOnClick(var message:TMessage);<br>var<br>&nbsp; p:TPoint;<br>begin<br>&nbsp; &nbsp;if &nbsp;(message.LParam=WM_LBUTTONDBLCLK) then<br>&nbsp; &nbsp; &nbsp; &nbsp;ShowWindow(handle,SW_SHOW);<br>&nbsp; &nbsp;if &nbsp;(message.LParam=WM_RBUTTONDOWN) then<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; GetCursorPos(p);<br>&nbsp; &nbsp; &nbsp; &nbsp; pop1.Popup(p.x,p.y);<br>&nbsp; &nbsp; &nbsp;end;<br>end;<br><br><br>
 
要写在类里面了
 
message WM_NID;<br>只能放在声明函数的地方,不能放在实现的地方.<br>例<br>&nbsp; TFrmMain = class(TForm)<br>&nbsp; private<br>&nbsp; &nbsp; procedure WMTimer (var Message: TMessage); message WM_TIMER;<br>&nbsp; end;<br><br>procedure TFrmMain.WMTimer(var Message: TMessage);<br>//定时消息<br>begin<br>&nbsp; case Message.wParam of<br>&nbsp; &nbsp; //.........<br>&nbsp; end;<br>end;<br>
 
多谢参与,可这样子运行不报错了,但却达不到目的了,消息处理函数要在后面加上消息的名称,这样当系统发来WM_NID消息时,就是自动触发<br>http://www.delphiboy.com/cgi-bin/doc/datacontent.php?no=336
 
procedure WMNID(var msg:TMessage); message WM_NID;<br>应该还有个类名吧<br>procedure TForm1.WMNID(var msg:TMessage); message WM_NID;<br>
 
后退
顶部