Experience Windows GUI programming under Code :: Blocks (32 bit and 64 bit)

0. Introduction

I do not know why, almost all of the C ++ programming tutorial is the command line version (console application) of the Hello World began. However, for today’s young people who, from an early age to operate a computer click on the window or icon with the mouse, for that mysterious black text in the window like hieroglyphics. For those of us coming from the DOS era, perhaps the black window will evoke many memories, however, for the current GUI era, the window that has little meaning. Except to show my knowledgeable and inscrutable, I usually will not tell what the black window that to young people.

Now that learning C ++ programming are young, and I still talk about how to build a GUI version of Hello World bar.

If you have not set up Code :: Blocks platform, please look at my other article: “With Code :: Blocks build a 64-bit C ++ development platform.”

Now I want to talk about include: the Code :: Blocks written in C ++ with a Windows GUI program, and compiled 32 bit and 64 bit versions.

1. Use the wizard to create a new Windows GUI program

Creating Windows GUI programs and create a Console application operation is almost the same, so before looking at the steps, look at my other article “C ++ programming experience under Code :: Blocks”.

In the following description, as long as the same operation to create a console program I will be briefly described or omitted. I do this not only to save time, but also to save a little space to the server.

Step one: Open the New Project Wizard

This step is to create a console with the program is the same, there are differences in the follow-up. There are two ways:

① Main menu: File-> New-> Projects

② Click the Start Here page in the Create New Project

Step two: Select the project type Win32 GUI project in the wizard

Step 3: Select the type of window, click Next

Offers two types of windows, the specific meaning explained later, now just select one on it (for example, select Dialog based).

Step Four: Enter a project name, file

Select the location to save the file, enter the project title, project file name automatically generated by title.

Interface and operating with the same console program, the program name to ghello.

Step Five: Choose compiler

This step interface, content and operating procedures with the same console, or keep the default on it, just click Finish on the line.

The resulting file to be more than a console file, including source code, header files, resource files, and so on.

Step 6: Compile and Run

Click the image above to compile the Run button will execute the compilation process. As long as it will run after an error, the compiler does not appear to complete the link, the following window will appear. It’s just an empty window, though not the content, but the appearance with the usual procedure of using the window is the same.

At this point, your first windouows GUI application has been created, it is not very simple?

2. changed to Hello World

Although the generation of an empty window, at least, say there has been a familiar appearance. After necessary, add the code, you can achieve more.

Now first title of the window by the Dialog changed Hello World

Double-click the file resource.rc Blocks Code :: management left column, you will see the following code in the code editor pane on the right

// Generated by ResEdit 1.5.10
// Copyright (C) 2006-2012

#include "resource.h"

// Dialog resources
DLG_MAIN DIALOG 0, 0, 186, 95
CAPTION "Dialog"
FONT 8, "Ms Shell Dlg"

// Manifest resources
1                  RT_MANIFEST    ".\\manifest.xml"

Will be one of CAPTION “Dialog” amended as CAPTION “Hello World”. Then run the operation compiled by the sixth step. Results window title run is not a Hello World program?

Although this change has no real significance, however, to say the least, it is our intention to change the pressing. Later, we can modify the code or add, I realize more meaningful function.

3. were compiled for 32bit and 64bit program

For native code, the compiler generates 32bit and 64bit program is very simple.

If you are using a 32bit TDM-GCC, the compiler must be the result of 32bit applications. If you are using the 64bit TDM-GCC, the following steps may be compiled program 32bit and 64bit.

3.1 32bit compiled applications

Step 1: Right click on the project name ghello in the management bar on the left of Code: :Blocks and choose Build options from the pop-up menu to open the project build options window.

Step Two: Select build target, then click [OK]

As shown, you see a build target options in the project build options window. Check 32bit option, the compiler-generated program for the 32bit and 64bit check or neither of the two, the compiler-generated program to the 64bit.

Check one 32bit, then click [OK], turn off the option to build the target window.

The third step: recompile

In Code :: Right-click on the project name ghello Blocks management left column, select Rebuild from the popup menu, start recompile the program. Then, wait until the completion of the translation.

Step Four: Run to compile and verify the results

Click Code :: Blocks upper tool bar Run button (green triangle) to run the program, appears in the title bar of the window displays Hello World.

Right-click the menu button in the lower left corner of the main operating system of the computer screen, select “Task Manager” from the pop-up menu to open the Task Manager window.

Find gheloo.exe from the “Apply” bar of the window, you will find (32) mark, that the application is 32bit behind.

3.2 64bit compiled applications

Repeat the first step to the fourth step 4.1, except that the first step in the build target options window check 64bit, other operations are identical.

You will find that after recompiling the fourth step of the Task Manager window in parentheses after the gheloo.exe no, indicating that the application is compiled of a 64bit.

4 Conclusion

how do you feel? Simple, right?

In fact, learn to write programs is a very simple matter, however, in order to learn, learn precision, we need to learn more training, the gradual accumulation of experience. It can start with a simple program to gradually increase functionality. You can also use a program other people, try to modify, implement the functions they need.

Like learning the language as learned a single word, and then make up the statement. Statements became more articles, with good logical relationship between statements became a good article.

Leave a Reply