Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2008.11.30;
Скачать: CL | DM;

Вниз

Menu messages   Найти похожие ветки 

 
Jon ©   (2007-11-24 01:50) [0]

Why can I not receive messages for menu"s?
I want to trap and process WM_NC* messages for PMenu.

unit PopupEx;

interface

uses
 Windows, KOL, Messages;

type
 PPopupMenuEx = ^TPopupMenuEx;
 TPopupMenuEx = object(TControl)
 public
   destructor Destroy; virtual;
 end;

function NewPopupMenuEx(AParent: PControl; MaxCmdReserve: DWORD;
 const Template: array of PKOLChar; aOnMenuItem: TOnMenuItem): PPopupMenuEx;

implementation

function MenuWndProc(Sender: PControl; var Msg: TMsg; var Rslt: Integer): Boolean;
begin
 Result := False;
end;

function NewPopupMenuEx;
begin
 Result := PPopupMenuEx(NewMenu(AParent,MaxCmdReserve,Template,aOnMenuItem));
//  Result.AttachProc(@MenuWndProc);       // <------ ERROR!!
end;

destructor TPopupMenuEx.Destroy;
begin
 inherited;
end;

end.


If I uncomment the line with AttachProc, a runtime error is generated.


 
Vladimir Kladov ©   (2007-11-24 20:11) [1]

Self is absent. Event must be a method, not a regular procedure, so if you use regular procedure in place of the method of the object, you must add (the first) parameter, which is passed for objects" methods hidden.

A bit strange idea to inherit new successor from the TControl but name it as it would be a menu.


 
Jon ©   (2007-11-24 21:42) [2]

Thanks Vladimir.

> Self is absent.
I did not think that AttachProc needs self. I know that MakeMethod requires it.
Code changed to:
function MenuWndProc(Dummy: Pointer; Sender: PControl; var Msg: TMsg; var Rslt: Integer): Boolean;
but still the same error.


> A bit strange idea to inherit new successor from the TControl
> but name it as it would be a menu.

If I inherit from PMenu then I am unable to use AttachProc.

I can find no other way to receive WM_NC* messages for a menu.


 
Vladimir Kladov ©   (2007-11-24 22:19) [3]

Oh, beg oardon! It is my error, I forget it (far away i used it).

But your error seems in inheriting from incorrect domain. Your TPopupMenuEx is just declared as a successor of TControl, but really it is created calling NewMenu, so TMenu object is created (and even not your TPopupMenuEx). Typecast does not make it a TPopupMenuEx, it just instructs the compiler to think that it is of TPopupMenuEx type derived from TControl, but physically it is still a TMenu object. (Hm, yor destructor also will never be called, too).


 
Jon ©   (2007-11-24 23:17) [4]

It looks like I still have a lot to learn. Thank you for your words of wisdom.
I studied examples but obviously did not understand - I shall look again.
Do you recommend a better way to receive required messages?
I can find no OnMessage event for PMenu.


 
Vladimir Kladov ©   (2007-11-25 08:56) [5]

Menu is not a window in a common sense. It should not receive any messages itself. But the owning window can receive some messages like WM_ENTERMENULOOP, WM_EXITMENULOOP, WM_COMMAND, WM_MENUCOMMAND... All this is defined in MSDN very detailed.


 
Jon ©   (2007-11-26 02:51) [6]

Understood. I solved it using a hook. Your information helped steer me in the right direction. Thank you.



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

Текущий архив: 2008.11.30;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.012 c
15-1222494767
TUser
2008-09-27 09:52
2008.11.30
Макс, с днем тебя!!


15-1222712852
NailMan
2008-09-29 22:27
2008.11.30
Просьба имеющим Емул ака Осла


15-1222358569
Real
2008-09-25 20:02
2008.11.30
Почему Microsoft игнорирует Delphi?


2-1224231868
NieL
2008-10-17 12:24
2008.11.30
COM и 1С


2-1224769834
Piero
2008-10-23 17:50
2008.11.30
Двумерный массив в классе