In-depth exploration of the next generation of Visual C ++

Source: Internet
Author: User
Explore the next generation of Visual C ++ Tarek madkour more... print
Email
Add to favorites
Rating
RSS (issues)
Add RSS to any
Related information
Live Spaces
Digg this
Blogthis!
Slashdot
Del. icio. us
Technorati
This article is based on the prerelease version of Visual Studio (codenamed "orcas. All information contained in this document may be changed. --------------------------------------------------------------------------------
This article discusses how to target applications with Windows Vista
Enhanced Functions of MFC
Prepare UAC applications
Sending and processing local and CLR type
This article uses the following technologies:
Visual c ++, Visual Studio
--------------------------------------------------------------------------------
Directory preparation for Windows Vista applications
Add support for new public controls
Other enhanced MFC Functions
Prepare for User Account Control
Interoperability with managed code
Use the mail handling database to simplify the program
Use STL/CLR on the CLR type
Build code more quickly
Conclusion
--------------------------------------------------------------------------------
W

Indows Vista exposes thousands of new Native APIs for WindowsThe platform has been expanded. These APIs allow developers to create more fashionable user interfaces, develop more responsive I/O operations, and manage threads more efficiently. The next version of Visual Studio codenamed "orcas"It will help c ++ developers make full use of the new features provided by Windows Vista. To achieve this, it provides built-in support for all new Native APIs, as well as additional support for new controls and public dialogs in the MFC and dialog box editor. In addition to all these native development improvements, Visual Studio "orcas" also provides a new library designed to bridge the gap between the native and hosted code, extends the ability of C ++ developers to implement their local components and Microsoft. NET Framework Technology for interoperability between managed components. This article will detail the new technologies included in the forthcoming Visual Studio "orcas.

 

Prepare applications for Windows Vista

Visual Studio "orcas" contains all necessary header files and library files for all Windows versions from Windows 2000 to Windows Vista. This allows developers to access low-level APIs directly exposed by the operating system and their components for C/C ++ applications. In addition to providing access to C-language APIs, Visual Studio "orcas" also extends MFC to use the new Windows Vista API where appropriate, in addition, an API subset is encapsulated and exposed in the MFC Library environment.

Most improvements to MFC are focused on the UI. After Visual Studio "orcas" is used to re-compile the MFC application, it will be automatically upgraded to a new interface for Windows Vista-that is, the public dialog box will be enhanced, the toolbar will follow the theme of Windows Vista, and the window frame and title bar will show the transparency of Aero. You do not need to modify any code for this interface upgrade-you only need to re-compile the application. Of course, by migrating the MFC application to the New Visual Studio version, developers can access the new controls and styles exposed in Windows Vista.

The updated MFC will also complete all necessary work to make it easy to use the public dialog box in Windows Vista. The following uses the MFC Code Compiled by Visual Studio "orcas" as an example:

 

    CFileDialog dlgFile(TRUE);    dlgFile.DoModal();

 


Figure 1 MFC public file dialog box on Windows Vista (click the image to get a small view)
Figure 1 MFC public file dialog box on Windows Vista (click the image to get a large view)

When executed on Windows Vista, the exquisite public file dialog box is displayed, as shown in figure 1. However, on low-level platforms, such as Windows 2000 and MFC, the rollback mechanism is used to display the old public file dialog box, as shown in figure 2.


Figure 2 MFC public file dialog box on the low-level platform (click the image to get a small view)
Figure 2 MFC public file dialog box on the low-level platform (click the image to get a large view)

Note that, if you use earlier versions of Visual Studio and MFC to compile the same code, the result can only be a traditional public file dialog box (as shown in Figure 2)-even on Windows Vista. If necessary, you can use the default value to overwrite the new MFC behavior, and always display the old version, non-Windows Vista public dialog box. The method is to pass an additional parameter to the cfiledialog class constructor and set the bvistastyle flag to false.

In addition, the updated MFC class allows developers to roll back to the underlying com Implementation of the Windows Vista public file dialog box to execute more complex tasks, such as the custom public dialog box. For example, the updated cfiledialog class has a getter to provide access to the ifiledialogcustomize interface, which allows developers to add controls to dialog objects.

Add support for new public controls

The support for new controls and styles provided by Windows Vista allows developers to create beautiful and pure Windows Vista applications. However, Visual Studio "orcas" also adds support for some Windows XP controls and styles that were not implemented in earlier versions of Visual Studio. The following is a summary of the new controls in Visual Studio "orcas:

The command link control is shown in Figure 3. command link is a new button style introduced in Windows Vista. It is essentially a button control with bs_commandlink STYLE tag set. These buttons actually indicate the operation to be performed by the button, with a brief description of the operation, which greatly improves the user interface. This control is mainly used in the Windows Vista task dialog box.


Figure 3 command link

The split button control is shown in Figure 4. The split button is a Windows Vista button that has a default operation, but other possible operations can also be accessed through a clever UI gesture, this gesture will display a drop-down menu with more operations. The split button control is essentially a button control with bs_splitbutton STYLE tag set.


Figure 4 SPLIT button

The network address control is shown in Figure 5. It is a simple Windows Vista editing box that verifies the input and limits the input to an IPv4 address, IPv6 address, or a friendly DNS name.


Figure 5 network address

Sys link control is a Windows XP control that is not supported by earlier Visual Studio versions. As shown in figure 6, it can easily embed hypertext links in the window.


Figure 6 Sys link

For each newly supported control, MFC also contains classes and notifications. In addition, the resource editor in IDE has been updated and you can use the new MFC class and control. The Toolbox window displays all the new controls as native controls available in the MFC dialog box editor. If you drag and drop controls to the MFC dialog box, they are correctly displayed on the Windows Vista host. If you drag and drop controls to a low-level platform, Placeholders are displayed with corresponding messages, indicates that the control cannot be rendered on a non-Windows Vista platform. Figure 7 shows the dialog box for versions earlier than Windows Vista, while Figure 8 shows a more beautiful Windows Vista dialog box .) Property pages have also been updated to display the styles and events available for the new control. Finally, you have added support for the MFC Wizard to add control classes and members.


