WxWidgets (v2.8): Use connect to customize messages
1. Declare a message
In the window header file:
Use the following method to declare the message evt_define:
Const wxeventtype evt_define = wxneweventtype ();
Extern const wxeventtype evt_define;
You can also use macros, but this method is only recommended for compatibility with versions earlier than 2.2. The macro expansion after Version 2.3 is the same as the above definition.
Define_event_type (evt_define)
Begin_declare_event_types ()
Declare_local_event_type (evt_define, 7777)
End_declare_event_types ()
2. Declare the message Response Function
Add the declaration of the message response function to the header file of the window:
Void eventhandle (wxcommandevent & event );
Add the function implementation in the implementation file of the window.
Void wxmydialog: eventhandle (wxcommandevent & event)
{
Wxmessagebox (wxt ("custom message"); // a prompt box is displayed.
}
3 connect messages and their response functions
Use the following code to bind a message with its response function:
Connect (evt_define, (wxobjecteventfunction) & wxmydialog: eventhandle );
This code can be placed in any function. After connect, The evt_define message will be processed by eventhandle.
If you do not use the connect method, you can also use a macro to bind messages and response functions.
Begin_event_table (class, base_class)
// Use the declare_event_table_entry macro to define the binding of a message and a response function
End_event_table ()
4. Send the evt_define message
Wxcommandevent eventcustom (evt_define );
Wxpostevent (this, eventcustom );
This section of code sends messages in non-blocking mode.
5. Some functions and macro definitions:
Int wxneweventtype ()
{
// MT-FIXME
Static int s_lastusedeventtype = wxevt_first;
Return s_lastusedeventtype ++;
}
// The wxneweventtype () function is used to obtain an unused eventtype.
# Define declare_event_table_entry (type, winid, idlast, FN, OBJ )/
Wxeventtableentry (type, winid, idlast, FN, OBJ)
# Define begin_declare_event_types ()
# Define end_declare_event_types ()
# Define declare_exported_event_type (expdecl, name, value )/
Extern expdecl const wxeventtype name;
# Define declare_event_type (name, value )/
Declare_exported_event_type (wxdllimpexp_core, name, value)
# Define declare_local_event_type (name, value )/
Declare_exported_event_type (wxempty_parameter_value, name, value)
# Define define_event_type (name) const wxeventtype name = wxneweventtype ();
# Define define_local_event_type (name) define_event_type (name)
# Define wxempty_parameter_value/* fake macro parameter value */