1.创建一个应用程序,在主窗体上增加一个tpopupmenu组件。并为该弹出选单组件增加选单项exit,标题为“退出”。
2.在uses中添加shellapi,因为在系统状态栏中增加图标时需调用shellapi中的函数shell_notifyicona。 该函数需要两个参数,其中一个是tnotifyicondataa结构,需在主窗体中增加tnotifyicondataa类型的全局变量ntida。
3.定义消息mousemsg,并编写主窗体的mousemessage消息处理函数,此函数说明在图标上用鼠标左键单击时,会打开应用程序窗口;用鼠标右键单击时,会弹出一个选单。
下面给出步骤2和3的实现代码:
unit unit1;
interface
uses
windows, messages, sysutils, classes, graphics, controls, forms, dialogs,
stdctrls, extctrls, menus, shellapi;
const
mousemsg = wm_user + 1; //自定义消息,用于处理用户在图标上点击鼠标的事件
iid = 100; //用户自定义数值,在tnotifyicondataa类型全局变量ntida中使用
type
tform1 = class(tform)
......
private
//自定义消息处理函数,处理鼠标点击图标事件
procedure mousemessage(var message: tmessage); message mousemsg;
public
{ public declarations }
end;
var
form1: tform1;
ntida: tnotifyicondataa;
//用于增加和删除系统状态图标
implementation
{$r .dfm}
procedure tform1.mousemessage(var message: tmessage);
var
mousept: tpoint; //鼠标点击位置
begin
inherited;
if message.lparam = wm_rbuttonup then begin //用鼠标右键点击图标
getcursorpos(mousept); //获取光标位置
popupmenu1.popup(mousept.x, mousept.y);
//在光标位置弹出选单
end;
if message.lparam = wm_lbuttonup then begin //用鼠标左键点击图标
//显示应用程序窗口
showwindow(handle, sw_show);
//在任务栏上显示应用程序窗口
showwindow(application.handle, sw_show);
setwindowlong(application.handle, gwl_exstyle,
not (getwindowlong(application.handle, gwl_exstyle)
or ws_ex_toolwindow and not ws_ex_appwindow));
end;
message.result := 0;
end
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器