Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Основная";
Текущий архив: 2004.09.26;
Скачать: [xml.tar.bz2];

Вниз

Как узнать, что PopupMenu закрылся?   Найти похожие ветки 

 
Layner ©   (2004-09-09 09:36) [0]

То, что появился, без проблем
procedure Tfm.PopupMenu1(Sender: TObject);
...

Заранее спасибо.


 
Layner ©   (2004-09-09 09:37) [1]

procedure Tfm.PopupMenu1Popup(Sender: TObject);
...

Т.е. так :(


 
Ломброзо ©   (2004-09-09 10:56) [2]

имхо никак нельзя


 
Layner ©   (2004-09-09 11:01) [3]

Совсем, совсем? :)


 
TUser ©   (2004-09-09 11:07) [4]

Тут в соседней ветке обсуждается wm_cancelmode. Может переписать обработчик сабжа и будет хорошо?


 
TUser ©   (2004-09-09 11:22) [5]

Нет, не будет


 
easy ©   (2004-09-09 12:11) [6]

unit ExPopupList;

interface

uses Controls;

const
 CM_MENUCLOSED = CM_BASE - 1;

implementation

uses Messages, Forms, Menus;

Type
 TExPopupList = class( TPopupList )
 protected
   procedure WndProc(var Message: TMessage); override;
 end;

{ TMyPopupList }

procedure TExPopupList.WndProc(var Message: TMessage);
 Procedure Send( msg: Integer );
 Begin
   If Assigned( Screen.Activeform ) Then
     Screen.ActiveForm.Perform( msg, Message.wparam, Message.lparam );
 End;
begin
 Case message.Msg Of
   WM_MENUSELECT :
     With TWMMenuSelect( Message ) Do
       If (Menuflag = $FFFF) and (Menu = 0) Then
         Send( CM_MENUCLOSED );
 End; { Case }
 inherited;
end;

Initialization
 Popuplist.Free;
 PopupList:= TExPopupList.Create;
 // Note: will be freed by Finalization section of Menus unit.
end.


//*****************************

unit Unit1;

interface

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

type
 TForm1 = class(TForm)
   PopupMenu1: TPopupMenu;
   Memo1: TMemo;
   File1: TMenuItem;
 private
 Procedure CMMenuClosed( var msg: TMessage ); message CM_MENUCLOSED;
   { Private declarations }
 public
   { Public declarations }
 end;

var
 Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.CMMenuClosed(var msg: TMessage);
begin
memo1.lines.add( "Menu closed" );
end;

end.


 
Layner ©   (2004-09-09 12:53) [7]

easy ©   (09.09.04 12:11)
Спасибо!!! Сейчас опробую.


 
Layner ©   (2004-09-09 13:16) [8]

То что выше, отлично! только один минус, при первом вызове PopupMenu событие CMMenuClosed не наступает, а при 2м, и следующих работает как часы.


 
Ломброзо ©   (2004-09-09 13:24) [9]

> If (Menuflag = $FFFF)

Так нечестно! :) Это не документировано!


 
DVM ©   (2004-09-09 13:27) [10]

А что, WM_EXITMENULOOP не подходит?


 
easy ©   (2004-09-09 13:48) [11]


> Ломброзо ©   (09.09.04 13:24) [9]

