请问如何把运行程序,以图标形式最小化在右下角(即像音量图标和输入法图标一样?如何右击出现菜单?(200分)

  • 主题发起人 主题发起人 zjhyxjs
  • 开始时间 开始时间
Z

zjhyxjs

Unregistered / Unconfirmed
GUEST, unregistred user!
我是一个初学者,<br>请问如何把运行程序,以图标形式最小化在右下角(即像音量图标和输入法图标一样)?<br><br>如何右击此处出现菜单?<br>最好能赠以源程序!
 
你能不能查以前的代码?<br>procedure TMainForm.NotifyIcon(var TM : TMessage); &nbsp; //响应鼠标消息<br>var<br>&nbsp; AC : LongInt;<br>&nbsp; CP : TPoint;<br>begin<br>&nbsp; &nbsp;AC:=TM.LParam;<br>&nbsp; &nbsp;if AC=WM_LBUTTONDBLCLK then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; MainForm.Show;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp;if AC=WM_RBUTTONDOWN then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if MainForm.Visible then<br>&nbsp; &nbsp; &nbsp; &nbsp; exit;<br>&nbsp; &nbsp; &nbsp; GetCursorPos (CP);<br><br>&nbsp; &nbsp; &nbsp; PopupMenu1.Popup (CP.X, CP.Y);<br>&nbsp; &nbsp; end;<br>end;<br><br>procedure AddTrayIcon (ID : integer; Hint : string; Icon : TIcon; hWnd : LongInt; CallBack : LongInt);<br>var<br>&nbsp; MC : TNotifyIconData;<br>begin<br>&nbsp; with MC do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;cbSize := sizeof(TNotifyIconData);<br>&nbsp; &nbsp; &nbsp;Wnd := hWnd;<br>&nbsp; &nbsp; &nbsp;uID := ID;<br>&nbsp; &nbsp; &nbsp;uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;<br>&nbsp; &nbsp; &nbsp;uCallbackMessage := CallBack;<br>&nbsp; &nbsp; &nbsp;hIcon := Icon.Handle;<br>&nbsp; &nbsp; &nbsp;if (length(hint)&gt;0) then<br>&nbsp; &nbsp; &nbsp; &nbsp;StrLCopy(szTip, PChar(hint), 63)<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp;szTip[0] := #0;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp;if Shell_NotifyIcon(NIM_ADD, @MC) then<br>&nbsp; &nbsp; SetWindowLong(Application.Handle, GWL_EXSTYLE,<br>&nbsp; &nbsp; &nbsp;GetWindowLong(Application.Handle, GWL_EXSTYLE) or &nbsp;WS_DLGFRAME and not WS_EX_APPWINDOW);<br>end;<br><br>procedure DestroyTrayIcon (ID : integer; hWnd : LongInt);<br>var<br>&nbsp; MC : TNotifyIconData;<br>begin<br>&nbsp; &nbsp;with MC do<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; cbSize := sizeof(TNotifyIconData);<br>&nbsp; &nbsp; &nbsp; Wnd := hWnd;<br>&nbsp; &nbsp; &nbsp; uID := ID;<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp;Shell_NotifyIcon (NIM_DELETE, @MC);<br>end;<br><br>AddTrayIcon (1,'IP监视器',Application.Icon,MainForm.Handle,WM_NOTIFYMSG);<br>DestroyTrayIcon (1,MainForm.Handle);
 
程序缩小为任务条右下角的小图标<br><br><br>某些程序运行启动后并不出现在任务条中,而是缩小为任务条右下角的一个小图标,当鼠标移到这个小图标上时会出现一些提示信息、单击该小图标会执行一些特定的操作。便如任务条右下角的小喇叭图标,单击它会弹出一个简单的音量控制条,双击会启动另一个更大的音量控制程序。<br><br>在Shell32.DLL动态链接库中包括一个函数Shell_NotifyIconA()可通知Windows在任务条右下角加入一个小图标,可惜该函数的详细说明未收入Delphi的帮助文档中,下面以一个简单的实例来说明如果使用该函数。<br><br><br>unit Unit1;<br><br><br>interface<br><br><br>{ 记住在uses部分中包括 ShellAPI}<br><br>uses<br><br>Windows<br><br>Messages<br><br>SysUtils<br><br>Classes<br><br>Graphics<br><br>Controls<br><br>Forms<br><br>Dialogs<br><br>ShellAPI<br><br>StdCtrls;<br><br><br>{自定义消息,当小图标捕捉到鼠标事件时Windows向回调函数发送此消息}<br><br>const MY_MESSAGE = WM_USER + 100;<br><br><br>type<br><br>TForm1 = class(TForm)<br><br>procedure FormCreate(Sender: TObject);<br><br>procedure FormClose(Sender: TObject; var Action: TCloseAction);<br><br>procedure FormPaint(Sender: TObject);<br><br>private<br><br>procedure OnIconNotify(var Message: TMessage);<br><br>message MY_MESSAGE;<br><br>public<br><br>{ Public declarations }<br><br>end;<br><br><br>var<br><br>Form1: TForm1;<br><br><br>implementation<br><br><br>{$R *.DFM}<br><br><br><br>{当小图标捕捉到鼠标事件时进入此过程}<br><br>procedure TForm1.OnIconNotify(var Message: TMessage);<br><br>const<br><br>Busy: Boolean = false;<br><br>begin<br><br>if not Busy then begin<br><br>Busy := true;<br><br>if Message.LParam=WM_LBUTTONDOWN then<br><br>if Application.MessageBox('Are you sure'<br><br><br>'Exit'<br><br>MB_YESNO)=IDYES then Close;<br><br>Busy := false;<br><br>end;<br><br>end;<br><br><br>{当主Form建立时通知Windows加入小图标}<br><br>procedure TForm1.FormCreate(Sender: TObject);<br><br>var<br><br>nid: TNotifyIconData;<br><br>begin<br><br>nid.cbSize := sizeof(nid); // nid变量的字节数<br><br>nid.Wnd := Handle; // 主窗口句柄<br><br>nid.uID := -1; // 内部标识,可设为任意数<br><br>nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指?<br><br>nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指?<br><br><br>nid.szTip := 'This is a test application'; // 提示字符串<br><br>nid.uCallbackMessage := MY_MESSAGE; // 回调函数消息<br><br>nid.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; // 指明哪些字段有?<br><br><br>if not Shell_NotifyIcon(NIM_ADD<br><br>@nid) then begin<br><br>ShowMessage('Failed!');<br><br>Application.Terminate;<br><br>end;<br><br>{将程序的窗口样式设为TOOL窗口,可避免在任务条上出现}<br><br>SetWindowLong(Application.Handle<br><br>GWL_EXSTYLE<br><br>WS_EX_TOOLWINDOW);<br><br>end;<br><br><br>{程序被关闭时通知Windows去掉小图标}<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br><br>var<br><br>nid: TNotifyIconData;<br><br>begin<br><br>nid.cbSize := sizeof(nid); // nid变量的字节数<br><br>nid.cbSize := sizeof(nid); // nid变量的字节数<br><br>nid.uID := -1; //内部标识,与加入小图标时的数一致<br><br>nid.Wnd := Handle; //主窗口句柄<br><br>Shell_NotifyIcon(NIM_DELETE<br><br>@nid); //去掉小图标<br><br>Shell_NotifyIcon(NIM_DELETE<br><br>@nid); //去掉小图标<br><br>end;<br><br><br>{主窗口初始化完毕并显示时将激活Paint重画事件,此时将主窗口隐藏}<br><br>procedure TForm1.FormPaint(Sender: TObject);<br><br>begin<br><br>Hide;<br><br>end;<br><br><br>end.<br><br><br><br><br>上例中将程序的图标放在任务条右下角,然后隐藏自身,当用户移动鼠标至该图标上时会看到提示字符串,如果单击该图标会出现一个对话框,选择Yes退出程序并清除小图标。<br>
 
//给你个例子吧<br><br>在uses中加入shellAPI<br>const MY_MESSAGE = WM_USER + 100;<br>procedure OnIconNotify(var Message: TMessage); &nbsp;message MY_MESSAGE;<br><br>procedure TForm1.OnIconNotify(var Message: TMessage);<br>const<br>&nbsp; Busy: Boolean = false;<br>begin<br>&nbsp; if not Busy then begin<br>&nbsp; &nbsp; Busy := true;<br>&nbsp; &nbsp; if Message.LParam=WM_LBUTTONDOWN then<br>&nbsp; &nbsp; &nbsp; if Application.MessageBox('Are you sure',<br>&nbsp; &nbsp; &nbsp; &nbsp; 'Exit', MB_YESNO)=IDYES then Close;<br>&nbsp; &nbsp; &nbsp; &nbsp; Busy := false;<br>&nbsp; &nbsp;end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>var <br>&nbsp; nid: TNotifyIconData;<br>begin<br>&nbsp; nid.cbSize := sizeof(nid); // nid变量的字节数<br>&nbsp; nid.Wnd := Handle; // 主窗口句柄<br>&nbsp; nid.uID := 1; // 内部标识,可设为任意数<br>&nbsp; nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指?nbsp;<br>&nbsp; nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指?nbsp;<br><br>&nbsp; nid.szTip := 'This is a test application'; // 提示字符串<br>&nbsp; nid.uCallbackMessage := MY_MESSAGE; // 回调函数消息<br>&nbsp; nid.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; // 指明哪些字段有?nbsp;<br>&nbsp;<br>&nbsp; if not Shell_NotifyIcon(NIM_ADD, @nid) then<br>&nbsp; begin<br>&nbsp; showmessage('failed');<br>&nbsp; Application.Terminate;<br>&nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {将程序的窗口样式设为TOOL窗口,可避免在任务条上出现} <br>&nbsp; SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);<br>end; <br><br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>var <br>&nbsp; nid: TNotifyIconData;<br>begin<br>&nbsp; nid.cbSize := sizeof(nid); // nid变量的字节数<br>&nbsp; nid.uID := 1; //内部标识,与加入小图标时的数一致<br>&nbsp; nid.Wnd := Handle; //主窗口句柄<br>&nbsp; Shell_NotifyIcon(NIM_DELETE, @nid); //去掉小图标<br>&nbsp; Shell_NotifyIcon(NIM_DELETE, @nid); //去掉小图标<br>end;<br><br>如果嫌麻烦,用控件,FormEx就是很好东东.<br><br>
 
我有一个例子,你要得话发邮件给我。<br>superhx2000@163.net
 
上述几个答案都可以,这个问题可以结束了,200分是不是高了些?
 
谢谢大家的帮助!由于初次进入论坛,刚学语言,可能分值设的不太理想!<br>大家都讲得很详细,由于halps 送来了源程序,所以我主要把分值给了他!
 
后退
顶部