zoltan082098
asked on
Taskbar icon’s popup menu
My application has an icon in the Taskbar Notification Area (but has no visible windows!). Clicking on this icon, a popup menu appears, which has a submenu with dinamically created items. There are several problems:
1. Sometimes, clicking on the icon the popup menu appears but disappears imediatelly.
2. Clicking out of the popup menu, sometimes the popup menu doesn’t disappear.
3. Clicking on the dinamically created submenu items, a protection fault error occurs.
I realized that the first two problems are in connection with the focused window, so I tried to resolve them by showing the main form while the popup menu appears (note that the form will not appear on the screen, because its Top property will be -10000):
procedure TFMail.OnNotifyIcon(var Message: TMessage);
var Pos:TPoint;
begin
if Message.LParam=WM_RBUTTOND OWN then
begin
GetCursorPos(Pos);
Top:=-10000;
if not(Visible) then Show;
Application.ProcessMessage s;
Popupmenu1.Popup(Pos.X,Pos .Y);
Hide;
end;
end;
Suprizing, this method resolved the protection fault problem, but if I run the program as an exe file (not from Delphi), the first two problems appears.
Has anybody an idea why the protection fault occurs, and how can I resolve this problem in an elegant way?
1. Sometimes, clicking on the icon the popup menu appears but disappears imediatelly.
2. Clicking out of the popup menu, sometimes the popup menu doesn’t disappear.
3. Clicking on the dinamically created submenu items, a protection fault error occurs.
I realized that the first two problems are in connection with the focused window, so I tried to resolve them by showing the main form while the popup menu appears (note that the form will not appear on the screen, because its Top property will be -10000):
procedure TFMail.OnNotifyIcon(var Message: TMessage);
var Pos:TPoint;
begin
if Message.LParam=WM_RBUTTOND
begin
GetCursorPos(Pos);
Top:=-10000;
if not(Visible) then Show;
Application.ProcessMessage
Popupmenu1.Popup(Pos.X,Pos
Hide;
end;
end;
Suprizing, this method resolved the protection fault problem, but if I run the program as an exe file (not from Delphi), the first two problems appears.
Has anybody an idea why the protection fault occurs, and how can I resolve this problem in an elegant way?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
zoltan,
I don't understand why the protection fault occurs/occured. I've just created a mini project that does nothing but show a taskbar icon and open a popup menu. No exceptions. Everything is fine.
Please make a little demo project and post it here with complete sources. If it is too long for that, send it to "Mathias.Rauen@gmx.de".
Then I'll see if I find the problem.
I'm not sure about your taskbar button problem. You said you have no window, only a taskbar icon. OK. Then you said when clicking on the taskbar icon you open a form. How do you do that? I've tested ShowMessage and that stuff and there's still no taskbar button...
Regards, Madshi.
I don't understand why the protection fault occurs/occured. I've just created a mini project that does nothing but show a taskbar icon and open a popup menu. No exceptions. Everything is fine.
Please make a little demo project and post it here with complete sources. If it is too long for that, send it to "Mathias.Rauen@gmx.de".
Then I'll see if I find the problem.
I'm not sure about your taskbar button problem. You said you have no window, only a taskbar icon. OK. Then you said when clicking on the taskbar icon you open a form. How do you do that? I've tested ShowMessage and that stuff and there's still no taskbar button...
Regards, Madshi.
ASKER
Do you have an idea why the protection fault occured?
What do you think about my last question (Taskbar button problem)? You said that in Delphi help it is something about it, and I didn’t find anything (I have Delphi 3). I resolved the problem by setting the application’s window style:
SetWindowLong(Application.
It doesn’t seems to be very elegant, but works.
Regards, Zoltan