About Popup Menu

How to programmatically let a popup menu "disappear" while it has been popupped?
eYesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

intheCommented:
hi,
from my paq:

"
Just before you call PopupMenu.Popup, make an API call:
 
      SetForegroundWindow(Handle);
 
This will force your application to get focus and, upon losing the focus (by clicking on the desktop or your app), the popup will close correctly. "
 
Regards Barry
0
eYesAuthor Commented:
i mean the popup menu has popuped by user right-clicking on form. now i need programmatically close this popup menu,
neednt user make any mouse clicking.
0
intheCommented:
ok,
try this demo:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Menus, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    PopupMenu1: TPopupMenu;
    hello1: TMenuItem;
    Timer1: TTimer;
    Label1: TLabel;
    procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure hello1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
p : tpoint;
  begin
  getcursorpos(p);
if (button = mbright) then
begin
timer1.Interval := 3000;
timer1.enabled:=true;
popupmenu1.popup(p.x,p.y);
application.processmessages;
end;
end;

procedure TForm1.hello1Click(Sender: TObject);
begin
showmessage('hello');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Timer1.Enabled := false;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
VAR
H : HWND;
begin
timer1.enabled := false;
h:=getnextWindow(handle,GW_HWNDNEXT);
{popup goes away thinking a selection has been made}
Setforegroundwindow(h);
end;

end.


Regards Barry

0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

eYesAuthor Commented:
have to change focus?
0
intheCommented:
yes have to either select and click something or change the focus otherwise menu just wait forever for a selection,there isnt another way apart from destroy menu and recreate it in code..
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
intheCommented:
just because you dont like the answer doesnt justify giving a bad grade !!
0
eYesAuthor Commented:
o, sorry. But why?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.