An Introduction to the New Internet Explorer 4 Common Controls

Example EX09A uses each of the new IE4 common controls. Figure 9-1 shows the dialog from that example. Refer to it when you read the control descriptions that follow.

click to view at full size.

Figure 9-1. The new Internet Explorer 4 Common Controls dialog.

The Date and Time Picker

A common field on a dialog is a place for the user to enter a date and time. Before IE4 controls provided the date and time picker, developers had to either use a third-party control or subclass an MFC edit control to do significant data validation to ensure that the entered date was valid. Fortunately, the new date and time picker control is provided as an advanced control that prompts the user for a date or time while offering the developer a wide variety of styles and options. For example, dates can be displayed in short formats (8/14/68) or long formats (August 14, 1968). A time mode lets the user enter a time using a familiar hours/minutes/seconds AM/PM format.

The control also lets you decide if you want the user to select the date via in-place editing, a pull-down calendar, or a spin button. Several selection options are available including single and multiple select (for a range of dates) and the ability to turn on and off the "circling" in red ink of the current date. The control even has a mode that lets the user select "no date" via a check box. In Figure 9-1, the first four controls on the left illustrate the variety of configurations available with the date and time picker control.

The new MFC 6.0 class CDateTimeCtrl provides the MFC interface to the IE4 date and time picker common control. This class provides a variety of notifications that enhance the programmability of the control. CDateTimeCtrl provides member functions for dealing with either CTime or COleDateTime time structures.

You set the date and time in a CDateTimeCtrl using the SetTime member function. You can retrieve the date and time via the GetTime function. You can create custom formats using the SetFormat member function and change a variety of other configurations using the CDateTimeCtrl interface.

CTime vs. COleDateTime

Most "longtime" MFC developers are accustomed to using the CTime class. However, since CTime's valid dates are limited to dates between January 1, 1970, and January 18, 2038, many developers are looking for an alternative. One popular alternative is COleDateTime, which is provided for OLE automation support and handles dates from 1 January 100 through 31 December 9999. Both classes have various pros and cons. For example, CTime handles all the issues of daylight savings time, while COleDateTime does not.

With the Year 2000 crisis looming ahead, many developers choose COleDateTime because of its much larger range. Any application that uses CTime will need to be reworked in approximately 40 years, since the maximum value is the year 2038. To see this limitation in action, select a date outside the CTime range in EX09A. The class you decide to use will depend on your particular needs and the potential longevity of your application.

The Month Calendar

The large display at the bottom left of Figure 9-1 is a Month Calendar. Like the date and time picker control, the month calendar control lets the user choose a date. However, the month calendar control can also be used to implement a small Personal Information Manager (PIM) in your applications. You can show as many months as room provides—from one month to a year's worth of months, if you want. EX09A uses the month calendar control to show only two months.

The month calendar control supports single or multiple selection and allows you to display a variety of different options such as numbered months and a circled "today's date." Notifications for the control let the developer specify which dates are in boldface. It is entirely up to the developer to decide what boldface dates might represent. For example, you could use the bold feature to indicate holidays, appointments, or unusable dates. The MFC 6.0 class CMonthCalCtrl implements this control.

To initialize the CMonthCalCtrl class, you can call the SetToday() member function. CMonthCalCtrl provides members that deal with both CTime and COleDateTime, including SetToday().

The Internet Protocol Address Control

If you write an application that uses any form of Internet or TCP/IP functionality, you might need to prompt the user for an Internet Protocol (IP) Address. The IE4 common controls include an IP address edit control as shown in the top right of Figure 9-1. In addition to letting the user enter a 4-byte IP address, this control performs an automatic validation of the entered IP address. CIPAddressCtrl provides MFC support for the IP address control.

An IP address consists of four "fields" as shown in Figure 9-2. The fields are numbered from left to right.

Figure 9-2. The fields of an IP address control.

To initialize an IP address control, you call the SetAddress member function in your OnInitDialog function. SetAddress takes a DWORD, with each BYTE in the DWORD representing one of the fields. In your message handlers, you can call the GetAddress member function to retrieve a DWORD or a series of BYTES to retrieve the various values of the four IP address fields.

The Extended Combo Box

The "old-fashioned" combo box was developed in the early days of Windows. Its age and inflexible design have been the source of a great deal of developer confusion. With the IE4 controls, Microsoft has decided to release a much more flexible version of the combo box called the extended combo box.

The extended combo box gives the developer much easier access to and control over the edit-control portion of the combo box. In addition, the extended combo box lets you attach an image list to the items in the combo box. You can display graphics in the extended combo box easily, especially when compared with the old days of using owner-drawn combo boxes. Each item in the extended combo box can be associated with three images: a selected image, an unselected image, and an overlay image. These three images can be used to provide a variety of graphical displays in the combo box, as we'll see in the EX09A sample. The bottom two combo boxes in Figure 9-1 are both extended combo boxes. The MFC CComboBoxEx class provides comprehensive extended combo box support.

Like the list control introduced in Chapter 6, CComboBoxEx can be attached to a CImageList that will automatically display graphics next to the text in the extended combo box. If you are already familiar with CComboBox, CComboBoxEx might cause some confusion: instead of containing strings, the extended combo box contains items of type COMBOBOXEXITEM, a structure that consists of the following fields:

  • UINT mask—A set of bit flags that specify which operations are to be performed using the structure. For example, set the CBEIF_IMAGE flag if the image field is to be set or retrieved in an operation.

  • int iItem—The extended combo box item number. Like the older style of combo box, the extended combo box uses zero-based indexing.

  • LPSTR pszText—The text of the item.

  • int cchTextMax—The length of the buffer available in pszText.

  • int iImage—Zero-based index into an associated image list.

  • int iSelectedImage—Index of the image in the image list to be used to represent the "selected" state.

  • int iOverlay—Index of the image in the image list to be used to overlay the current image.

  • int iIndent—Number of 10-pixel indentation spaces.

  • LPARAM lParam—32-bit parameter for the item.

You will see first-hand how to use this structure in the EX09A example.



Programming Microsoft Visual C++
Programming Microsoft Visual C++
ISBN: 1572318570
EAN: 2147483647
Year: 1997
Pages: 332

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net