Building a GUI framework for C + + wxwidgets development environment on Visual Studio _android

Source: Internet
Author: User
Tags gtk wxwidgets

This article uses the Unicode+dll+debug method because the EXE file that does not want to be last generated is too large.

The environmental construction steps are as follows:

1, download Wxwidgets package:

Login wxwidgets download page: http://www.wxwidgets.org/downloads
Download the latest stable release stabilizer and I'll use the old version 2.8.12 as a demo.

2, the wxmsw-2.8.12.zip will be extracted to the D-packing directory.

Go to the D:\WXMSW-2.8.12\BUILD\MSW directory, open wx.dsw with VS2005, and you will be prompted to convert items:

Select "All is".

3, into the VS2005 interface, in the following figure shows the region to select the DLL Debug:

4, press F7 to build the solution, this operation will generate a "Vc_dll" folder under the D:\wxMSW-2.8.12\lib, which is the DLL and Lib we need.

But the first execution will prompt some failure. Because there are some build items that depend on other build items. Continue pressing F7 at this point until 1 of the prompts fail. At this point, and then press F7 is useless, to see the error hint:

1>link:fatal Error LNK1104: Unable to open file "... \.. \lib\vc_dll\wxbase28ud_odbc.lib "

This wxbase28ud_odbc.lib does not exist under D:\wxMSW-2.8.12\lib\vc_dll. You can select Unicode Debug in the previous illustration, then select ODBC on the left, right-click, select Build, and create Wxbase28ud_odbc.lib in the D:\wxMSW-2.8.12\lib\vc_lib directory to copy this file to D:\ In the Wxmsw-2.8.12\lib\vc_dll directory, select the option back to DLL Unicode Debug in the previous illustration, and then press F7 so that all the files are generated.

In this way, 14 DLL files and 18 lib files are generated.

5, select the tool in the menu bar--option, in the Open window, select the project and solution--vc++ directory.

5.1 Add in "Include Files":

D:\wxMSW-2.8.12\include
D:\wxMSW-2.8.12\include\msvc

5.2 Add in library files:

D:\wxMSW-2.8.12\lib\vc_dll
D:\wxMSW-2.8.12\lib\vc_dll\mswud

The following figure:

6, close the original project, a new empty Win32 project, the name is Wxtest. Note that if the item is empty.

Add a C + + file Test.cpp for this project, content for D:\wxMSW-2.8.12\samples\minimal\minimal.cpp content.

7, configure the project:

Select the item, select the Item--wxtest property in the menu bar, and configure the properties in the open window:

7.1 Add the preprocessor definition in the configuration Properties--c/c++--preprocessor:

_unicode; Wxusingdll

7.2 In the Configure Properties--c/c++--Runtime Library, select the runtime Library:

Multithreaded Debug DLL (/MDD)

7.3 Add the Additional Dependencies library in the Configure properties--linker-Input:

Wxbase28ud.lib
wxbase28ud_net.lib
wxbase28ud_odbc.lib
wxbase28ud_xml.lib
wxexpatd.lib
Wxjpegd.lib
wxmsw28ud_adv.lib
wxmsw28ud_aui.lib
wxmsw28ud_core.lib
wxmsw28ud_html.lib
wxmsw28ud_media.lib
wxmsw28ud_qa.lib
wxmsw28ud_richtext.lib
wxmsw28ud_xrc.lib
Wxpngd.lib
wxregexud.lib
wxtiffd.lib
wxzlibd.lib

This is a whole brain plus.

8, the generation of solutions, is successful. Press F5 to run this program, will prompt the computer to lose Wxmsw28ud_core_vc_custom.dll, from D:\wxMSW-2.8.12\lib\vc_dll to copy this file to the generated EXE file in the directory. Run again, will be prompted to lose Wxbase28ud_vc_custom.dll, and then copy the file to the generated EXE file in the directory. You can run it again right now:

About solving garbled problems with wxwidgets controls
these two days in using wxwidgets to do a small program, suddenly encountered a control display garbled problem.

Declare first: The compiler I use is the visual Studio 2005,wxwidgets version is 2.8.12, and the following workaround is not necessarily valid for all platforms.

As we know, the control display string in wxwidgets is generally wxstring, such as a small piece of code to create and display a button:

Create a button that displays the name "button"
wxbutton* Onebutton = new Wxbutton (itemFrame1, Id_button, wxt ("button"), Wxdefaultposition, Wxdefaultsize, 0);
Put this button in a Boxsizer
itemboxsizer->add (Onebutton, 1, Wxalign_center_vertical|wxall, 5);

The above code has no errors, the screenshot below shows:

However, in many cases, the label of the control we want to display is first placed in char *, we have to convert it to wxstring first, there are many ways to convert, such as using Wxstring::fromutf8 (), or you can define a Wxstring object, Invokes the printf method. Neither method, however, is working.

The following code:

Char *label = "button";
Wxstring Wxlabel;
wxlabel.printf (WXT ("%s"), label);
wxbutton* Onebutton = new Wxbutton (itemFrame1, Id_button, Wxlabel, Wxdefaultposition, wxdefaultsize, 0);
Itemboxsizer->add (Onebutton, 1, Wxalign_center_vertical|wxall, 5);

The result is

If you use Wxstring::fromutf8 (), there is no label displayed in the control at all.

Google for a long time did not find a solution, then suddenly thought, before doing a GTK project encountered in the Chinese garbled problem, when peak brother sent me a string conversion encoding function, of course, GTK has its own functions can be converted, is G_locale_to_utf8. And Wxwidgets doesn't seem to have such a function. The function that Brother Feng gave me just came in handy.

The function that Brother Feng gave me is that ANSI and UTF8 are converted to each other, why is it useful because the VS default encoding is ANSI. When I was at Google today, I saw someone say to change the encoding format of the source code to UTF8, in the VS file--advanced save option, I tried, useless. But use the function that the peak elder brother gives me, the effect is different.

Brother Peak's code is:

BOOL Ansi_to_utf8 (char * lpcszstr, char** lpwszstr)
{  
 wchar* stra; 
 int i= MultiByteToWideChar (CP_ACP, 0, (char*) Lpcszstr,-1, NULL, 0); 
 Stra = (WCHAR *) malloc (sizeof (WCHAR) * i); 
 MultiByteToWideChar (CP_ACP, 0, (char*) Lpcszstr,-1, Stra, i*2); 
 I= WideCharToMultiByte (Cp_utf8, 0, Stra,-1, NULL, 0, NULL, NULL);
 *LPWSZSTR = (char *) malloc (i);
 WideCharToMultiByte (Cp_utf8, 0, Stra,-1, *LPWSZSTR, I, NULL, NULL);  
 return TRUE;
}

You can put this code in a header file of your program as a member function. Don't forget to include the Windows.h header file.

Then revise the second paragraph of the above code as follows:

Char *label = "button 2";
char *label_utf8;
This->ansi_to_utf8 (label, &label_utf8);
wxbutton* Onebutton = new Wxbutton (itemFrame1, Id_button, Wxstring::fromutf8 (Label_utf8), Wxdefaultposition, Wxdefaultsize, 0);
Free (LABEL_UTF8);
Itemboxsizer->add (Onebutton, 1, Wxalign_center_vertical|wxall, 5);

This will show up correctly:

Related Article

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.