Solved

PopupMenu + ShellNotifyIcon

Posted on 1998-12-19
4
216 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
No, I don't think so...  :-)

Thanx for the points.

Regards... Madshi.

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

12 Experts available now in Live!

Get 1:1 Help Now