Board index » delphi » Why won't my TPopupMenu go away?

Why won't my TPopupMenu go away?

I'm writing a small program which places an icon on the win95 tray
bar. This works fine, and I have trapped the right mouse click in
order to generate a TPopupmenu. The menu appears and operates as
expected, except that it won't go away until the focus returns to the
parent form, or an item is clicked. In other words when I click the
desktop, taskbar or another application the menu still sits there.
This presents a slight problem as I don't have a visible parent form!!

I've tried everything I can think of, from creating a new control, to
building the popup with API commands. Even the shareware popup
components on the web don't seem to work in this scenario. Can someone
please tell me how to do it?

Many thanks,

Iain

-----------------------------------------
Iain Magee
iainma...@enterprise.net
-----------------------------------------

 

Re:Why won't my TPopupMenu go away?


On Fri, 01 Nov 1996 18:23:52 GMT, iainma...@enterprise.net (Iain

Quote
Magee) wrote:

>I'm writing a small program which places an icon on the win95 tray
>bar. This works fine, and I have trapped the right mouse click in
>order to generate a TPopupmenu. The menu appears and operates as
>expected, except that it won't go away until the focus returns to the
>parent form, or an item is clicked. In other words when I click the
>desktop, taskbar or another application the menu still sits there.
>This presents a slight problem as I don't have a visible parent form!!

>I've tried everything I can think of, from creating a new control, to
>building the popup with API commands. Even the shareware popup
>components on the web don't seem to work in this scenario. Can someone
>please tell me how to do it?

I had the first problem at first but I found the solution.  Here is a
code snipit from one of my TrayIcon programs.

procedure TMainForm.TrayIcon1Click(Sender: TObject);
var
  MouseCo:TPoint;
begin
  GetCursorPos(MouseCo);
  SetForegroundWindow(Application.Handle);
  Application.ProcessMessages;
  PathMenu.Popup(Mouseco.X, Mouseco.Y);
end;

If I remember correctly the problem is that you have to call the
SetForgroundWindow and the ProcessMessages for it to work.  Then when
it loses its focus it kills the popupmenu for you.  If you want it to
disappear after a certian time period then that is a little different.

Let me know how it goes.

Chris

Other Threads