WTL for MFC Programmers
WTL for MFC Programmers
WTL for MFC Programmers
1
Contents
About the Author .............................................................................................................................. 5
Part I - ATL GUI Classes ...................................................................................................................... 6
Introduction to the Series ......................................................................................................... 7
Introduction to Part I ................................................................................................................. 8
ATL Background ......................................................................................................................... 9
ATL and WTL history .......................................................................................................... 9
ATL-style templates ........................................................................................................... 9
ATL Windowing Classes ........................................................................................................... 12
Defining a Window Implementation ....................................................................................... 12
Filling in the message map .............................................................................................. 14
Advanced Message Maps and Mix-in Classes ......................................................................... 16
Structure of an ATL EXE ........................................................................................................... 18
In VC 6 ............................................................................................................................. 18
In VC 7 ............................................................................................................................. 20
Dialogs in ATL .......................................................................................................................... 22
I'll Get to WTL, I Promise!........................................................................................................ 25
Part II - WTL GUI Base Classes ......................................................................................................... 26
Introduction to Part II .............................................................................................................. 26
WTL Overview ......................................................................................................................... 26
Beginning a WTL EXE ............................................................................................................... 26
WTL Message Map Enhancements ......................................................................................... 29
What You Get with the WTL AppWizard ................................................................................. 34
Going through the wizard (VC 6) ..................................................................................... 34
Going through the wizard (VC 7) ..................................................................................... 36
Examining the generated code ........................................................................................ 38
CMessageLoop Internals ......................................................................................................... 40
CFrameWindowImpl Internals ................................................................................................ 41
Back to the Clock Program ...................................................................................................... 42
UI Updating ............................................................................................................................. 43
New menu items to control the clock ............................................................................. 44
Calling UIEnable() ............................................................................................................ 45
One Last Note on Message Maps ............................................................................................ 47
Next Stop, 1995 ....................................................................................................................... 48
Part III - Toolbars and Status Bars .................................................................................................... 49
Introduction to Part III ............................................................................................................. 49
Toolbars and Status Bars in a Frame ....................................................................................... 49
AppWizard Code for Toolbars and Status Bars ........................................................................ 50
How CMainFrame creates the bars ................................................................................. 52
Showing and hiding the bars ........................................................................................... 55
Built-in features of the bars ............................................................................................ 56
Creating a toolbar with a different style ......................................................................... 57
WTL for MFC Programmers
2
The Toolbar Editor ................................................................................................................... 57
UI Updating Toolbar Buttons ................................................................................................... 59
Enabling toolbar UI updating .......................................................................................... 59
Using a Rebar Instead of a Plain Toolbar ................................................................................. 60
Multi-Pane Status Bars ............................................................................................................ 63
UI updating the panes ..................................................................................................... 64
Up Next: All About Dialogs ...................................................................................................... 66
References ............................................................................................................................... 66
Part IV - Dialogs and Controls .......................................................................................................... 67
Introduction to Part IV ............................................................................................................ 67
Refresher on ATL Dialogs ......................................................................................................... 67
Control Wrapper Classes ......................................................................................................... 67
Creating a Dialog-Based App with the AppWizard .................................................................. 68
Using the Control Wrapper Classes ......................................................................................... 72
ATL Way 1 - Attaching a CWindow .................................................................................. 72
ATL Way 2 - CContainedWindow ..................................................................................... 72
ATL Way 3 - Subclassing ................................................................................................... 76
WTL Way 1 - DDX_CONTROL ........................................................................................... 78
WTL Way 2 - DDX_CONTROL_HANDLE ............................................................................ 80
More on DDX ........................................................................................................................... 80
DDX macros ..................................................................................................................... 81
More about DoDataExchange() ....................................................................................... 82
Using DDX ........................................................................................................................ 82
Handling Notifications from Controls ...................................................................................... 86
Handling notifications in the parent ............................................................................... 86
Reflecting Notifications ................................................................................................... 88
Odds & Ends ............................................................................................................................ 91
Dialog Fonts ..................................................................................................................... 91
_ATL_MIN_CRT ................................................................................................................ 92
Up Next ................................................................................................................................... 92
Part V - Advanced Dialog UI ............................................................................................................ 93
Introduction to Part V ............................................................................................................. 93
Specialized Owner Draw and Custom Draw Classes ............................................................... 93
COwnerDraw ................................................................................................................... 93
CCustomDraw .................................................................................................................. 97
New WTL Controls ................................................................................................................... 98
CBitmapButton ................................................................................................................ 98
CCheckListViewCtrl ........................................................................................................ 101
CTreeViewCtrlEx and CTreeItem .................................................................................... 103
CHyperLink .................................................................................................................... 104
UI Updating Dialog Controls .................................................................................................. 108
DDV ....................................................................................................................................... 110
Handling DDV failures ................................................................................................... 112
Resizing Dialogs ..................................................................................................................... 113
WTL for MFC Programmers
3
Up Next ................................................................................................................................. 113
References ............................................................................................................................. 113
Part VI - Hosting ActiveX Controls ................................................................................................. 115
Introduction .......................................................................................................................... 115
Starting with the AppWizard ................................................................................................. 115
Creating the project ...................................................................................................... 115
The generated code ...................................................................................................... 117
Adding Controls with the Resource Editor ............................................................................ 118
ATL Classes for Control Hosting ............................................................................................. 120
CAxDialogImpl ............................................................................................................... 120
AtlAxWin and CAxWindow ............................................................................................ 121
Calling the Methods of a Control .......................................................................................... 121
Sinking Events Fired by a Control .......................................................................................... 122
Adding handlers in VC 6 ................................................................................................ 122
Adding handlers in VC 7 ................................................................................................ 125
Advising for events ........................................................................................................ 126
Overview of the Sample Project............................................................................................ 127
Creating an ActiveX Control at Run Time .............................................................................. 129
Keyboard Handling ................................................................................................................ 132
Up Next ................................................................................................................................. 133
Part VII - Splitter Windows ............................................................................................................ 134
Introduction .......................................................................................................................... 134
WTL Splitter Windows ........................................................................................................... 134
Classes ........................................................................................................................... 134
Creating a splitter .......................................................................................................... 135
Basic methods ............................................................................................................... 135
Data members ............................................................................................................... 138
Starting the Sample Project .................................................................................................. 138
Creating windows in the panes ............................................................................................. 142
Effects of WS_EX_CLIENTEDGE ..................................................................................... 144
Message Routing ................................................................................................................... 146
Pane Containers .................................................................................................................... 147
Classes ........................................................................................................................... 147
Basic methods ............................................................................................................... 147
Using a pane container in a splitter window ................................................................. 149
The Close button and message handling ...................................................................... 150
Advanced Splitter Features ................................................................................................... 150
Nested splitters ............................................................................................................. 150
Using ActiveX controls in a pane ................................................................................... 152
Special drawing ............................................................................................................. 153
Special Drawing in Pane Containers ...................................................................................... 154
Bonus: Progress Bar in the Status Bar ................................................................................... 156
Up Next ................................................................................................................................. 157
References ............................................................................................................................. 157
WTL for MFC Programmers
4
Part VIII - Property Sheets and Wizards ........................................................................................ 158
Introduction .......................................................................................................................... 158
WTL Property Sheet Classes .................................................................................................. 158
CPropertySheetImpl methods ....................................................................................... 158
WTL Property Page Classes ................................................................................................... 160
CPropertyPageWindow methods .................................................................................. 161
CPropertyPageImpl methods ........................................................................................ 162
Handling notification messages .................................................................................... 163
Creating a Property Sheet ..................................................................................................... 164
The simplest property sheet, ever ................................................................................ 164
Creating a useful property page .................................................................................... 165
Creating a better property sheet class .......................................................................... 168
Creating a Wizard .................................................................................................................. 169
Adding More Pages, Handling DDV ............................................................................... 172
Other UI Considerations ........................................................................................................ 175
Centering a sheet .......................................................................................................... 175
Adding icons to pages ................................................................................................... 176
Up Next ................................................................................................................................. 177
Part IX - GDI Classes, Common Dialogs, and Utility Classes .......................................................... 178
Introduction .......................................................................................................................... 178
GDI Wrapper Classes ............................................................................................................. 178
Common functions in the wrapper classes ................................................................... 179
Using CDCT .................................................................................................................... 181
Differences from the MFC wrapper classes................................................................... 182
Resource-Loading Functions ................................................................................................. 183
Using Common Dialogs ......................................................................................................... 186
CFileDialog ..................................................................................................................... 188
CFolderDialog ................................................................................................................ 191
Other useful classes and global functions ............................................................................. 193
Struct wrappers ............................................................................................................. 193
Classes for handling dual-typed arguments .................................................................. 194
Other utility classes ....................................................................................................... 194
Global functions ............................................................................................................ 197
Macros ........................................................................................................................... 198
The Sample Project ............................................................................................................... 200
- 1
- 2
前往页