Table Of ContentProgrammer's Guide
Borland®
ObjectWindows®
Borland International, Inc., 100 Borland Way
P.O. Box 660001, Scotts Valley, CA 95067-0001
Borland may have patents and/or pending patent applications covering subject matter in this document. The
furnishing of this document does not give you any license to these patents.
COPYRIGHT © 1991, 1994 Borland International. All rights reserved. All Borland products are trademarks or
registered trademarks of Borland International, Inc. Other brand and product names are trademarks or registered
trademarks of their respective holders.
Printed in the U.S.A.
1EOR1094
9495969798-9 8 7 6 5 4 3 2
Hl
Contents
Introduction 1 Finding the object . . . . . . . . . . . . . . 17
Creating the minimum application . . . . . . . 17
ObjectWindows documentation . . . . . . . . . . 1
Initializing applications . . . . . . . . . . . . . . 18
Programmer's Guide organization. . . . . . 2
Constructing the application object . . . . . . . 18
Typefaces and icons used in this book . . . . . . 3 Using WinMain and OwlMain ......... 20
Calling initialization functions. . . . . . . . . . 21
Chapter 1
Initializing the application . . . . . . . . . . . 21
Overview of ObjectWindows 5 Initializing each new instance . . . . . . . . . 23
Initializing the main window. . . . . . . . . . 23
Working with class hierarchies ........... 5
Using a class ......................5 S~~~~~ ~h~ ~a~.~~~~~ ~~s~l~~ . . . . . 24
Deriving new classes ............... 5
Changing the main window . . . . . . . . . . 25
Mixing object behavior . . . . . . . . . . . . . . 6
Application message handling . . . . . . . . . . 25
Instantiating classes . . . . . . . . . . . . . . . . 6
Extra message processing. . . . . . . . . . . . . 25
Abstract classes . . . . . . . . . . . . . . . . . . . 7
Idle processing . . . . . . . . . . . . . . . . . . . 25
Inheriting members .................7
Types of member functions . . . . . . . . . . . . .8 Closing applications . . . . . . . . . . . . . . . . 26
Virtual functions . . . . . . . . . . . . . . . . . . 8 Changing closing behavior. . . . . . . . . . . . 26
Nonvirtual functions . . . . . . . . . . . . . . . 8 Closing the application . . . . . . . . . . . . . 26
Pure virtual functions . . . . . . . . . . . . . . . 9 Modifying CanClose . . . . . . . . . . . . . . . 26
Default placeholder functions . . . . . . . . . . 9 Using control libraries ............... 27
Object typology . . . . . . . . . . . . . . . . . . . . 9 Using the Borland Custom Controls
Window classes . . . . . . . . . . . . . . . . . . . 10 Library ....................... 27
Windows ..................... 10 Using the Microsoft 3-D Controls Library ... 28
Frame windows . . . . . . . . . . . . . . . . . 10
Chapter3
MDI windows . . . . . . . . . . . . . . . . . . 10
Decorated windows . . . . . . . . . . . . . . . 10 Interface objects 29
Dialog box classes . . . . . . . . . . . . . . . . . 10
Why interface objects? ............... 30
Common dialog boxes . . . . . . . . . . . . . 10
What do interface objects do? .......... 30
Other dialog boxes . . . . . . . . . . . . . . . . 11
The generic interface object: TWindow . . . . . 30
Control classes . . . . . . . . . . . . . . . . . . . 11
Standard Windows controls . . . . . . . . . . 11 Creating interface objects ............. 31
Widgets ...................... 11 When is a window handle valid? ........ 31
Gadgets ...................... 11 Making interface elements visible ........ 31
Decorations . . . . . . . . . . . . . . . . . . . . 11 Object properties. . . . . . . . . . . . . . . . . . 32
Graphics classes ................... 12 Window properties . . . . . . . . . . . . . . . . 32
DC classes . . . . . . . . . . . . . . . . . . . . . 12 Destroying interface objects . . . . . . . . . . . . 33
GDI objects . . . . . . . . . . . . . . . . . . . . 13 Destroying the interface element . . . . . . . . 33
Printing classes ................... 13 Deleting the interface object . . . . . . . . . . . 33
Module and application classes . . . . . . . . . 13
Parent and child interface elements . . . . . . . 34
Doc/View classes .................. 13
Child-window lists . . . . . . . . . . . . . . . . 34
Miscellaneous classes . . . . . . . . . . . . . . . 14
Constructing child windows . . . . . . . . . . . 34
Menus ....................... 14
Creating child interface elements . . . . . . . . 35
Clipboard . . . . . . . . . . . . . . . . . . . . . 14
Destroying windows . . . . . . . . . . . . . . . 36
Chapter 2 Automatic creation . . . . . . . . . . . . . . . . 37
Manipulating child windows . . . . . . . . . . 37
Application and module objects 15
Operating on all children: ForEach . . . . . . 37
The minimum requirements . . . . . . . . 16 Finding a specific child . . . . . . . . . . . . . 38
Including the header file .............. 16 Working with the child list ........... 38
Creating an object. . . . . . . . . . . . . . . . . . 16 Registering window classes . . . . . . . . . . . . 38
Calling the Run function. . . . . . . . . . . . . . 16
Chapter4 Constructing window objects . . . . . . . . . . 65
Event handling 39 Constructing window objects with
virtual bases . . . . . . . . . . . . . . . . . . . 66
Declaring response tables . . . 40 Setting creation attributes. . . . . . . . . . . . . 66
Defining response tables. . . . 40 Overriding default attributes . . . . . . . . . . 67
Child-window attributes . . . . . . . . . . . . 67
Defining response table entries. . . . 41
Creating window interface elements . . . . . . 68
Command message macros. . . . . . . . . . . . 43
Layout windows . . . . . . . . . . . . . . . . . . 69
Windows message macros . . . . . . . . . . . . 45
Child ID notification message macros ...... 46 Layout constraints . . . . . . . . . . . . . . . . . 70
EV_CHILD_NOTIFY .............. 46 Defining constraints . . . . . . . . . . . . . . . 70
EV_CHILD_NOTIFY_ALL_CODES ..... 47 Defining constraining relationships . . . . . . 73
EV_CHILD_NOTIFY_AND_CODE ..... 48 Indeterminate constraints . . . . . . . . . . . . 74
EV _CHILD_NOTIFY_AT_CHILD ...... 48 Using layout windows .............. 74
Frame windows . . . . . . . . . . . . . . . . . . . 75
Chapters Constructing frame window objects . . . . . . 76
Command enabling 49 Constructing a new frame window . . . . . . 76
Constructing a frame window alias . . . . . . . 77
Handling command-enabling messages . . 49 Modifying frame windows. . . . . . . . . . . . 78
Working with command-enabling objects ... 51 Decorated frame windows . . . . . . . . . . . . 78
ObjectWindows command-enabling objects . . 51 Constructing decorated frame window
TCommandEnabler: The command-enabling objects ....................... 79
interface . . . . . . . . . . . . . . . . . . . . . . 51 Adding decorations to decorated frame
Functions . . . . . . . . . . . . . . . . . . . . . 52 windows. ..................... 80
Data members . . . . . . . . . . . . . . . . . . 53
MDI windows .................... 80
Common command-enabling tasks . . . . . . . 53 MDI applications. . . . . . . . . . . . . . . . . . 81
Enabling and disabling command items . . . . 53 MDI Window menu . . . . . . . . . . . . . . . 81
Changing menu item text . . . . . . . . . . . . . 55 MDI child windows . . . . . . . . . . . . . . . 81
Toggling command items ............. 56 MDI in ObjectWindows . . . . . . . . . . . . . 81
Building MDI applications . . . . . . . . . . . . 82
Chapter6
Creating an MDI frame window. . . . . . . . 82
ObjectWindows exception handling 59 Adding behavior to an MDI client
window ..................... 83
ObjectWindows exception hierarchy . . . . . 59 Manipulating child windows . . . . . . . . 83
Working with TXBase ............... 60 Creating MDI child windows. . . . . . . . . . 83
Constructing and destroying TXBase . . . . . 60 Automatic child window creation . . . . . 83
Cloning exception objects. . . . . . . . . . . . 60 Manual child window creation . . . . . . . 84
Throwing TXBase exceptions . . . . . . .. . . 61
Working with TXOwl ............... 61 Chapters
Constructing and destroying TX Owl . . . . . 62 Menu objects 85
Cloning TXOwl and TXOwl-derived
exception objects . . . . . . . . . . . . . . . . 62 Constructing menu objects . 85
Specialized ObjectWindows exception Modifying menu objects . . . 86
classes. . . . . . . . . . . . . . . . . . . . . 62 Querying menu objects. . . . . . 86
ObjectWindows exception-handling Using system menu objects . . . . . . . . . . 87
macros . . . . . . . . . . . . . . . . . . . 63
Using pop-up menu objects . . . . . . . . . . 88
T~~1?b!e~~':~~~~s. e.x~e.p~~~s.o~ ..... 64 Using menu objects with frame windows. ... 89
Adding menu resources to frame windows . . 89
Macro expansion . . . . . . . . . . . . . . . . . . 64
Using menu descriptors . . . . . . . . . . . . . 90
Chapter 7 Creating menu descriptors . . . . . . . . . . . 92
Constructing menu descriptor objects. . . . . 93
Window objects 65
Creating menu groups in menu resources . . 93
Using window objects . . 65 Merging menus with menu descriptors. . . . 94
ii
Chapter9 Creating a document class. . . . . . . . . . . . 128
Dialog box objects 97 Constructing TDocument. . . . . . . . . . . . .129
Adding functionality to documents. . . . . . .129
Using dialog box objects. . . . . . . . . . . . . . 97 Data access functions . . . . . . . . . . . . . . .129
Constructing a dialog box object . . . . . . . . . 98 Stream access ...................1 30
Calling the constructor . . . . . . . . . . . . . 98 Stream list .....................1 30
Executing a dialog box. . . . . . . . . . . . . . . 98 Complex data access ...............1 30
Modal dialog boxes . . . . . . . . . . . . . . . 98 Data access helper functions ..........1 31
Modeless dialog boxes . . . . . . . . . . . . . 99 Closing a document. . . . . . . . . . . . . . . .131
Using autocreation with dialog boxes. . . . . 100 Expanding document functionality. . . . . . .132
Managing dialog boxes . . . . . . . . . . . . . 101 Working with the document manager . . . . .132
Handling errors executing dialog boxes . . . 101 Working with views ................1 32
Closing the dialog box . . . . . . . . . . . . . . 102
Creating a view class . . . . . . . . . . . . . . . 134
Using a dialog box as your main window . . 102 Constructing TView. . . . . . . . . . . . . . . .134
Manipulating controls in dialog boxes . . . . 103 Adding functionality to views . . . . . . . . . .134
Communicating with controls . . . . . . . . . 104 TView virtual functions .............1 35
Associating interface objects with Adding a menu ..................1 35
controls . . . . . . . . . . . . . . . . . . . . . . 104 Adding a display to a view. . . . . . . . . . . .135
Control objects . . . . . . . . . . . . . . . . . . 105 Adding pointers to interface objects ......1 35
Setting up controls . . . . . . . . . . . . . . . . 106 Mixing TView with interface objects .....1 36
Using dialog boxes . . . . . . . . . . . . . . . . 106 Closing a view . . . . . . . . . . . . . . . . . . .136
Using input dialog boxes . . . . . . . . . . . . 107 Doc/View event handling ............ 136
Using common dialog boxes . . . . . . . . . . 107 Doc/View event handling in the
Constructing common dialog boxes. . . . . . 107 application object . . . . . . . . . . . . . . . .137
Executing common dialog boxes . . . . . . . 108 Doc/View event handling in a view ......1 38
Using color common dialog boxes. . . . . . . 109 Handling predefined Doc/View events ...1 38
Using font common dialog boxes . . . . . . . 110 Adding custom view events ..........1 38
Using file open common dialog boxes. .... 111 Doc/View properties. . . . . . . . . . . . . . . 139
Using file save common dialog boxes . . . . . 112 Property values and names . . . . . . . . . . .140
Using find and replace common dialog Accessing property information. . . . . . . . .141
boxes ....................... 113 Getting and setting properties . . . . . . . . .141
Constructing and creating find and replace
common dialog boxes . . . . . . . . . . . . . 113 Chapter 11
Processing find-and-replace messages . . . . 113 Control objects 143
Handling a Find Next command ....... 114
Using printer common dialog boxes. . . . . . 115 Control classes . . . . . . . . . . . . . . . . . . . 143
What are control objects? . . . . . . . . . . . . .144
Chap!er 10 Constructing and destroying control
DocNiew objects 117 objects . . . . . . . . . . . . . . . . . . . . . . . 144
Constructing control objects . . . . . . . . . . .144
How documents and views work
together. . . . . . . . . . . . . . . . . . . 117 A!~:~!e.c~~~~l ~~j~~ :~~~e~ ~~~ ....l 4S
Documents. .................... 119 Calling control object constructors .......1 45
Views ........................ 119 Changing control attributes. . . . . . . . . . .146
Associating document and view classes . . . 120 Initializing the control ..............1 46
Managing Doc/View . . . . . . . . . . . . . . 120 Showing controls. . . . . . . . . . . . . . . . . .146
Document templates . . . . . . . . . . . . . . . 121 Destroying the control . . . . . . . . . . . . . .146
Designing document template classes. . . . . 121 Communicating with control objects . . . . . 147
Creating document registration tables . . . . 122 Manipulating controls. . . . . . . . . . . . . . .147
Creating template class instances . . . . . . . 123 Responding to controls . . . . . . . . . . . . . .147
Modifying existing templates .......... 125 Making a window act like a dialog box . . . .147
Using the document manager . . . . . . . . . 125 Using particular controls. . . . . . . . . . . . . 147
Constructing the document manager . . . . . 126 Using list box controls. . . . . . . . . . . . . . .148
TDocManager event handling . . . . . . . . . 127 Constructing list box objects ..........1 48
iii
Moclifying list boxes . . . . . . . . . . . . . . . 148 Supporting transfer for customized
Querying list boxes . . . . . . . . . . . . . . . 149 controls. . . . . . . . . . . . . . . . . . . . . .169
Responding to list boxes . . . . • . . . . . . . 149
Chapter 12 ·
Using static controls . . . . . . . . . . . . . . . 150
Constructing static control objects. . . . . . . 150 Gadget and gadget window objects 171
Modifying static controls . . . . . . . . . . . . 151
Gadgets . . . . . . . . . . . . . . . . . . . . . . . 171
Querying static controls. . . . . . . . . . . . . 151
Class TGadget ...................1 71
Using button controls . . . . . . . . . . . . . . 151
Constructing and destroying TGadget ....1 71
Constructing buttons . . . . . . . . . . . . . . 151
Identifying a gadget . . . . . . . . . . . . . . .172
Responding to buttons . . . . . . . . . . . . . 152
Modifying and accessing gadget
Using check box and radio button
appearance . . . . . . . . . . . . . . . . . . .173
controls . . . . . . . . . . . . . . . . . . . . . . 152
Bounding the gadget ...............1 73
Constructing check boxes and radio
Shrink wrapping a gadget. ...........1 73
buttons. . . . . . . . . . . . . . . . . . . . . .153
Setting gadget size ................1 74
Modifying selection boxes . . . . . . . . . . . 153
Matching gadget colors to system colors ...1 74
Querying selection boxes . . . . . . . . . . . . 154
TGadget public data members .........1 74
Using group boxes . . . . . . . . . . . . . . . . 154
Enabling and disabling a gadget. .......1 74
Constructing group boxes . . . . . . . . . . . 154
Deriving from TGadget. . . . . . . . . . . . . .175
Grouping controls . . . . . . . . . . . . . . . . 154
Initializing and cleaning up ...........1 75
Responding to group boxes . . . . . . . . . . 155
Painting the gadget. ...............1 75
Using scroll bars . . . . . . . . . . . . . . . . . 155
Invalidating and updating the gadget. ....1 76
Constructing scroll bars . . . . . . . .. . . . . . 155
Mouse events in a gadget ............1 76
Controlling the scroll bar range . . . . . . . . 155
Controlling scroll amounts . . . . . . . . . . . 156 ObjectWindows gadget classes . . . . . . . . . 177
Querying scroll bars . . . . . . . . . . . . . . . 156 Class TSeparatorGadget .............1 78
Modifying scroll bars . . . . . . . . . . . . . . 156 Class TTextGadget. ................1 78
Responding to scroll-bar messages . . . . . . 156 Constructing and destroying
Av oiding thumb tracking messages . . . 157 TTextGadget. . . . . . . . . . . . . . . . . . .178
Specializing scroll bar behavior . . . . . . 157 Accessing the gadget text ............1 78
Using sliders and gauges . . . . . . . . . . . . 158 Class TBitmapGadget. . . . . . . . . . . . . . .179
Using edit controls . . . . . . . . . . . . . . . . 159 Constructing and destroying
TBitmapGadget. . . . . . . . . . . . . . . . .179
Constructing edit controls . . . . . . . . . . . 159
Selecting a new image ..............1 79
Using the Clipboard and the Edit menu . . .160
Setting the system colors ............1 79
Querying edit controls. . . . . . . . . . . . . .160
Class TButtonGadget . . . . . . . . . . . . . . .180
Modifying edit controls . . . . . . . . . . . . . 161
Constructing and destroying
Using combo boxes. . . . . . . . . . . . . . . . 162
TButtonGadget .................1 80
Varieties of combo boxes . . . . . . . . . . . . 162
Accessing button gadget information .....1 81
Choosing combo box types. . " . . . . . . . .163
Setting button gadget style ...........1 81
Constructing combo boxes . . . . . . . . . . . 163
Command enabling ...............1 82
Modifying combo boxes . ; . . . . . . . . . .164
Setting the system colors . . . . . . . . . . . .182
Querying combo boxes . . . . . . . . . . . . . 164
Class TControlGadget. . . . . . . . . . . . . . .182
Setting and reading control values. . . . . . . 164
Constructing and destroying
Using transfer buffers . . . . . . . . . . . . . . 164 TControlGadget ................1 82
Defining the transfer buffer . . . . . . . . . . . 165
Gadget windows . . . . . . . . . . . . . . . . . 182
List box transfer . . . . . . . . . . . . . . . . . 166
Constructing and destroying ·
Combo box transfer . . . . . . . . . . . . . . . 167 TGadgetWindow ................1 83
Defining the correspondillg window or Creating a gadget window . . . . . . . . . . .183
dialog box . . . . . . . . . . . . . . . . . . . . 167
Inserting a gadget into a gadget window. . .183
Using transfer with a dialog box. . . . . . . .168
Re~oving a gadget from a gadget
Using transfer with a window . . . . . . . . . 168 wmdow .....................1 84
Transferring the data. . . . . . . . . . . . . . . 168 Set?ng ~dow margins and layout ·
Transferring data to a window. ........ 168 drrection .....................1 84
Transferring data from a dialog box. . . . . .169 Laying out the gadgets .............1 84
Transferring data from a window. . . . . . .169 · Notifying ~e window when a gadg~t
changes size ...................1 85
iv
Shrink wrapping a gadget window . . . . . . 185 Drawing attribute functions . . . . . . . . . .209
Accessing window font . . . . . . . . . . . . . 186 Viewport and window mapping
Capturing the mouse for a gadget. . . . . . . 186 functions . . . . . . . . . . . . . . . . . . . . .210
Setting the hint mode . . . . . . . . . . . . . . 186 Coordinate functions. . . . . . . . . . . . . . .210
Idle action processing . . . . . . . . . . . . . . 187 Clip and update rectangle and region
Searching through the gadgets ......... 187 £Unctions . . . . . . . . . . . . . . . . . . . . .210
Deriving from TGadgetWindow. . . . . . . . 187 Metafile functions . . . . . . . . . . . . . . . .210
Painting a gadget window . . . . . . . . . . . 187 Current position functions . . . . . . . . . . .210
Size and inner rectangle. . . . . . . . . . . . . 188 Font functions. . . . . . . . . . . . . . . . . . .211
Layout units. . . . . . . . . . . . . . . . . . . . 188 Path functions. . . . . . . . . . . . . . . . . . .211
Message response functions . . . . . . . . . . 189 Output functions . . . . . . . . . . . . . . . . .211
Object data members and functions . . . . . .213
ObjectWindows gadget window classes . . . 189
Class TControlBar . . . . . . . . . . . . . . . . 189 TPen class. . . . . . . . . . . . . . . . . . . . . . 213
Class TMessageBar ................ 190 Constructing TPen. . . . . . . . . . . . . . . . .213
Constructing and destroying Accessing TPen. . . . . . . . . . . . . . . . . . .215
TMessageBar . . . . . . . . . . . . . . . . . . 190 TBrush class . . . . . . . . . . . . . . . . . . . . 215
Setting message bar text. . . . . . . . . . . . . 190 Constructing TBrush . . . . . . . . . . . . . . .215
Setting the hint text . . . . . . . . . . . . . . . 190 Accessing TBrush . . . . . . . . . . . . . . . . .216
Class TStatusBar . . . . . . . . . . . . . . . . . 191 TFont class . . . . . . . . . . . . . . . . . . . . . 217
Constructing and destroying TStatusBar. . . 191 Constructing TFont . . . . . . . . . . . . . . ..2 17
Inserting gadgets into a status bar. . . . . . . 191
Accessing TFont . . . . . . . . . . . . . . . . . .218
Displaying mode indicators . . . . . . . . . . 191
TPalette class. . . . . . . . . . . . . . . . . . . . 218
Spacing status bar gadgets . . . . . . . . . . . 192
Constructing TPa:lette . . . . . . . . . . . . . . .218
Class TToolBox .................. 192
Constructing and destroying TToolBox . . . i92 Accessing TPa:lette. . . . . . . . . . . . . . . . .219
Member functions . . . . . . . . . . . . . . . .219
Changing tool box dimensions. . . . . . . . . 193
Extending TPalette. . . . . . . . . . . . . . . . .220
Chapter 13 TBitmap class . . . . . . . . . . . . . . . . . . . 221
Printer objects 195 Constructing TBitmap. . . . . . . . . . . . . . .221
Accessing TBitmap . . . . . . . . . . . . . . . .222
Creating a printer object . . . . . . . . . . . 195 Member functions . . . . . . . . . . . . . . . .223
Creating a printout object . . . . . . . 197 Extending TBitmap . . . . . . . . . . . . . . . .224
Printing window contents ............ 198 TRegion class . . . . . . . . . . . . . . . . . . . 224
Printing a document . . . . . . . . . . . . . . . 199 Constructing and destroying TRegion . . . . .224
Setting print parameters. . . . . . . . . . . . . 199 Accessing TRegion. . . . . . . . . . . . . . . . .226
Counting pages . . . . . . . . . . . . . . . . . . 199 Member functions . . . . . . . . . .. _. . . . .226
Printing each page . . . . . . . . . . . . . . . . 200 Operators . . . . . . . . . . . . . . . . . . . . .227
Indicating further pages . . . . . . . . . . . . . 200 Tlcon class . . . . . . . . . . . . . . . . . . . . . 229
Other printout considerations . . . . . . . . . 200 Constructing Tlcon . . . . . . . . . . . . . . . .229
Choosing a different printer. .......... 201 Accessing Tlcon . . . . . . . . . . . . . . . . . .230
TCursor class. . . . . . . . . . . . . . . . . . . . 231
Chapter 14
Constructing TCursor. . . . . . . . . . . . . . .231
Graphics objects 203 Accessing TCursor. . . . . . . . . . . . . . . . .232
TDib class. . . . . . . . . . . . . . . . . . . . . . 232
GDI class organization. . . . . . . . . . . . . 203
Constructing and destroying TDib . . . . . . .233
Changes to encapsulated GDI functions . . . 204 -
Accessing TDib. . . . . . . . . . . . . . . . . . .234
Working with device contexts . . . . . . . . . 206 Type conversions . . . . . . . . . . . . . . . . .234
TDC class . . . . . . . . . . . . . . . . . . . . . 206 Accessing internal structures . . . . . . . . . .234
Constructing and destroying TDC . . . . . . 207 DIB information . . . . . . . . . . . . . . . . .235
Device-context operators . . . . . . . . . . . . 207 Working in palette or RGB mode .......2 35
Device-context functions . . . . . . . . . . . . 208 Matching interface colors to system
Selecting and restoring GDI objects . . . . . . 208 colors .......................2 37
Drawing tool functions . . . . . . . . . . . . . 209 Extending TDib . . . . . . . . . . . . . . . . . .237
Color and palette functions. . . . . . . . . . . 209
v
Chapter 15 The TModule object. . . . . . . . . . . . . . . . 259
Validator objects 239 Using ObjectWindows asa DLL ........ 260
Calling an ObjectWindows DLL from a
The standard validator classes . . . . . . . . . 239
non-ObjectWindows application . . . . . . . 260
Validator base class ................ 240
Implicit and explicit loading. . . . . . . . . . . 261
Filter validator class . . . . . . . . . . . . . . . 240
Mixing static and dynamic-linked libraries. . 261
Range validator class. . . . . . . . . . . . . . . 240
Lookup validator class. . . . . . . . . . . . . . 240 Chapter 18.
String lookup validator class . . . . . . . . . . 241
Support for OLE in Borland C++ 263
Picture validator class .............. 241
Using data validatdrs. . . . . . . . . . . . . . . 242 What does ObjectComponents do? ...... 263
Constructing an edit control object. . . . . . . 242 Where should you start? ............. 264
Constructing and assigning validator Writing applications ................2 64
objects. . . . . . . . . . . . . . . . . . . . . . . 242 Creating a new application . . . . . . . . . . .264
Overriding validator member functions . . . 243 Converting an application into an OLE
Member function Valid ............. 243 container . . . . . . . . . . . . . . . . . . . . .264
Member function IsValid ............ 243 Converting application into a linking and
Member function IsValidlnput. ........ 243 embeddfug server . . . . . . . . . . . . . . .265
Member function Error . . . . . . . . . . . . . 244 Adding automation support . . . . . . . . . .265
Other useful topics . . . . . . . . . . . . . . . .265
Chapter 16 Leaming about ObjectComponents. . . . . . .265
Visual Basic controls 245 What is OLE? . . . . . . . . . . . . . . . . . . . 266
Linking and embedding . . . . . . . . . . . . .266
Using VBX controls ................ 245 Automation. . . . . . . . . . . . . . . . . . . . .267
VBX control classes. . . . . . . . . . . . . . . . 246 What does OLE look like? . . . . . . . . . . . . 267
TVbxControl class . . . . . . . . . . . . . . . . 246 Inserting an object . . . . . . . . . . . . . . . . .268
TVbxControl constructors . . . . . . . . . . . 247 Editing an object in place . . . . . . . . . . . . .269
Implicit and explicit construction . . . .... 248
Activating, deactivating, and selecting an .
TVbxEventHandler class . . . . . . . . . . . . 249 . object ........................2 71
Handling VBX control messages. . . . . . . . 249 Finding an object's verbs .............2 72
Event response table . . . . . . . . . . . . . . . 249 Linking an object ..................2 73
Interpreting a control event . . . . . . . . . . . 250 Opening an object to edit it ............2 74
Finding event information . . . . . . . . . . . 251 What is ObjectComponents? . . . . . . . . . . 275
Accessing a VBX control. . . . . . . . . . . . . 251 OLE 2 features supported by
VBX control properties. . . . . . . . . . . . . . 251 ObjectComponents . . . . . . . . . . . . . . .276
Finding property information . . . . . . . . . 252 Using ObjectComponents . . . . . . . . . . . . 278
Getting control properties . . . . . . . . . . . 252 Overview of classes and messages . . . . . . .278
Setting control properties . . . . . . . . . . . . 253 Linking and embedding classes . . . . . . . .279
VBX control methods . . . . . . . . . . . . . . 253 Connector objects. . . . . . . . . . . . . . . . .279
Automation classes. . . . . . . . . . . . . . . .280
Chapter 17
ObjectComponents messages. . . . . . . . ..2 81
ObjectWindows dynamic-link Messages and windows . . . . . . . . . . . . .283
libraries 255 New ObjectWindows OLE classes. . . . . . .283
Exception handling in ObjectComponents. . .284
Writing DLL functions. . . . . . . . . . . . . . 255 TXOle and OLE error codes. . . . . . . . . . .285
DLL entry and exit functions . . . . . . . . . . 256 Building an ObjectComponents ·
LibMain . . . . . . . . . . . . . . . . . . . . . . 256 application . . . . . . . . . . . . . . . . . . . .286
WEP ........................ 256 Distributing files with your application . . . .287
DllEntryPoint . . . . . . . . . . . . . . . . . . . 257 How ObjectComponents works . . . . . · . . . 287
Exporting DLL functions . . . . . . . . . . . . 257 How ObjectComponents talks to OLE . . . . .287
Importing (calling) DLL functions ....... 257 How ObjectComponents talks to you . . . . .288
Writing shared ObjectWindows classes. . . . 258 Linking and embedding connections. . . . . .288
Defining shared classes . . . . . . . . . . . . . 258 Automation connections . . . . . . . . . . . . .291
vi
ObjectComponents Programming Tools . . . 292 1. Registering a container. . . . . . . . . . . . .329
Utility programs . . . . . . . . . . . . . . . . . 292 Building a registration table. . . . . . . . . . .330
Where do Ilook for information? ....... 293 Creating the registrar object. . . . . . . . . . .330
Creating a memory allocator . . . . . . . . . .331
Books ........................ 293
2. Creating a view window. . . . . . . . . . . .332
Online Help . . . . . . . . . . . . . . . . . . . . 294
Example programs . . . . . . . . . . . . . . . . 294 Cr~ating,. resizing, and destroying the
view wmdow . . . . . . . . . . . . . . . . ..3 32
Glossary of OLE terms . . . . . . . . . . . . . . 295
Creating a TOcDocument and TOcView ...3 33
Handling WM_OCEVENT ...........3 34
Chapter 19
Handling selected view events . . . . . . . . .335
Creating an OLE container 303
Painting the document. . . . . . . . . . . . . .335
Activating and deactivating objects . . . . . .337
Turnillg a Doc/View application into an
3. Programming the main window . . . . . . .337
OLE container . . . . . . . . . . . . . . . . . . 303
Creating the main window . . . . . . . . . . .337
1. Connecting objects to OLE . . . . . . . . . . 304
Handling WM_O CEVENT . . . . . . . . . . .337
Deriving the application object from
TOcModule . . . . . . . . . . . . . . . . . . . 304 Handling selected application events . . . . .338
Inheriting from OLE classes . . . . . . . . . . 305 Handling standard OLE menu
commands. . . . . . . . . . . . . . . . . . . .338
Creating an application dictionary ...... 306
Building the program . . . . . . . . . . . . . . .339
2. Registering a container . . . . . . . . . . . . 306
Including ObjectComponents headers . . . .339
Building registration tables. . . . . . . . . . . 307
Compiling and linking. . . . . . . . . . . . . .340
Understanding registration macros . . . . . . 309
Creating a registrar object ............ 310 Chapter20
3. Supporting OLE commands ......... 311
Creating an OLE server 341
Settin~ up the Edit menu and the
tool ar ...................... 312
Turnillg a Doc/View application into an
Loading and saving compound
OLE server . . . . . . . . . . . . . . . . . . . . 341
documents .................... 312
1. Connecting objects to OLE ...........3 42
4. Building the container. . . . . . . . . . . . . 313
Creating an application dictionary .......3 42
Including OLE headers ............. 314
Deriving the application object from
Compiling and linking . . . . . . . . . . . . . 314
TOcModule ...................3 43
Turnillg an ObjectWindows application Inheriting from OLE classes. . . . . . . . . . .344
into an OLE container . . . . . . . . . . . . . 315 2. Registering a linking and embedding
1. Setting up the application. .......... 316 server .......................3 44
Defining an application dictionary object .. 316 Building registration tables . . . . . . . . . . .344
Modifying your application class ....... 316 Creating a registrar object . . . . . . . . . . . .347
2. Registering a container ............ 317 Processing the command line. . . . . . . . . .349
Creating registration tables ........... 317 3. Drawing, loading, and saving objects ....3 50
Creating a registrar object ............ 318 Telling clients when an object changes ....3 50
3. Setting up the client window ......... 319 Loading and saving the server's
Inheriting from OLE classes . . . . . . . . . . 320 documents. . . . . . . . . . . . . . . . . . . .351
Delaying the creation of the client 4. Building the server ...............3 51
window in SDI applications . . . . . . . . . 320 Including OLE headers . . . . . . . . . . . . .351
Creating ObjectComponents view and Compiling and linking. . . . . . . . . . . . . .352
document objects. . . . . . . . . . . . . . . . 321
Turnillg an ObjectWindows application
4. Programming the user interface . . . . . . . 322
into an OLE server . . . . . . . . . . . . . . . 352
Handling OLE-related messages and
1. Registering the server . . . . . . . . . . . . .353
events ...................... 322
Creating an application dictionary .......3 53
Supporting menu merging . . . . . . . . . . . 324
Creating registration tables . . . . . . . . . . .353
Updating the Edit menu . . . . . . . . . . . . 327
Creating the document list . . . . . . . . . . .355
Assigning a tool bar ID . . . . . . . . . . . . . 328
Creating the registrar object. . . . . . . . . . .355
5. Building a container . . . . . . . . . . . . . . 328
2. Setting up the client window . . . . . . . . .356
Including OLE headers . . . . . . . . . . . . . 328
Creating helper objects for a document . . . .356
Compiling and linking . . . . . . . . . . . . . 328
3. Modifying the application class ........3 57
Turnillg a C ++ application into an OLE
container . . . . . . . . . . . . . . . . . . . . . 328
vii