[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 354
  • Last Modified:

About Popup Menu

How to programmatically let a popup menu "disappear" while it has been popupped?
0
eYes
Asked:
eYes
  • 4
  • 3
1 Solution
 
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
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
 
intheCommented:
just because you dont like the answer doesnt justify giving a bad grade !!
0
 
eYesAuthor Commented:
o, sorry. But why?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now