Comparison between MFC and wxWidgets (2)

Source: Internet
Author: User
Tags wxwidgets

Today, we will compare the most core code of MFC and wxWidgets, that is, message ing of MFC and event table of wxWidgets.

1. Message ing macro in MFC

Declare_message_map ()

Begin_message_map (theclass, baseclass)

End_message_map ()

The expanded code is as follows:

# Ifdef _ afxdll
# Define declare_message_map ()

/

PRIVATE :/

Static const afx_msgmap_entry _ messageentries [];/

Protected :/

Static afx_data const afx_msgmap messagemap ;/

Static const afx_msgmap * Pascal _ getbasemessagemap ();/

Virtual const afx_msgmap * getmessagemap () const ;/

# Else
# Define declare_message_map ()

/

PRIVATE :/

Static const afx_msgmap_entry _ messageentries [];/

Protected :/

Static afx_data const afx_msgmap messagemap ;/

Virtual const afx_msgmap * getmessagemap () const ;/

# Endif

# Ifdef _ afxdll
#

Define begin_message_map (theclass, baseclass)

/

Const afx_msgmap * Pascal theclass: _ getbasemessagemap ()/

{Return & baseclass: messagemap ;}/

Const afx_msgmap * theclass: getmessagemap () const/

{Return & theclass: messagemap ;}/

Afx_comdat afx_datadef const afx_msgmap theclass: messagemap =/

{& Theclass: _ getbasemessagemap, & theclass: _ messageentries [0]};/

Afx_comdat const afx_msgmap_entry theclass: _ messageentries [] =/

{/

# Else
#

Define begin_message_map (theclass, baseclass)

/

Const afx_msgmap * theclass: getmessagemap () const/

{Return & theclass: messagemap ;}/

Afx_comdat afx_datadef const afx_msgmap theclass: messagemap =/

{& Baseclass: messagemap, & theclass: _ messageentries [0]};/

Afx_comdat const afx_msgmap_entry theclass: _ messageentries [] =/

{/

# Endif

#

Define end_message_map ()

/

{0, 0, 0, 0, afxsig_end, (afx_pmsg) 0 }/

};/

Afx_msgmap and afx_msgmap_entry are declared as follows:

StructAfx_msgmap

{

# Ifdef _ afxdll // use shared DLL

Const afx_msgmap * (Pascal * pfngetbasemap )();

# Else

Const afx_msgmap * pbasemap;

# Endif

Const afx_msgmap_entry * lpentries;

};

StructAfx_msgmap_entry

{

Uint nmessage; // WINDOWS Message

Uint ncode; // control code or wm_policy code

Uint NID; // Control ID (or 0 for Windows messages)

Uint nlastid; // used for entries specifying a range of Control ID's

Uint nsig; // signature type (action) or pointer to message #

Afx_pmsg PFN; // routine to call (or special value)

};

2. Event table macro in wxWidgets

Declare_event_table ()

Begin_event_table (theclass, baseclass)

End_event_table ()

The expanded code is as follows:

# Define declare_event_table ()

/

PRIVATE :/

Static const wxeventtableentry sm_eventtableentries [];/

Protected :/

Static const wxeventtable sm_eventtable ;/

Virtual const wxeventtable * geteventtable () const ;/

Static wxeventhashtable sm_eventhashtable ;/

Virtual wxeventhashtable & geteventhashtable () const;

# Define begin_event_table (theclass, baseclass)

/

Const wxeventtable theclass: sm_eventtable =/

{& Baseclass: sm_eventtable, & theclass: sm_eventtableentries [0]};/

Const wxeventtable * theclass: geteventtable () const/

{Return & theclass: sm_eventtable ;}/

Wxeventhashtable theclass: sm_eventhashtable (theclass: sm_eventtable );/

Wxeventhashtable & theclass: geteventhashtable () const/

{Return theclass: sm_eventhashtable ;}/

Const wxeventtableentry theclass: sm_eventtableentries [] = {/

# Define end_event_table ()

Declare_event_table_entry (wxevt_null, 0, 0, 0 )};

Struct wxdllimpexp_baseWxeventtable

{

Const wxeventtable * basetable; // base event table (next in chain)

Const wxeventtableentry * entries; // bottom of entry Array

};

Class wxdllimpexp_baseWxeventhashtable

{

PRIVATE:

// Internal data structs

Struct eventtypetable

{

Wxeventtype eventtype;

Wxeventtableentrypointerarray evententrytable;

};

Typedef eventtypetable * eventtypetablepointer;

Public:

// Constructor, needs the event table it needs to hash later on.

// Note: hashing of the event table is not done in the constructor as it

// Can be that the event table is not yet full initialize, the hash

// Will gets initialized when handling the first event look-up request.

Wxeventhashtable (const wxeventtable & table );

// Destructor.

~ Wxeventhashtable ();

// Handle the given event, in other words search the event table hash

// And call self-> processevent () If a match was found.

Bool handleevent (wxevent & event, wxevthandler * Self );

// Clear table

Void clear ();

// Clear all tables

Static void clearall ();

// Rebuild all tables

Static void reconstructall ();

Protected:

// Init the hash table with the entries of the static event table.

Void inithashtable ();

// Helper funtion of inithashtable () to insert 1 entry into the hash table.

Void addentry (const wxeventtableentry & entry );

// Allocate and init with null pointers the base hash table.

Void alloceventtypetable (size_t size );

// Grow the hash table in size and transfer all items currently

// In the table to the correct location in the new table.

Void groweventtypetable ();

Protected:

Const wxeventtable & m_table;

Bool m_rebuildhash;

Size_t m_size;

Eventtypetablepointer * m_eventtypetable;

Static wxeventhashtable * sm_first;

Wxeventhashtable * m_previous;

Wxeventhashtable * m_next;

Declare_no_copy_class (wxeventhashtable)

};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.