WxWidgets 101 - 10 Porting from MFC or QT to wxWidgets or QT Posted on 2008-11-15 04:02 chefZ 阅读. Copy convert.sh and replacements to the target directory.
- Mfc To Wxwidgets Converter Download
- Mfc To Wxwidgets Converter
- Mfc To Wxwidgets Converter Mac
- Mfc To Wxwidgets Converter Free
This question seems common so I thought I'd write an article. Note that sometimes there may be more than one possible solutions, so don't forget to check the docs.
Literals
A literal is a string written in code with 'quotes around it'. A literal is not a wxString, and (in wxWidgets 2.8) will not be implicitly converted to one. This means that you can never pass in a raw literal into a wxWidget function or method (unless you don't care about your app not building with Unicode-enabled wxWidgets builds)
Instead, wxWidgets (prior to wxWidgets 3.0) requires you to use one of these macros to turn literals into wxString-compatible characters:
WxWidgets 2.6 manual wrote:wxWindow::ConvertDialogToPixels wxPoint ConvertDialogToPixels(const wxPoint& pt) wxSize ConvertDialogToPixels(const wxSize& sz) Converts a point or size from dialog units to pixels. For the x dimension, the dialog units are multiplied by the average character width and then divided by 4. String class for passing textual data to or receiving it from wxWidgets. Note While the use of wxString is unavoidable in wxWidgets program, you are encouraged to use the standard string classes std::string or std::wstring in your applications and convert them to and from wxString only when interacting with wxWidgets.
Rather than being a nuisance, the _(), wxT(), and _T() macros take care of some unicode issues.
char* to wxString
Note that in wxWidgets 3.0, it just works to pass a char array where a wxString parameter is expected, the conversion will be automatic and implicit, using the current locale encoding. So even in wx 3.0, the snippets presented below still make sense when you don't want to be at the mercy of the current locale encoding.
wxString to char*
mb_str() returns a temporary pointer; if you need the output for more than one function call (as is the case above), you can store the char buffer for a little while :
And if you really need to copy it in to char* (but why would you? ;) :
You can also use ToUTF8(), since which encoding you get is clearer than with mb_str()
From const char* to char*:
Variadic functions (like printf) won't work with mb_str(), but this will work:
Alternatively, use the method recommended in Potential Unicode Pitfalls:
wchar_t* to wxString
wxString to wchar_t*
Mfc To Wxwidgets Converter Download
See the following methods in the docs :
wxString to TCHAR
int to wxString
or
float to wxString
or
wxString to integer number
or
wxString to floating-point number
std::string to wxString
Mfc To Wxwidgets Converter
Starting from wxWidgets 3.0, you may also use the appropriate constructor
wxString to std::string
wxWidgets 2.8 :
Under wxWidgets 3.0, you may use
std::wstring to wxString
Starting from wxWidgets 3.0, you may use the appropriate constructor
wxString to std::wstring
Under wxWidgets 3.0, you may use
See also top-level FAQ page.
List of questions in this category
Which Windows platforms are supported?
wxWidgets can be used to develop and deliver applications on WindowsXP, Vista, 7, 8, 10.
Why do controls in my application look odd?
If the controls do not look as expected (very noticeable e.g. with buttons),your application probably does not have an application manifestand so Windows displays the controls using the old (Windows 95-like) “classic” look.wxWidgets provides such a manifest in wx/msw/wx.rc and so your application will bethemed automatically so long as you include that file in your own .rc file.
Why does my application look blurry?
The most likely reason is that you have a High DPI displaybut your application does not state High DPI support.Please see High DPI Support in wxWidgets Overview.If you need more information about High DPI on Windows, please read Microsoft Windows High DPI Guide.
What compilers are supported?
Please see docs/msw/install.md file for up-to-date information.Also see this article.
Is wxWidgets compatible with MFC?
There is a sample which demonstrates MFC and wxWidgets code co-existing in thesame application. However, don’t expect to be able to enable wxWidgets windowswith OLE-2 functionality using MFC.
Why do I get errors about setup.h not being found?
When you build the wxWidgets library, setup.h is copied frominclude/wx/msw/setup.h to e.g. lib/vc_lib/mswud/wx/setup.h (the path depends onthe configuration you’re building). So you need to add lib/vc_lib/mswud
toyour include path if building using the static Unicode Debug library, orlib/vc_lib/mswu
if building the static Unicode Release library.
Why do I get errors about FooBarA when I only use FooBar in my program?
If you get errors like:
Or similar ones for the other functions, i.e. the compiler error messagesmention the function with the 'A'
suffix while you didn’t use it in yourcode, the explanation is that you had included <windows.h>
header whichredefines many symbols to have such suffix (or 'W'
in the Unicode builds).
The fix is to either not include <windows.h>
at all or include'wx/msw/winundef.h'
immediately after it.
How do I port MFC applications to wxWidgets?
Set up your interface from scratch using wxWidgets (especiallyDialogBlocks – it’ll save you alot of time) and when you have a shell prepared, you can start ‘pouring in’code from the MFC app, with appropriate modifications. This is the approach Ihave used, and I found it very satisfactory. A two-step process then -reproduce the bare interface first, then wire it up afterwards. That way youdeal with each area of complexity separately. Don’t try to think MFC andwxWidgets simultaneously from the beginning - it is easier to reproduce theinitial UI by looking at the behaviour of the MFC app, not its code.
Why are menu hotkeys or shortcuts not working in my application?
This can happen if you have a child window intercepting EVT_CHAR
events andswallowing all keyboard input. You should ensure that event.Skip()
is calledfor all input that isn’t used by the event handler.
It can also happen if you append the submenu to the parent menu before youhave added your menu items. Do the append after adding your items, oraccelerators may not be registered properly.
Is MS Active Accessibility supported?
Mfc To Wxwidgets Converter Mac
Please see this page for the current status.
Visual C++ gives errors about multiply defined symbols, what can I do?
Mfc To Wxwidgets Converter Free
If you get errors like this
when linking your project, this means that you used different versions of CRT(C Run-Time) library for wxWindows (or possibly another library) and the mainproject. Visual C++ provides static or dynamic and multithread safe or notversions of CRT for each of debug and release builds, for a total of 8libraries. You can choose among them by going to the “Code generation”page/subitem of the “C++” tab/item in the project proprieties dialog in VC.
To avoid problems, you must use the same one for all components of yourproject. wxWindows uses multithread safe DLL version of the CRT which is a goodchoice but may be problematic when distributing your applications if you don’tinclude the CRT DLL in your installation – in this case you may decide toswitch to using a static CRT version. If you build with wxUSE_THREADS 0
you may also use the non MT-safe version as it is slightly smaller and faster.
But the most important thing is to use the same CRT setting for allcomponents of your project.
How to get HWND
of a wxWindow object?
If you need to interface with native Windows code, you may usewxWindow::GetHWND()
method whose result can be cast to HWND
.
How do I handle Windows messages in my wxWidgets program?
To handle a Windows message you need to override a virtual MSWWindowProc()
method in a wxWindow-derived class. You should then test if nMsg
parameter isthe message you need to process and perform the necessary action if it is orcall the base class method otherwise.