PDA

View Full Version : Replacement for MESSAGE_MAP()



krishbhala
4th December 2007, 15:18
What is the for below MFC Macros?

DECLARE_MESSAGE_MAP()


BEGIN_MESSAGE_MAP()
.....
END_MESSAGE_MAP()

jpn
4th December 2007, 15:40
Don't even consider porting your application line by line, macro by macro like that. Things just don't work that way. Think of what your MFC application does and then write the functionality with Qt. Corresponding functionality is done in Qt with signals and slots (http://doc.trolltech.com/latest/signalsandslots.html).

rickbsgu
4th December 2007, 16:20
What is the for below MFC Macros?

DECLARE_MESSAGE_MAP()


BEGIN_MESSAGE_MAP()
.....
END_MESSAGE_MAP()

These are the way MFC implements event handling routines. In the old Win32 API, you created a window class and then implemented a message handler for a window instance that intercepted all windows messages. It was up to you to break out the functionality you needed on a message-by-message basis (usually in a big switch statement), or pass the message on to the windows code.

MFC introduced the message map as a way to handle windows events (in c++) in a more discrete manner - one function per message. This is done in a mechanism (through the macros) that works remarkably like Qt's signal-slot mechanism - it's essentially a way of tying a callback to an instance of a class.

That said, it's very specific to Windows events - Qt's signal-slot is a more general mechanism that goes beyond any particular windowing system's events. Many window events in Qt - such as 'clicked' - are forwarded through signals. Other's aren't and you have to override the base class implementation to intercept them.

Interestingly enough, wxWidgets has somewhat resurrected the message-map idea, but they don't implement a signals-slots mechanism, at all.