почему?.. =(

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardacce lerators/keyboardacceleratorreference/keyboardacceleratormessages/wm_menuselect.asp


 
Layner ©   (2004-09-09 14:10) [12]

Ещё опробовал вариант с сообщением WM_EXITMENULOOP
 
private
  procedure PopNo(var msg: TMessage); message WM_EXITMENULOOP;

..........

procedure Tfrash.PopNo(var msg: TMessage); //может что не так делаю :(
begin
 if msg.Msg = WM_EXITMENULOOP then e2.Color:=RGB(242,150,150);  //вернуть к старому цвету
end;

..........

procedure Tfrash.PopupMenu1Popup(Sender: TObject);
begin
  e2.Color:=RGB(242,111,111);  //на момент открытого PopupMenu1 яркий цвет
end;


 
DVM ©   (2004-09-09 14:12) [13]


> Layner ©   (09.09.04 14:10) [12]

а оно приходит вообще окну?


 
Layner ©   (2004-09-09 15:48) [14]

В смысле? С сообщениями я не особо :(


 
easy ©   (2004-09-09 17:38) [15]

In article <MPG.1256aa814a90bf65989689@forums.inprise.com>, Peter
Aschbacher wrote:
> OK, so how can I detect when the menu is closed, if the user closes the
> menu not by clicking on the menu but somewhere else?
>

Not easily, unfortunately. Windows sends a WM_EXITMENULOOP message and a
WM_MENUSELECT message (with some specific parameter values) to the window
owning the menu (which for TPopupMenus is a tool window maintained by the
Popuplist object in the Menus unit). None of these allows you to detect
*which* menu has closed and how it was closed. And it is not easy to get
at these messages in the first place. In Delphi 5 we finally have a decent
chance since PopupMenu is now published in the Interface of the Menus
unit. So we can replace it, but this has to be done at startup, before any
TPopupMenu instances have been created. I post a unit below which replaces
it with a TPopuplist derivative which echos the critical messages to the
currently active form, so they can be trapped there in message handlers.
An example form (popupmenu1 connected to edit1.popupmenu) is also given.

This requires Delphi 5!

--------------
unit ExPopupList;

interface

uses Controls;

const
 CM_MENUCLOSED = CM_BASE - 1;
 CM_ENTERMENULOOP = CM_BASE - 2;
 CM_EXITMENULOOP = CM_BASE - 3;

implementation

uses Messages, Forms, Menus;

Type
 TExPopupList = class( TPopupList )
 protected
   procedure WndProc(var Message: TMessage); override;
 end;

{ TMyPopupList }

procedure TExPopupList.WndProc(var Message: TMessage);
Procedure Send( msg: Integer );
Begin
 If Assigned( Screen.Activeform ) Then
   Screen.ActiveForm.Perform( msg, Message.wparam,Message.lparam );
End;
begin
Case message.Msg Of
 WM_ENTERMENULOOP: Send( CM_ENTERMENULOOP );
 WM_EXITMENULOOP : Send( CM_EXITMENULOOP );
 WM_MENUSELECT :
   With TWMMenuSelect( Message ) Do
     If (Menuflag = $FFFF) and (Menu = 0) Then
       Send( CM_MENUCLOSED );
 End; { Case }
inherited;
end;

Initialization
 Popuplist.Free;
 PopupList:= TExPopupList.Create;
// Note: will be freed by Finalization section of Menus unit.
end.

----------
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
PopupMenu1: TPopupMenu;
PasteSpecial1: TMenuItem;
Paste1: TMenuItem;
Copy1: TMenuItem;
Cut1: TMenuItem;
Undo1: TMenuItem;
Memo1: TMemo;
private
{ Private declarations }
Procedure CMEnterMenuLoop( var msg: TMessage );
 message CM_ENTERMENULOOP;
Procedure CMExitMenuLoop( var msg: TMessage );
 message CM_EXITMENULOOP;
Procedure CMMenuClosed( var msg: TMessage );
 message CM_MENUCLOSED;
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.DFM}

{ TForm1 }

procedure TForm1.CMEnterMenuLoop(var msg: TMessage);
begin
 memo1.lines.add( "Enter menu loop" );
end;

procedure TForm1.CMExitMenuLoop(var msg: TMessage);
begin
 memo1.lines.add( "Exit menu loop" );
end;

procedure TForm1.CMMenuClosed(var msg: TMessage);
begin
 memo1.lines.add( "Menu closed" );
end;

end.


Peter Below (TeamB) 100113.1101@compuserve.com)
No e-mail responses, please, unless explicitly requested!



Страницы: 1 вся ветка

Форум: "Основная";
Текущий архив: 2004.09.26;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.49 MB
Время: 0.064 c
1-1094625734
kwSergio
2004-09-08 10:42
2004.09.26
совместимость Delphi и Builder


4-1092715743
DION
2004-08-17 08:09
2004.09.26
А хто знает, как определить производителя монитора....


1-1094983725
raiks
2004-09-12 14:08
2004.09.26
Ошибка при использовании функции StrToFloat


1-1095072110
limon_
2004-09-13 14:41
2004.09.26
поиск в combobox


1-1095155759
Kovsh
2004-09-14 13:55
2004.09.26
Как изменить цвет выделения в StringGrids





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский