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

Вниз

Как отловить нажатие кнопки во время появления PopupMenu   Найти похожие ветки 

 
allrussia   (2010-03-19 17:29) [0]

При нажатии на  Esc поп-ап меню закрывается, а нужно отловить это сообщение.

KeyPreview не помогает.Kak u Вообще form.onkeydown.


 
oldman ©   (2010-03-19 18:59) [1]


> Kak u Вообще form.onkeydown


Ты уверен, что popupmenu входит в эту "группу событий"?


 
Leonid Troyanovsky ©   (2010-03-20 10:34) [2]


> allrussia   (19.03.10 17:29)  

> При нажатии на  Esc поп-ап меню закрывается, а нужно отловить
> это сообщение.

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)

--
Regards, LVT.


 
allrussia   (2010-03-21 02:25) [3]

Leonid Troyanovsky
спасибо
я правда нашел уже другой метод,
но попробую и этот



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

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

Наверх





Память: 0.46 MB
Время: 0.07 c
2-1269057230
Delphist2
2010-03-20 06:53
2010.08.27
бинарный поиск в listbox


15-1265186248
Mike Kouzmine
2010-02-03 11:37
2010.08.27
Глобальное Затемнение


2-1268397398
timekiller
2010-03-12 15:36
2010.08.27
Интерактивный генератор текстов


15-1268838645
Дмитрий
2010-03-17 18:10
2010.08.27
IbExpert


6-1223267358
JohnKorsh
2008-10-06 08:29
2010.08.27
Индикация наличия пакета.





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
Английский Французский Немецкий Итальянский Португальский Русский Испанский