WxWidgets (v2.8): Use connect to customize messages

Source: Internet
Author: User
Tags wxwidgets

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 */

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.