Some common sense of vc++.net2005 (turn) __c++

Source: Internet
Author: User
Tags locale

1.

Source file: Is the implementation of the class member function
Header file: Is class interface declaration
Resource files: Resources such as pictures and dialog boxes used in the program

2.

StdAfx.h and stdafx.cpp documents;

is the first compile-time system to create a precompiled header file (*) on the contents of these two files. PCH) and the precompiled target file (stdafx.obj), which can be improved by compiling the two files at a later time.

3.

Adds a message handler function to a control in vs2005.net. Just right click on the control to click on it. This is quite different from the vc++6.0. Must pay attention to AH.

4.MFC Document/View structure

Document: A collection of basic elements of application data that form the unit of data used by an application and provide the means to manage and maintain data

View: The user window of the data, which provides the user with a visual display of the document, which can be displayed in some or all of the contents of the document in the window.

In short: The Document object is used to hold the data, while the attempted object displays the data and allows the user to edit the data

5 various objects related to the GUI

Font objects CFont fonts used in different styles and sizes when outputting text. Alternative styles include whether italic, bold, font name, underline, and so on. Colors and background colors do not belong to the font's properties

The brush CBrush The object determines the color or template to use when populating the area.

Brush CPen objects are useful when drawing points and drawing lines. Its properties include color, width, line style, such as dashed lines, solid line, dot dash, etc.

Bitmap CBitmap objects can contain an image that can be saved in a resource

6 DC Objects

The DC (Device context device Environment) object is an abstract mapping environment, possibly a corresponding screen, or a corresponding printer or other. This environment is device-independent, so you just need to use a different device environment for different devices, and the mapping method can be completely unchanged. This is a bit of Windows dazzling device independence. As you would use a camera or copier for a painting, it would produce a different output without any adjustment to the painting.

7 managed code and managed data

Managed code is code that is written to support the common language runtime services (see "What is the common language runtime.") ”)。 To support these services, the code must provide the minimum level of information (metadata) to the runtime. By default, all C #, Visual Basic.NET, and J.net code are managed code. Visual Studio.NET C + + code is not managed code by default, but the compiler can also generate managed code by specifying a command-line switch (/clr).

Closely related to managed code is managed data. Managed data is data that is allocated and released by the common language runtime's garbage collector. By default, C #, Visual Basic, and j.net data are managed data. However, by using special keywords, C # data can be marked as unmanaged data. Visual Studio.NET C + + data is unmanaged data by default (even when the/clr switch is used), but when using Managed Extensions for C + +, you can use the "__gc" keyword to mark a class as a managed class. As the name suggests, it indicates that the memory of the class instance is managed by the garbage collector. In addition, the class is fully a member of the. NET framework, along with the benefits and limitations it brings. An example of the benefit is that it can interoperate correctly with classes written in other languages (such as managed C + + classes can inherit from the Visual Basic Class); one example of a constraint is that a managed class can inherit only from one base class.

82 in-File and text files

A file is another form of storage on an external storage medium in which the binary representation of data is in the computer's memory.
Files are usually divided into binary files and text files.
A binary file is a file that contains data or program instructions written in ASCII and extended ASCII characters. Typically executable programs, graphics, images, sounds, and so on.
A text file (also called an ASCII file): Each byte of it holds a file that can be represented as a character ASCII code. It is a "line" as a basic structure of information organization and storage of files, can be read by any word processing program simple text files.

When we write data to a file as text, once the newline character (ASCII is 10) is encountered, it is converted to carriage return-wrapping (ASCII is 13, 10). When you read a file, the combination of carriage return and line wrapping (that is, consecutive ASCII 13, 10) is converted to a newline character (ASCII is 10).
When we write data to a file in binary form, the data is exported to the file as it is stored in memory.

9 problems with MessageBox in visual Studio2005. Net

In VS, when writing MFC programs, if not attention, often out of error C2664: "MessageBoxW": Cannot convert parameter 2 from "const char [16]" to "LPCWSTR" error.

Yes, in 2005, the option is set to Unicode by default, or instead of Unicode, or use:: MessageBoxA (null, L "Hello", NULL, 0);

MessageBox (_t ("Test")); You can also do this, because this translates to Unicode encoding, which is actually a coding problem.

10

. printf only provides ANSI/MB output and does not support output of Unicode stream.
For example:
wchar_t test[] = L "Test 1234";
printf ("%s", test);

is not going to output correctly.

11

WPRINTF also does not provide Unicode output,
But he would convert the wchar_t string into a locale sb/mb character encoding, and then output
For example:
wchar_t test[] = L "Testing test";
wprintf (L "%s", test);

Will output?? 1234 string, or do not output any results
Because wprintf has no way to convert L test test to the default ANSI, you need to set the locale
SetLocale (Lc_all, "CHS");
wchar_t test[] = L "Testing test";
wprintf (L "%s", test);

will have the correct output
Equivalent to printf ("%ls", test);

In summary: CRT I/O functions do not provide Unicode output.

==================================================================

1. The most famous problem-------the native compiled program cannot run on a machine that does not have a VC installed .

Because the vc++2005 default dynamic Link Run-time library, resulting in the compilation of a good program in the runtime depends on the runtime library, of course, porting to other machines can not run. I really do not know what Microsoft was thinking, it is all the programmers, write their own procedures are for their own use. Oh. But Microsoft is confused and we can't be confused, this problem is not difficult to solve. is to use static compilation on it.

Specifically as follows:

for a generic Win32 console program, you can set this:

Click "Project"---"Properties", open the Project Properties page and click Configure Properties---"C + +"---"code generation" to change the Run-time library on the right side of this page from the default multithreaded DLL (/MD) to multi-threaded (/MT) or multithreaded Debugging (/MTD).
However, in general, when generating release version of the application, choose Multithreading (/MT), because the resulting EXE program is smaller.
If you choose Multithreaded Debugging (/MTD), the resulting EXE program will grow several times as a result of adding a lot of debugging information.

However, if MFC program, this method in Vc++2005 Express is not workable.

Instead of a static link, I have no way to find a solution. But I now for MFC is just contact, helpless ~ ~ ~ ~


2. CL: Command line Error D8016: "/MTd" and "/clr:pure" Command-Line options are not compatible

It's also a classic question---in VC + + 2005 The FStream object cannot access files under the noon path,

Including Chinese name documents under the English path.

This is a bug in VS, because of the localization problem, which can be handled as follows:

Set the global locale to the local environment before you open the file with Ifstream and Ofstream, and then set it back when you open the file.

Ofstream WriteFile;
String Filename= ("d:/my document/test. txt");
Locale loc = Locale::global (Locale ("")); The file path to open contains Chinese, setting global locale to local environment
Writefile.open (Filename.c_str (), ios::out); Open File
Locale::global (LOC)//restore global locale

With the name method of the Locale object, you can see that the name of the locale object constructed by locale ("") is "Chinese_people ' Republic of china.936", while the original locale object's name is "C" , which is the default Ansi_c convention.

Note: If you use locale loc = Locale::global (Locale ("")) to set the global locale without Locale::global (LOC), then the cout statement at the end of the program cannot be exported at noon. Although it is not a problem to operate Chinese documents at this time, it is also a place where people fall into traps easily and should be noted.


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.