Wtl also released the latest version, providing some Vista interface templates, which provides good news for C ++ programmers!

Source: Internet
Author: User
Tags microsoft download center

 

Responsible for Windows Template Library (wtl) Developers recently released the latest version, this template library is very good, fully supported with Windows VistaAlmost all new user interface functions and enhancements introduced. This month, I will focus on some new features in the latest version. If you are not familiar with wtl and it works with Visual C ++I will briefly introduce the adaptation between development fields at the beginning.

 

To easily create COM clients and servers and generate the smallest and fastest code possible at the same time, the visual C ++ team developed the Active Template Library (ATL ). Unlike MFC, ATL supports COM development since its design, and does a good job. While MFC focuses on developing user interface applications and only adds support for com later. ATL only supports basic user interface development. However, the classes provided by ATL can be used as lightweight building blocks and basic classes for more advanced user interface libraries.

Wtl extends ATL and provides a large number of class templates for building applications. If you want to be simple, you need to be simple. If you want to be complex, you need to be complex. Wtl is not provided with Visual C ++, but can be obtained through sourceforge.net/projects/wtl and Microsoft download center on the SourceForge website.

The main development focus of wtl 8.0 is Windows Vista UI support, so I will talk about some topics I have discussed in previous columns and articles. However, this month's focus is on how wtl's latest improvements promote adoption of these new features and ensure further reduction of code that requires your own writing! MsdnThe magazine website provides download of this column. The download content provides examples of most of the features described in this article.

Task dialog box

The task dialog box is one of my favorite new features in Windows Vista. It provides powerful APIs to develop simple and advanced dialogs with just a few effort.

The taskdialogindirect function and taskdialogconfig structure may be daunting. It does need some help from C ++ to simplify its use. Wtl supports the task dialog box through the ctaskdialogimpl base class template. The ctaskdialogimpl class uses the ctaskdialogconfig class internally to encapsulate the taskdialogconfig structure. If you need to directly access this structure, you can access it through the public variable m_tdc, but you are not likely to need it because the corresponding member functions provided by the ctaskdialogimpl class have packaged it, this is an excellent job. In addition, the ctaskdialogimpl class derived from ctaskdimpl is used in simple cases. However, it is recommended to derive a class from ctaskdialogimpl to implement the task dialog box.

Figure 1 shows some task dialog box functions and how to use them in wtl. This example sets the window title, main description, and text description. The task dialog box supports multiple additional text descriptions, but you need to set these text descriptions based on whether the task dialog box has been constructed or not. Unfortunately, the ctaskdialogimpl class does not summarize these differences, which makes it confusing to update these text descriptions. Figure 2 illustrates how to use the ctaskdialogimpl class to set various text descriptions based on the text description before or after the create a task dialog box. A common method to update these instructions is to use the pre-constructor in the task dialog box and the post-constructor in various Event Handlers.


Figure 1 Task dialog box example

The code in Figure 1 also uses the modifyflags method. The Windows SDK records various tags that can be used to customize the appearance of the task dialog box. The first parameter of the modifyflags method indicates the tag to be deleted, and the second parameter indicates the tag to be added. The setbuttons method is also used to specify the buttons that will be displayed in the task dialog box. In this example, the taskdialog_button structure array is declared as static to ensure that it is still effective outside the constructor. This is very important because the button definition will be referenced when the domodal method is called later, and all information will be passed to the taskdialogindirect function to display the task dialog box.

It is quite concise to call the domodal method. You can also select the button identifier that you select. Figure 3 shows how to display the task dialog box in Figure 1 and how to process various button identifiers.

Alternatively, you can use the callback function of the ctaskdialogimpl class to publish the task dialog box through a set of public methods. You can selectively implement these methods in the derived class to process different events. For example, to process the button-click event in the dialog box class, you can add the public method shown in Figure 4.

Processing this event is particularly useful when you want to process a specific button click instead of closing the task dialog box. There are many other events that can be handled using similar methods. Figure 5 shows a series of overwrites provided by the ctaskdialogimpl class. Remember, these are all Atl-style overwrites and are evaluated during compilation, so they do not need to call virtual functions.

