Solved

Taskbar icon’s popup menu

Posted on 1998-09-18
3
400 Views
Last Modified: 2010-04-06
 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_RBUTTONDOWN then
    begin
      GetCursorPos(Pos);
      Top:=-10000;
      if not(Visible) then Show;
      Application.ProcessMessages;
      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?
0
Comment
Question by:zoltan082098
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
Madshi earned 50 total points
ID: 1340100
zoltan,

write "SetForegroundWindow(Application.handle)" instead of "if not visible then Show" and it will work.

Regards, Madshi.
0
 

Author Comment

by:zoltan082098
ID: 1340101
Thank you, Madshi. I knew the solution must be simple.
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.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);

It doesn’t seems to be very elegant, but works.

Regards, Zoltan
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1340102
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
System restore point 4 91
find a node in VST 2 63
How to open a new windows chrome resized and disabled the toolbar? 3 80
can't find the executable in Simulator 1 80
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now