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);