Figure 7 Windows XP dialog box

The MFC in Visual Studio "orcas" also extends support for existing controls that have been enhanced in Windows Vista. The following controls support extensions: Treeview, monthcalendar, datetimepicker, static, Slider (trackbar), and SS controls. In addition, Windows Vista also enhances many other controls by extending the style to make the UI look smoother and richer user functions. The styles of these controls can be directly set by sending messages to their respective controls. For example, to activate the rich tooltip on the Treeview control to customize the content with icons and text, you can send a tvm_setextendedstyle message to the tvs_ex_richtooltip extension style on the control.


Figure 8 Windows Vista Control update dialog box (click the image to get a small view)
Figure 8 Windows Vista Control update dialog box (click the image to get a large view)

Applications that want to follow the Windows Vista UI Guide should use the new controls provided by Windows Vista to create a more eye-catching and functional user interface.

Other enhanced MFC Functions

New Windows Vista UI conventions, such as selectively hiding the menu bar of an application by default, are also included in Visual Studio "orcas. In this example, the menu bar is displayed only when the Alt key is used for activation. Otherwise, the menu bar is hidden. Many Microsoft applications use the same technology, such as Internet Explorer running in Windows Vista.7. To enable this behavior, developers need to set the appropriate flag on cframewnd by calling cframewnd: setmenubarvisibility (afx_mbv_displayonfocus. MFC also discloses the aero wizard. Currently, you can set m_psh.dwflags | = psh_aerowizard in the cpropertysheet constructor to update the MFC Wizard to use the aero wizard framework.

The resource editor is also updated to support the new Windows Vista UI guide. By default, the new dialog box to be added follows the UI guide in terms of the control position, control size, and font used. Resource Manager also provides enhanced functions for viewing icons used in Windows Vista-based applications. It now supports viewing 32-bit color images, PNG images, 256x56 icons, and PNG icons (as shown in Figure 9 ). In addition, it supports better preview modes for icon files that contain multiple icon images.


Figure 9 supported icons in the resource editor (click the image to get a smaller view)
Figure 9 supported icons in the resource editor (click the image to get a larger view)

Finally, the spy ++ application has been updated to monitor new messages introduced in Windows Vista. In addition, spy ++ is proud of its support for 64-bit applications in Visual Studio "orcas.

Prepare for User Account Control

