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

Вниз

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 вся ветка

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

Наверх





Память: 0.45 MB
Время: 0.008 c
15-1222602793
Дмитрий С
2008-09-28 15:53
2008.11.30
Молчаливый OleVariant


2-1224238980
Серёга
2008-10-17 14:23
2008.11.30
не удается вызвать форму из dll(KOL MCK)


2-1224606132
Tonick2001
2008-10-21 20:22
2008.11.30
Свойство CaretPos


3-1210840647
npr2
2008-05-15 12:37
2008.11.30
ведение справочника для 2-х баз


2-1224507050
Игорь
2008-10-20 16:50
2008.11.30
Как определить заглавная буква или нет





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