The task dialog box provides more functions. The sample code in this column provides a set of comprehensive examples, fully demonstrating all the functions of the wtl task dialog box. To learn more about the API functions of the task dialog box, read my blog "Windows Vista for developers-Part 2-task dialogs in depth" (tasks ).

Aero wizard

Windows Vista introduces a stylish new look to the general wizard. AeroThe TM wizard adopts the same standard as the old wizard, but only makes some changes to the Attribute Table API. In this way, it is very easy to update the application to use the new user interface. Wtl provides a set of class templates that encapsulate all new functions to make updates easier.

You only need to derive the wizard window class from the caerowizardframeimpl class template. This class automatically applies the appropriate tag to instruct windows to use the new Aero user interface. Caerowizardframeimpl is derived from cpropertysheetimpl that provides all common functions. The Wizard Page is derived directly from the caerowizardpageimpl class, which provides a method to control the new Aero wizard button. Figure 6 provides a simple but complete single-page aero wizard example.


Figure 6 simple aero wizard

As you can see, there are not many new things to explain, and it is quite easy to move to the aero wizard. The main task will be to manage the standard buttons for the modifier of the aero wizard. This example demonstrates the showwizardbuttons, enablewizardbuttons, and setbuttontext methods. Showwizardbuttons: display or hide one or more buttons. The first parameter indicates the button for which the operation is to be performed, and the second parameter indicates the button to be displayed in these buttons. Similarly, the first parameter of enablewizardbuttons indicates the button for which the operation is to be performed, and the second parameter indicates the button to be enabled in these buttons. Other buttons will be disabled. Finally, setbuttontext updates the text description of the next, finish, and cancel buttons.

New File Dialog Box

The new file dialog box provided by Windows Vista presents a new appearance consistent with the new windows Resource Manager user interface. For the getopenfilename and getsavefilename functions that have been used for many years, this is a popular update. The new file dialog box is made public through a set of COM interfaces, so it is not difficult to directly use them. However, it is really boring to compile the same sample com code every time you need to pop up the file dialog box, especially when you need to respond to the file dialog box events that require the implementation of the COM interface. Fortunately, wtl packages it into a group of easy-to-use classes, which is indeed good. Figure 7 provides an example of the "open file" dialog box.


Figure 7 "Open File" dialog box (click the image to get a smaller view)
Figure 7 "Open File" dialog box (click the image to get a large view)

Compared with the Multi-string method used by getopenfilename, The comdlg_filterspec structure provides a more manageable format to specify the file type. Then, the arrays of these structures are passed to the setfiletypes method to specify the file types to be filtered by the dialog box. The ifileopendialog interface pointer of the getptr method returned dialog box, used to customize the appearance and behavior of the dialog box.

The new file dialog box also allows you to respond to various events. However, you must implement the ifiledialogevents interface to receive these events. Fortunately, wtl has implemented this interface through the cshellfiledialogimpl base class template, so you only need to provide a handler for the event you are interested in.

Figure 8 shows a series of overwrites provided by the cshellfiledialogimpl class. For example, you may want to confirm whether the selected file is acceptable before closing the "open file" dialog box. This is easy to implement. You only need to call the onfileok event before the dialog box returns the result. If you are sure that the selected file is unacceptable, you can close the event by blocking the dialog box. The example in Figure 9 illustrates this method.

Finally, you can use the "open file" dialog box as follows:

 

SampleOpenDialog dialog;if (IDOK == dialog.DoModal()){    CString filePath;    COM_VERIFY(dialog.GetFilePath(filePath));    // Use file here...}

 

The new file dialog box provides more functions through various COM interfaces. To learn more about the functions provided by the API in the new file dialog box, read my blog article "Windows Vista for developers-Part 6-the new file dialogs" (feature ).

Other wtl functions to be explored

In the previous "using C ++ for Windows development" column, I introduced many control enhancements in Windows Vista (msdn.microsoft.com/msdnmag/issues/07/08/windowscpp ). Currently, wtl encapsulates almost all new features through updated classes and macros to process new messages and notifications. The latest wtl version is even more attractive, from improvements to support for the adjustable size dialog box, new tab view classes to many other useful new features and improvement features. It takes several minutes to explore the wtl title. If you are new to wtl, you will be pleasantly surprised by the simple design and powerful class of Windows's excellent C ++ library.

 

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.