The most noteworthy new security feature in Windows Vista is User Account Control (UAC ). With UAC, you can run with the lowest permission and must explicitly grant the administration permission. This function is of great significance. Now, when applications run under Windows Vista's default UAC, developers must be aware of how their applications will be executed, which is critical. In addition, it is recommended that developers actively enhance Desktop Security by specifying the security level required for their applications. Visual Studio "orcas" eliminates the burden required by UAC to manually generate a list of necessary XML commands to help developers prepare applications for UAC. Applications that do not have a UAC command list and do not explicitly run with administrator permissions run in compatible virtualization mode. In this mode, all writes that have a global impact (such as writing data to the registry or non-user disk location) will be redirected to the location of each user. However, note that the compatibility mode should be considered only a matter of expediency, because it may cause minor defects to applications. We recommend that all applications designed for Windows Vista be tested against UAC and have an appropriate UAC command list.

The UAC command list can contain one of the following three call modes: As-invoker, highest-available, and require-administrator.

As-invoker this permission level allows the application to use the same token as its parent process when running the program. This is the default value and is the UAC setting recommended for all Windows Vista applications.

Require-Administrator this permission level requires the full administrator permission to run the application. Only members of administrators on the local computer can use this setting to run applications. When you use this permission level to call an application, a UAC dialog box is displayed, which requires execution at this permission level.

Highest-available this permission level requires that you use the highest permissions provided to the current user to run the application. This is usually converted to the require-Administrator permission because too many users run as administrators.

How do you generate a UAC command list? Visual Studio "orcas" exposes a new switch of link. EXE, which enables Automatic Generation of uac xml Instruction List fragments. The format of the new switch/manifestuac is:

 

/MANIFESTUAC[:{NO|UAC fragment}]

 

The default value of this switch is to generate a command list with the as-invoker permission. Specifying no for this switch will not generate a command list, and will cause the application to run in compatible mode. When requireadministrator or highestavailable is specified, the corresponding permissions are set on the UAC command list generated.

As shown in figure 10, Visual Studio "orcas" also exposes the same option on the project property page.


Figure 10 User Account Control Options for Visual C ++ projects (click the image to get a small view)
Figure 10 User Account Control Options of Visual C ++ (click the image to get a large view)

By default, an as-invoker UAC command list is generated for all new applications created with Visual Studio "orcas. UAC is automatically enabled for all applications upgraded from earlier versions of Visual Studio.

I also want to point out that Internet Explorer 7 uses Windows Vista's UAC function to provide a safer protection mode. This default mode is essentially to run components in Internet Explorer with lower than standard user permissions. This is achieved by starting components in the newly generated Internet Explorer instance (with lower permissions. Therefore, components that need to be run in Internet Explorer 7, such as ActiveXControl, Internet Explorer 7 protection mode must be tested.

Visual Studio "orcas" adds a new option for the c ++ project to debug applications in a web browser. The list of available debuggers currently contains the web browser debugger, which also takes into account Internet Explorer 7 protection mode and performs all the necessary work to attach the newly created process with low permissions.

Interoperability with managed code

In addition to focusing on the local tools of C ++ developers.. NET Component (managed code development). Visual Studio "orcas" also extends its support. With the release of. NET Framework, more and more industry-level applications are incorporating more hosted components into their local C ++ applications. Hosted code is of great value and applicability in these fields.

To integrate those. NET components into existing and new local C ++ code, Visual Studio "orcas" makes it easier. Visual Studio currently provides libraries that integrate local practices into managed code and help you effectively write code that spans the local-managed boundary.

Use the mail handling database to simplify the program

The most basic requirement of the mixed local and Common Language Runtime Library (CLR) types is to be able to send and process data across two systems. Fortunately, Visual Studio "orcas" brings about a solution. It contains a new mail and mail processing database, which simplifies the compilation of code used to mail and process types between the local environment and CLR. The mail handling database operation is based on the existing. NET Framework routines. However, by exposing the mail handling routine as a member of the Scalable Template Library, the complexity of using these classes is reduced.

The new mail handling library has built-in support for all common string types used by C ++ applications-such as ATL cstring, BSTR, ccombstr, char *, wchar *, STD:: String, STD: wstring, and system: String ^. In addition, developers can add more conversions than existing ones. The following is a simple example of Converting System: string to char * using the mail handling database:

 

