Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

PopupMenu + ShellNotifyIcon

Posted on 1998-12-19
4
219 Views
Last Modified: 2010-04-04
Me again...
Now I use a TShellNotifyIcon.
some code:

private
  procedure WndProc ( var Msg: TMessage ); override;
end;

procedure TfrmMain.WndProc ( var Msg: TMessage );
var       pos: TPoint;
begin
     case Msg.Msg of
     WM_User + 1 :
        case Msg.LParam of
             WM_RBUTTONDOWN:
                begin
                     GetCursorPos ( pos );
                     mnuMain.Popup ( pos.x, pos.y );
                end;
             WM_LBUTTONDOWN:
                begin
                    //still to do
                end;
        end;
     end;
     inherited;
end;

everything's working fine, except to the fact, that when the mnuMain.Popup function is called, it doesn't take it back. I mean: when you open a popup-menu by a right-click onto an Icon in the Shell_NotificationArea and then click onto the Desktop or onto the window of another app, the popup-menu disapears. Well, my popup window does not disapear. Why ?
I did already try

begin
  Application.ProcessMessages;
  ShowWindow ( Application.Handle, SW_HIDE );
end.

at the end of my code. Still, the popup-menu stays visible.
Well, at least until you move the cursor over it again. If you clicked onto the desktop before ( lost focus ) and then move the cursor to the still visible popup-menu, then it disapears.
0
Comment
Question by:Oli2
  • 2
  • 2
4 Comments
 
LVL 1

Author Comment

by:Oli2
ID: 1351990
okay, I figured something out:

I placed a TTimer with TTimer.Interval := 10 onto my form and the TTimer.OnTimer event:

procedure TfrmMain.Timer.OnTimer ( Sender: TObject );
begin
  Application.ProcessMessages;
end;

it works now.
Anybody better ideas ??

Greetings, Oli
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1351991
Oli,

use these two functions before showing the popup menu:

SetForegroundWindow(Application.Handle);
Application.ProcessMessages;

Hmmm. This works under win95. Have not tested it with win98. Win98 behaves a little bit different when calling SetForegroundWindow. Please just try it.

Regards... Madshi.
0
 
LVL 1

Author Comment

by:Oli2
ID: 1351992
Madshi => cool, it works perfect, at least with Win95. I'll test it with Win98 some other time, that's not so important.
How about setting your comment to an answer?
Or do you think, you already have enough points ?  ;-)

Gruß, Oli
0
 
LVL 20

Accepted Solution

by:
Madshi earned 150 total points
ID: 1351993
No, I don't think so...  :-)

Thanx for the points.

Regards... Madshi.

P.S: Und noch einer aus Deutschland...
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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