富翁们,帮帮忙吧(50分)

  • 主题发起人 wubo830814
  • 开始时间
W

wubo830814

Unregistered / Unconfirmed
GUEST, unregistred user!
小弟有两个问题
1.我的程序放到托盘中,右击后弹出PopupMenu1,我再把鼠标移动到别的地方,PopupMenu1为什么还在那里,怎么才能让它关掉
2.程序在托盘中,我如果再运行exe文件,怎样才能把已经运行的程序调出来。
谢谢!
 
解决第一个问题:
uCallbackMessage 消息的处理中要增加一个函数处理popupmenu:
SetForegroundWindow(Form1.Handle);
设置form1 为前台窗口(即当前用户当前工作的窗口),以便弹出菜单后,在别的地方单击能使菜单消失。
解决第二个问题:
你在项目的dpr文件中修改一下,可以使用findWindow函数判断程序是否在运行,若在运行则显示当前在运行的程序。
hwnd:= FindWindow(nil,[你的程序窗体名称]);
if hwnd<>nil then
ShowWindow(hwnd, SW_SHOW)
else
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;

end;
 
多谢,我先试试看
 
const
WM_TrayIcon = WM_USER + 1234;

procedure TrayIconMessage(var Msg: TMessage);
message WM_TrayIcon;
procedure TMainForm.TrayIconMessage(var Msg: TMessage);
var
cursorpos: TPoint;
begin
//点ICO右键 和左键
if (Msg.LParam = WM_RBUTTONDOWN) then
begin
SetForegroundWindow(self.Handle);
getcursorpos(cursorpos);
popupmenu.Popup(cursorpos.x, cursorpos.y);
end;

if (Msg.LParam = WM_LBUTTONDBLCLK) and Assigned(MainForm) then
begin
//显示到最前
SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
MainForm.WindowState := wsNormal;
//恢复显示
MainForm.Show;
end
else
exit;
end;

参考该一下吧!
 
谢谢二位仁兄,第一个问题解决了
但是第二个问题还是不行,
 
大家都走了吗
还有在线的吗
 
没有人再帮帮忙了吗
 
多人接受答案了。
 

Similar threads

D
回复
0
查看
739
DelphiTeacher的专栏
D
D
回复
0
查看
742
DelphiTeacher的专栏
D
D
回复
0
查看
737
DelphiTeacher的专栏
D
D
回复
0
查看
681
DelphiTeacher的专栏
D
顶部