WxWidgets (3) -- initial experience of the wxWidgets Application

Source: Internet
Author: User
Tags wxwidgets
WxWidgets is the full folder of the person who started learningPDF and attachment download 1 Preface
2. Download and install wxWidgets
3 wxWidgets application initial experience
4 wxWidgets learning materials and usage instructions
5. Use wxsmith for Visual Design
Appendix: learning material list

3 wxWidgets application initial experience

All the experiences in this article are carried out in code: blocks.

To compile and execute the wxWidgets program written in C ++ in code: blocks, you need to make some further settings.

First, you must add an environment variable in the wxWidgets root folder. The setting method is similar to setting the PATH variable in 2.3. In win7, right-click the "computer" icon on the desktop, select "properties" from the menu, and complete a series of operations from 1 to 5 in the "System Properties" dialog box. The new variable is named wxwin with the value x: \ wxWidgets-3.0.0.

The following settings should be performed in code: blocks.

Open code: blocks, select Settings-> global variables ..., Create a new wx variable under set default. Under build-in fields:, enter "$ {wxwin}" in base (wxwin is a variable just set ), enter "$ {wxwin} \ include" in "include", and "$ {wxwin} \ Lib" in "lib". These are part of the "Environment" required for development.


3.1 create and execute GUI applications by "Empty Projects"

The following describes how to create an empty project from scratch and make a simple application. The program is adapted from the first program in the "first programs in wxWidgets" section of the online tutorial wxWidgets tutorial (http://zetcode.com/gui/wxwidgets. This tutorial will be used as one of the bishop's steps in the proposed learning scheme.


3.1.1 create a project

The project creation process is as follows:

(1) choose "file"> "new"> "project…" from the menu ...", Select "Empty Project" to create an empty project

  

(2) After clicking the "go" button, there is a welcome page. Click "Next" and the page appears. Enter the project name. The name of the project I created is wxtest.

(3) After clicking "Next", select the compiler and the generated target file type, and select

(4) Click "finish" to generate an empty project,

(5) click File> New> file... to create a source program file for the project. In the dialog box that appears consecutively, select "C/C ++ source" (that is, the source file) as the file type to be added ), in the dialog box, select "C ++ ". Next, in the displayed dialog box, give the name of the source file with the complete path (main. cpp is used in this example). Note that the debug check box is selected.

(6) Click "finish" and input (or paste) the following source code to the main. cpp file.

#include <wx/wx.h>class Simple : public wxFrame{public:    Simple(const wxString& title);}; Simple::Simple(const wxString& title)   : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(250, 150)){  Centre();} class MyApp : public wxApp{  public:    virtual bool OnInit();}; IMPLEMENT_APP(MyApp) bool MyApp::OnInit(){    Simple *simple = new Simple(wxT("Simple"));    simple->Show(true);    return true;}

After the source code is added, the project is shown as follows:

Temporarily ignore the meaning of statements in the program. The complete process of executing the program is our current task. You can execute the program, and then look at the "Portal ".

Compile the project and see the execution result.


3.1.2 compile and execute projects

Select the "build" option in the "build" menu (or the corresponding button in the toolbar) to compile and connect the project. The first line of the program is an error. The error message is:

fatal error: wx/wx.h: No such file or directory

That is to say, the header file wx \ wx. h to be included cannot be found.

You need to set "Search Path. Select project> build options... and set compiler in the search directories tab. Add the folder X: \ wxWidgets-3.0.0 \ Lib \ gcc_dll \ mswud and X: \ wxWidgets-3.0.0 \ include through Add. The result is as shown in the following:

  

Then build, there will be no syntax errors.

There are a lot of error prompts, from the connection link. The problem is that the library file cannot be found.

Choose project> build options.... In the linker settings tab, add the target file to be connected ". As you can see, add all. A files in the X: \ wxWidgets-3.0.0 \ Lib \ gcc_dll folder through addbutton (in fact, you can select several of them. Because I don't know which ones are needed, selecting all of them is the most convenient way ):

  

Then compile, 0 errors, 0 warnings. Successful!

However, an error occurs when executing the program, for example:

Follow the prompts, find the wxmsw30ud_gcc_custom.dll file in X: \ wxWidgets-3.0.0 \ Lib \ gcc_dll, copy it to the folder where the project is located, and then execute, you will see the desired form, see.

The above execution error occurs because I added the. A file in the Lib \ gcc_dll folder in linker settings. These are "Dynamic Link Libraries" (This term can be used by Baidu ). The advantage of this method is that the compilation speed is fast and the target code is small. However, when the compiled program is executed, you must find the required. dll file. The simplest way is to copy the. dll file.

This program is very short and the result is just an empty form. However, it is sufficient to compile and execute the form program.

The above settings and file replication can be completed in advance after "experience. The descriptive method described above is to give readers more feelings about each link.


3.2 use the code: blocks Wizard to create an application

Another method to create the wxWidgets project in code: blocks is to develop the application through the "Wizard. This method is not widely used and can be used for understanding.

The materials below this section are not original and are organized from http://www.cnzui.com/archives/962.

The detailed steps for development using the wizard are as follows:

(1) choose "file"> "new"> "project…" from the menu ...", Select the wxWidgets Project at the end.

  

(2) Click "go" to enter the project Configuration Wizard. A welcome form is displayed first. Click "Next" and select the wxWidgets version number to install.

Note: In code: blocks 13.12, wxWidgets 3.0.x is supported. You must select the correct version number. Otherwise, the application can be generated, but the connection and execution are not correct.

(3) Press "Next", enter the project name "wxtest", and select the folder to save the project.

  

(4) continue "Next" and enter the author and some copyright notice information.

  

(5) continue "Next", select the GUI Design Tool and program type, and use wxsmith and dialog based.

  

(6) Press "Next" and the following are some settings in the wxWidgets environment. Here we enter the wxWidgets root folder we just set and enter "$ (# wx)" directly).

  

(7) Press "Next". here we can see that the mingw compiler is selected by default. The following is only the debug version, so we only select "CREATE" debug "configuration ".

  

(9) continue "Next". Next, you need to select how to use the wxWidgets library. Here, we will refer to the compiled wxWidgets library.

  

(10) Press "Next". Because "Configure advanced options" is selected, many other settings should be made for the wxWidgets library, here we choose to use Lib for calling (requires that the number of shared = 0 records be used when wxWidgets is compiled to generate a static library file ).

  

(11) Press "Next" to go to the last step. We will select the required database. If you do not know, We will select all the databases.

  

(12) Click "finish" and the project is created successfully.

In this case, you can view the files generated by yourself in the project, including. cpp source files and. h header files. Then read it carefully, and the program entered in 3.1 is almost the same.

In fact, the role of the Wizard is to automatically generate the application by using a series of options.

The execution result of the application created in the preceding step is:

  

Errors may occur during compilation and execution. This is generally not a problem with the program itself, but is caused by incomplete code: blocks compilation environment and execution support files.

Please refer to section 3.1.2, which may help you solve the problem and make the program run correctly.




======================= Author he Lijian csdn blog = | = Category folder of it student growth guide column (occasionally updated) ==||== C ++ online class column he Lijian Course Teaching Link (by course grade) ==|||== my book-"attacking the university against the normal energy passed to it students" ==|==== paving the runway for it cainiao to take off, A university that enjoys happiness and passion with its students ====



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.