MFC to WxWidgets porting pen _wxwidgets

Source: Internet
Author: User
Tags wxwidgets

Porting begins with the simplest and smallest modules, and several control classes in the Mymoney are relatively independent, first porting them.

Cdoubleedit is a text control that can only enter a double, with a decimal position of up to two bits, which provides the function of money input in the Mymoney.

In MFC, Cdoubleedit derives from CEdit, in response to message En_change, realizes the message function Onenchange, when the text control content changes, determines whether is the legal value, if not then reverts to the old value m_content. The following is the declaration of Cdoubleedit in MFC:

Class Cdoubleedit:public CEdit
{
Public
Cdoubleedit ();
Virtual~cdoubleedit ();

Protected
Declare_message_map ()

Public
Afx_msg Voidonenchange ();

Private
Std::wstring m_content;
};

Wxwidgets provides a Wxtextctrl class, which is equivalent to CEdit, and also wxwidgets a message mapping mechanism that implements the message function Ontext, and responds to message wxevt_command_text_update. The following is the Cdoubleedit statement in wxwidgets:

Class Cdoubleedit:public Wxtextctrl
{
Public
Cdoubleedit (Wxwindow *parent,
Wxwindowid id = wxid_any,
Const wxstring& value = WXT ("0"),
Const wxpoint& pos = wxdefaultposition,
Const wxsize& size = wxdefaultsize);
Virtual~cdoubleedit ();

Public
Voidontext (wxcommandevent& event);

Private
Wxstring m_content;
Declare_event_table ()
};

I do not like to use the MFC CString, so the previous code with std::wstring more, although this type can also cross the platform, but Wxstring seems to use a little better, so after the transplant all std::wstring changed to wxstring.

WXWIDGETS macro WXT can convert strings based on the engineering character set.

Wxpoint and Wxsize are similar to CPoint and CSize in MFC.

MFC declares the message map table with Declare_message_map (), and Wxwidgets is declare_event_table ().

And then change the CPP file. In MFC

Begin_message_map (Cdoubleedit, CEdit)
On_control_reflect (En_change, Onenchange)
End_message_map ()

Replace it with a wxwidgets suit.

Begin_event_table (Cdoubleedit, Wxtextctrl)
Evt_text (Wxid_any,cdoubleedit::ontext)
End_event_table ()

Other work is to replace part of the member function of the physical life. GetWindowText GetValue setwindowtext SetValue setsel setselection getsafehwnd gethandle

Another mention of a wxstring, very useful, such as he provided the Format function:

Double d = 5.6f;

M_content =wxstring::format (L "%.2f", D);

and type Conversion functions:

Double D;

M_content. ToDouble (&D);

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.