"Original" develop WM application series with C ++ (1) -- "Hello World" pro! (I)

Source: Internet
Author: User
Tags what header

Develop WM application series Article indexes using C ++

Introduction:

In fact, a long time ago, I wanted to get involved in the WM development of native C ++, but my c ++ level was limited to the test-taking stage in college, I hope you can share it with me, especially for beginners who want to develop WM in C ++. My seriesArticleFrom the perspective of a beginner (I am not a master), we will also introduce step by step how to conduct general WM development in the native C ++ language environment.

Of course, in order to take care of the same entry-level scholars as me, I will also spend part of my time introducing some C ++ knowledge, however, please visit haihan ~ Haha! Another point is that this article is intended for those who have developed WM applications using the C # language. It would be a bit difficult if there is no such foundation!

 

Body:

The world's most cheesy entryProgram"Hello, world !" (Hello world !) Now (I found that Chinese language requires several fewer buttons than English ~ HahaIn this case, Jack is not vulgar. Let's take the most easy-to-understand example and come and join us in today's essay. We use vs2008 and C ++ to build a smart device project, while the project template uses MFC, for example:

1-select the language, Project template, and project type, and enter the project name "helloworld"

2-Note that we chose the Windows Mobile 5.0 Pocket pc sdk as our instance SDK:

3-select the application type as "based on the dialog box"

What is MFC? I suggest you check the information on your own. It's really too wide! Of course, I am also a beginner. As the Redbook tells me, I will establish this project step by step.

TIPS: What is MDI, SDI and dialog box?

Reference Link (with a picture showing the truth ):Http://book.51cto.com/art/200901/105523.htm

So far, we have created a newDialog Box"MFC mobile application, you can see that the solution resource browser on the right has several folders, what header files, source files, for more information about the functions and relationships of these folders, see <Visual Studio 2005 c ++ getting started>. I will not go into details here.

Open a form called "resource view", as shown in:

You may be interested in this content, but it is limited to space. Please read some information and learn about what this "resource" is, what is its use for this project? How can we use it ~ And so on. Then, we double-click the menu marked in. In the main editing area, we can see that a familiar interface is opened, and you can drag the control from the toolbar to this interface. Is it a bit of Delphi? So far, I will not say much. You must have put a button on the interface.

Okay, if we want to add events to this button, we suddenly find that we cannot double-click the control like in C #. Here, we need to follow the MFC rules, to add an "event handler" to the control. In MFC, this method is very common. It uses a wizard-type process to help us create these methods andCode. The specific process is as follows:

1-right-click our button1 button and select "add event handler" from the context menu ":

2-in the new window, set the message type, the class in which the message is located, and the name of the function handler, as shown in the red box.

OK. Now, we have learned how to create the corresponding code and method for the control in MFC, so we can start to write the code. It is very simple, that is, in the method just now, write the following code:

 
Void chelloworlddlg: onbnclickedbutton1 () {MessageBox (L "Hello World", l "Tips", 0 );}

Next, compile, generate, and run it!

Is it successful ?! Don't be happy. Here we still have some things that we don't understand, but we are not in a hurry. We are a beginner. Let's get to know each other first. This article is here. In the next article, I will share with you how to use classes, functions, and member variables to expand our "Hello, world !" Program!

 

Summary:

We learned:

    1. Use vs2008 to create an MFC-based smart device application project
    2. We understand the concept of MDI, SDI and dialog box.
    3. We learned to add an "event handler" for the control"
    4. We learned to add functional code for the program.

Problem:

We can see:

    1. Why should I add an L before the strings in the MessageBox method? In fact, we can find the information by ourselves. Here I recommend an article: http://www.cnblogs.com/wanghao111/archive/2009/05/25/1488816.html
    2. Why is it so troublesome to add events and introduce the concept of "message processing? In fact, this is related to some basic knowledge of MFC. We may have to check the basic knowledge about MFC by ourselves. I believe you can understand it.

Postscript:

In the next article, I will expand this basic program function. We will create a new class, add methods and attributes for this class, and let the program call this class, to perform some simple calculations.

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.