Author : Unknown
Page : << Previous 12
type, input "AVI". 4) Name the resource ID as IDR_AVI.
Sample Implementation
In the dialog box's initialization stage, we need to initialize the animate control, progress control and set timer as follows:
(Code omitted)
First, function CAnimateCtrl::Open(...) is called to open the animation resource, then function CAnimateCtrl::Play(...) is called to play the AVI data. When doing this, we pass 0 to its first parameter and -1 to the second parameter, this will let the animation be played from the first frame to the last frame. The third parameter is also -1, this means the animation will be played again and again without being stopped.
Then we initialize the range of progress control from 0 to 50, incremental step 2, and a timer with time out period of 500 milliseconds is set.
Message WM_TIMER can be handled by adding message handlers, this can be easily implemented through using Class Wizard. In the sample, this member function is implemented as follows:
(Code omitted)
The only parameter of this function is nIDEvent, which indicates the ID of the timer that has just timed out. If we have two or more timers set within the same window, by examining this ID we know which timer has timed out. In the sample, when timer times out, we simply call function CProgressCtrl::StepIt() to advance the progress bar one step forward.
Summary:
1) A spin control must work together with another control, which is called the "Buddy" of the spin control. Usually the "Buddy" is an edit box, but it could be any other types of controls such as button or static control.
2) To set buddy automatically, we must make sure that the buddy window is the previous window of the spin control in Z-order.
3) The buddy can also be set by calling function CSpinButtonCtrl::SetBuddy(...).
4) If we set "Set buddy integer" style, the spin control will notify the buddy control to update its contents whenever the position of the spin control changes. If we set this style, the buddy edit box can display only integers.
5) If we want to customize the behavior of buddy control, we need to handle message UDN_DELTAPOS. This message will be sent when the position of the spin control changes. By doing this, we can let the buddy control display text strings or bitmap images.
6) Slider control shares the same message with scroll bars. By handling message WM_HSCROLL (for horizontally orientated sliders) and WM_VSCROLL (for vertically orientated sliders), we can trap the mouse activities on the slider.
7) List box can be implemented in different styles: single selection, multiple selection, extended selection. By default, the items in the list box will contain only characters, and they will be alphabetically sorted. These styles can be changed by calling member functions of CListCtrl.
8) A list box can be used to display directories and files contained in a specific directory by calling function CListCtrl::Dir(...).
9) We can handle LBN_... type messages to customize the default behavior of a list control.
10) A combo box is composed of an edit box and a list box. Because they are not created by MFC code, we can not access them through the normal method.
11) To trap RETURN, ESC keys for combo box, we need to override function CWnd:: PreTranslateMessage(...).
12) To implement subclass for edit box contained in a combo box, we need to call function CWnd:: SubclassWindow(...) instead of CWnd::SubclassDlgItem(...).
13) To create owner-draw list box or combo box, first we need to set "Owner draw" style, then override WM_MEASUREITEM and WM_DRAWITEM message handlers.
14) Image list is used by tree control, list control and tab control. Once an image list is assigned to a control, the images contained in the list can be accessed through their zero-based indices.
15) To use a tree control, we can create its resource in the dialog template. Then in the dialog's initialization stage, we can create the tree structure. A tree item can be added to the control by stuffing a TV_ITEM type object, then calling function CTreeCtrl::InsertItem(...).
16) We need to handle message TVN_ITEMEXPANDING or TVN_ITEMEXPANDED to customize a tree control's expanding and collapsing behaviors.
17) We need to set "Edit labels" style and handle TVN_ENDLABELEDIT message to enable label editing for tree control.
18) We need to handle messages TVN_BEGINDRAG, WM_MOSUEMOVE, and WM_LBUTTONUP to enable drag-n-drop for tree control.
19) The list box can be displayed in four different styles: Normal (big) icon style, small icon style, list style, and report style. We can select one style when the list box resource is being created. If we want to change the style dynamically, we need to call function ::SetWindowLong(...).
20) Because list control can be used to represent items in different styles, usually we need to prepare two image lists (big icon and small icon) for a list control.
21) To create a list control, we need to create columns first. For each column, we need to create sub-items for all the items contained in the list.
22) To create a column for a list control, we need to stuff an LV_COLUMN type object and call function CListCtrl::InsertColumn(...). To create an item, we need to stuff an LV_ITEM type object and call function CListCtrl::InsertItem(...). To set the rest sub-items, we need to stuff LV_ITEM type objects and call function CListCtrl::SetItem(...).
23) To use tab control, first we need to create tab control resource in the dialog template. Then in the dialog's initialization stage, we need to create and select the image list, stuff TV_ITEM type objects and call function CTabCtrl::InsertItem(...) to add items.
24) The animate control can be used to play AVI data. Because this is not a standard resource supported in Developer Studio, we need to create custom resource if we want to include AVI data in an application as a resource.
25) The progress control is used to indicate the progress of events. In order to synchronize the progress bar with the events, we need to advance the progress bar within the event's message handler.
Page : << Previous 12