Главная страница
    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.063 c
15-1273756585
oldman
2010-05-13 17:16
2010.08.27
Визитная карточка Samsung - оружие самурая...


2-1267556430
AntonioBanderas
2010-03-02 22:00
2010.08.27
Доступ к данным БД Oracle


11-1220430650
Dodfr
2008-09-03 12:30
2010.08.27
strange form behavior for Form and TabControl


15-1270659190
Smile
2010-04-07 20:53
2010.08.27
Документ Word, его объем (размер) в байтах (килобайтах)?


2-1269648248
HF-Trade
2010-03-27 03:04
2010.08.27
IDHttp.Post Проблема с залогиниванием





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