#include <msclr/marshal.h>void myfunc (String^ s){    msclr::interop::marshal_context ctx;    char *s2 = ctx.marshal_as<char*> (s);    //...}

 

Use STL/CLR on the CLR type

The container-iterator-algorithm structure of the standard template library (STL) Simplifies C ++ development and has become a common mode for many c ++ developers. Just like the practice that STL implements for the local type, Visual Studio "orcas" uses STL/CLR to bring the same Convention into the CLR field. This new feature allows the same convention to be used in both local and hosted environments, which may significantly increase the productivity of C ++ developers. In addition, this function makes it easier to exchange data between STL containers and. net collections.

The containers provided by STL/CLR for the CLR type are the same as those provided by STL for the local type. The new container is part of the client namespace. STL/CLR also makes the algorithm complexity consistent with STL. STL/CLR containers can store the CLR reference type and value type of garbage collection, as well as Clr and native built-in types. They cannot store native type or pointer to native type.

STL/CLR also discloses iterators that can be used with its containers. The level of STL/CLR iterator is the same as that of STL iterator, and the Access Mode of STL/CLR iterator is also the same. STL/CLR also discloses the same algorithm set as STL. This algorithm can be run on STL/Clr and STL containers. The following example shows the running STL/CLR container and iterator:

 

#include <cliext/hash_map>void myfunc (){    cliext::hash_map<Int32, String^> m;    m.insert (cliext::make_pair(5, L”five”));    cliext::hash_map<Int32, String^>::iterator i = m.find(5);    Console::WriteLine(“map[{0}] == {1}”, i->first, i->second);}

 

Build code more quickly

Another improvement in developing C ++ code for CLR is that the speed of incremental building is significantly faster. A long-term weakness in the development of large-scale CLR applications with C ++ components is the need to re-build dependencies, even if the core components only implement changes without interface changes. The reason is that the CLR Assembly encapsulates the component metadata and implementation into the same Binary Package. Therefore, when any part of the CLR assembly is changed, you must re-build a large C ++ project that depends on the CLR assembly.

A new tool is added to the forthcoming Visual Studio version to create an assembly with metadata only. This Assembly captures the interface, the dependent C ++ project is re-built only when the interface assembly is changed. Changes made to the implementation of the Assembly will not trigger re-build of the dependent assembly. This will significantly shorten the build time in the incremental build solution, and thus increase the productivity of developers.

When discussing the topic of building throughput, one of my favorite Visual Studio "orcas" features is the ability to compile source files in parallel. This applies to both local code and managed code. Cl. EXE provides a new switch/MP to enable this behavior. The new switch syntax is as follows:

 

/MP[n] use up to ‘n’ processes for compilation

 

N is used to specify the number of processors to be used. If no number of processors is specified, the compiler will use the number of logical processors available on the machine. If the number of processes is specified, N processes are accurately generated to complete compilation.

The parallel compilation function is implemented by compiling different conversion units in different processes. A single conversion unit cannot be compiled across multiple processes. For example, when running on a computer with a 4-processor, consider the following compiler call results:

 

CL /c /MP a.cpp b.cpp c.cpp d.cpp e.cpp f.cpp

 

The result is that the compiler compiles four conversion units in parallel. Once one of the four processors is released, the compiler starts to compile the new conversion unit immediately.

Consider the following compiler call results on a computer with a dual processor:

 

CL /c /MP a.cpp

 

The compiler will compile the received single conversion unit in sequence because it cannot execute parallel compilation within the conversion unit.

Conclusion

For C ++ developers eager to use new features and features provided by Windows Vista, the forthcoming Visual Studio "orcas" version will provide significantly enhanced tools. In this versionDevelopers provide thousands of new Windows Vista APIs. MFC has also been improved to make it easy for MFC developers to take advantage of many Windows Vista features. IDE extends the resource editor to publish new Windows Vista controls. In addition, you have added support for creating UAC-compatible applications.

Visual Studio "orcas" also provides improvements for developers who need to bridge the gap between their local C ++ code and CLR. This is achieved by providing new libraries and tools that help increase developers' productivity. At the same time, the new version of Visual Studio also includes convenient new features such as parallel compilation to further improve the experience of developers.

 

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.