Board index » delphi » Message handler for dynamic messages ?

Message handler for dynamic messages ?

Here is a neat little question.

How do I write a Windows (NOT a component !) message handler, that
responds only to a message with a specific ID. A dynamic ID that is ?

With dynamic, I think of  a registered message created through a call to
RegisterWindowMessage.

After the call, the ID is unique for as long Windows is running, but the
normal way to create an individual handler is something like :
(Delphi pascal used)

type
  something = someting_else
     ----
protected
     procedure SpecialMessageHandler(var Msg : TMessage); message
Constant_ID;
end;

WM_User etc. is a constant, and I only have a variable, with unknown
content.

Yes, I can use the Delphi OnMessage event and catch my in-comming
message there, but I'd rather have something a little more efficient.

As this may be more into low level Windows programming, I am posting it
on the only VC group I could find too, though I don't that much C.

 

Re:Message handler for dynamic messages ?


Quote
On Wed, 26 May 1999 16:01:51 +0200, "J.Hansen" <gu...@ddre.dk> wrote:
>Here is a neat little question.

>How do I write a Windows (NOT a component !) message handler, that
>responds only to a message with a specific ID. A dynamic ID that is ?

>With dynamic, I think of  a registered message created through a call to
>RegisterWindowMessage.

>After the call, the ID is unique for as long Windows is running, but the
>normal way to create an individual handler is something like :
>(Delphi pascal used)

>type
>  something = someting_else
>     ----
>protected
>     procedure SpecialMessageHandler(var Msg : TMessage); message
>Constant_ID;
>end;

>WM_User etc. is a constant, and I only have a variable, with unknown
>content.

>Yes, I can use the Delphi OnMessage event and catch my in-comming
>message there, but I'd rather have something a little more efficient.

Use OnMessage.  The amount of extra processing involved is tiny.  You
will not see a difference.

If you want the equivalent of a message procedure for a non-constant
message, override Dispatch.  I'm throwing that in just in case anyone
really needs the answer to that question.  The important difference
between Dispatch and OnMessage is that Dispatch lets you trap a message
to a specific form or component, while OnMessage sees every message
received by the application.

Quote
>As this may be more into low level Windows programming, I am posting it
>on the only VC group I could find too, though I don't that much C.

Trimmed from reply.

--
"Generally speaking, things have gone about as far as they can possibly
go when things have got about as bad as they reasonably get."

Re:Message handler for dynamic messages ?


If you can use message maps, this maco will do what you want:

ON_REGISTERED_MESSAGE( nMessageVariable, memberFxn )

Example from MSDN

// example for ON_REGISTERED_MESSAGE
const UINT    wm_Find = RegisterWindowMessage( FINDMSGSTRING )
BEGIN_MESSAGE_MAP( CMyWnd, CMyParentWndClass )
    //{{AFX_MSG_MAP( CMyWnd )
    ON_REGISTERED_MESSAGE( wm_Find, OnFind )
    // ... Possibly more entries to handle additional messages
    //}}AFX_MSG_MAP
END_MESSAGE_MAP( )

Quote
J.Hansen wrote in message <374BFECF.66507...@ddre.dk>...
>Here is a neat little question.

>How do I write a Windows (NOT a component !) message handler, that
>responds only to a message with a specific ID. A dynamic ID that is ?

>With dynamic, I think of  a registered message created through a call to
>RegisterWindowMessage.

>After the call, the ID is unique for as long Windows is running, but the
>normal way to create an individual handler is something like :
>(Delphi pascal used)

>type
>  something = someting_else
>     ----
>protected
>     procedure SpecialMessageHandler(var Msg : TMessage); message
>Constant_ID;
>end;

>WM_User etc. is a constant, and I only have a variable, with unknown
>content.

>Yes, I can use the Delphi OnMessage event and catch my in-comming
>message there, but I'd rather have something a little more efficient.

>As this may be more into low level Windows programming, I am posting it
>on the only VC group I could find too, though I don't that much C.

Re:Message handler for dynamic messages ?


This looks like it does the task, but does anybody know, how to do that in
Delphi ?
(I am using D4 SP3)
Quote
Bryan Donaldson wrote:
> If you can use message maps, this maco will do what you want:

> ON_REGISTERED_MESSAGE( nMessageVariable, memberFxn )

> Example from MSDN

> // example for ON_REGISTERED_MESSAGE
> const UINT    wm_Find = RegisterWindowMessage( FINDMSGSTRING )
> BEGIN_MESSAGE_MAP( CMyWnd, CMyParentWndClass )
>     //{{AFX_MSG_MAP( CMyWnd )
>     ON_REGISTERED_MESSAGE( wm_Find, OnFind )
>     // ... Possibly more entries to handle additional messages
>     //}}AFX_MSG_MAP
> END_MESSAGE_MAP( )

> J.Hansen wrote in message <374BFECF.66507...@ddre.dk>...

> >How do I write a Windows (NOT a component !) message handler, that
> >responds only to a message with a specific ID. A dynamic ID that is ?

> >With dynamic, I think of  a registered message created through a call to
> >RegisterWindowMessage.

Other Threads