Discuss this help topic in MsgConnect Forum

Filter: C++  Pascal  C#  VB.NET  Java  Java ME  ActiveX  DLL 



MessageHandler.OnMessage

MessageHandler     See also    


This event is fired when the message code for the message fits into range of messages handled by the object.

Declaration

[C++]
    typedef void (STDCALLCONV *MCHandleMessageEvent)(void* UserData, void* Sender, MCMessage& Message, bool& Handled);
    MCHandleMessageEvent getOnMessage(void * *UserData);
    void setOnMessage(MCHandleMessageEvent v, void* UserData = NULL);

[Pascal]
    property OnMessage: TMCHandleMessageEvent
    TMCHandleMessageEvent = procedure (Sender :TObject; var Message : TMCMessage; var Handled : boolean) of object;

[VB6]
    Event IMCXQueueEvents.OnMessage(Message As IMCXMessage, Handled As Boolean)

[ActiveX]
    void IMCXQueueEvents.OnMessage([in] IMCXMessage * Message, [in, out] VARIANT_BOOL * Handled);

[C#]
    public MCHandleMessageEvent OnMessage;

    public delegate void MCHandleMessageEvent(object Sender, MCHandleMessageEventArgs Args);

    public class MCHandleMessageEventArgs:EventArgs
    {
        public MCMessage Message;
        public bool Handled;
    }

[VB.NET]
    Public Event OnMessage As MCHandleMessageEvent
    Public Delegate Sub MCHandleMessageEvent(ByVal Sender As Object, ByVal Args As MCHandleMessageEventArgs)
    Public Class MCHandleMessageEventArgs
        Public Message As MCMessage
        Public Handled As Boolean
    End Class

[Java]
    public class MCHandleMessageEvent {
        public MCQueue getSender();
        public MCMessage getMessage();
    }
    public abstract interface MCHandleMessageListener {
        public boolean handleMessage(MCHandleMessageEvent e);
    }
    void addMessageListener(MCHandleMessageListener l);
    void removeMessageListener(MCHandleMessageListener l)

[Java ME]
    public class MCHandleMessageEvent {
        public MCQueue getSender();
        public MCMessage getMessage();
    }
    public abstract interface MCHandleMessageListener {
        public boolean handleMessage(MCHandleMessageEvent e);
    }
    void addMessageListener(MCHandleMessageListener l);
    void removeMessageListener(MCHandleMessageListener l)

[DLL]
    void __stdcall MCMessageHandlerSetOnMessage(HMCMessenger h, HandleMessageProc Code, long UserData);
    void __stdcall MCMessageHandlerGetOnMessage(HMCMessenger h, HandleMessageProc* Code, long* UserData);
    void (__stdcall *HandleMessageProc)(long UserData, HMC Reserved, MCMessage Message, bool* Handled);

Parameters

  • [DLL]h - handle to the MessageHandler object that was returned by MessageHandlers.Add method
  • [DLL]Code - pointer to the callback function that is called to handle the message

  • UserData - application-defined data that is passed back to the callback function
  • Message - the message that was sent with given credentials.
  • Handled - set this value to true to tell the queue that the message was handled and false otherwise

Description

    This event is fired when the handler is to handle the incoming message. If the application receives a message via this event, it should NOT call Messenger.MessageProcessed method -- the queue will do this automatically.
    Set Handled to true to tell the messenger that the message was processed. If the message was not processed, the queue will attempt to find another handler and finally call OnUnhandledMessage event. If OnUnhandledMessage also doesn't handle the message, messenger will set Message.Result to 0.
    It is safe to change the data pointed by Message.Data parameter. If Message.MessageType is BDT_VAR, such changes will be sent back to the message sender. If the application needs to change the size of the data, it can deallocate existing memory block (if any) using MCMemFree function. New block is allocated with MCMemAlloc function. Message.DataSize field should then be set to the size of the new block.

See also:     MCMessage structure     Queue class     MCMemAlloc     MCMemFree    

Discuss this help topic in MsgConnect Forum