Table of Contents

preface xv

about this book xix

acknowledgments xxvi

A brief recap of OWL 1

HELLO.EXE 2

HELLO as a C/SDK app 3

WinMain 4, The message loop 6, WndProc 7

HELLO as an OWL app 8

OwlMain 9, TOWLHelloApp 9, TOWLHelloWindow 9, What HELLO.CPP provides without asking 10

Where'd everything go? 10

The wonders of encapsulation 11, The power of inheritance 13

The fundamental components of OWL 14

TWindow 15, TFrameWindow 15, TDialog 16, TApplication and TModule 16

What else is left to add? 16

Where do we go from here? 18

The OWL Support Systems 19

ClassLib 20

OBSOLETE 21, Containers 21, Iterator objects versus iteration methods 33, BIDS Iterators 36, Allocators 37, Containers, in conclusion 38, Date and time 38, TFileName 40, Some flaws with TFileName 44, TFileNameIterator 45, TFile 47, Smart pointers 49, TPointer 50, TAPointer 51, TEnvelope 52, TAEnvelope 53, TVoidPointer 53, Why on Earth should I use TPointer<T> or TAPointer<T> instead of T*? 54, When do TEnvelope and TAEnvelope make sense? 56, Shortcomings of smart pointers 58, TCmdLine 60, TFixedPoint 64, THeapSelector 65

WinSys 70

Registry and Profile support 70, GUI geometry 73, Color and color support 75, System support 76, TUIMetric 77, TResId 78, TDropInfo and TFileDroplet 78, TProcInstance 78, TResource 79, Strings 79, BIDS and the STL/Std C++ Library 81, Other libs--VDBT and OCF 81

Conclusion 84

Mixins 85

Conceptual overview: Mixin theory 86

OWL Mixins 89

TEventHandler 91, TRecentFiles 92, TSerializeReceiver 96, TClipboardViewer 103

OWL Decorators 104

TPictDecorator 106

Conclusion 112

Help! 113

The online Help file 114

Why help the user? 114, Ways to help the user before a Help file 115

WinHelp--an overview 118

Creating a Help file 119

The Help Project (.HPJ) file 119, The content (.RTF) files 121, Topics 122, Context strings and topic titles 122, Hyperlinks 123, INDEX/CONTENTS 124, Browse sequences 125, Help keywords 126, Bitmaps and hotspot bitmaps 128, WinHelp macros 130, Creating a help file--newer ways 132

Interacting with your Help file 132

The WinHelp API call 132, Loading the WinHelp file 133, Calling a macro from an application 134, Look up a topic based on a keyword 134, Closing the WinHelp file 135

OWL Help supports THelpFileManager 135

Usage 135

The future of WinHelp 140

Conclusion 141

Multithreaded OWL 143

What is a thread? 144

Why threads? 144, Why not threads? 145

Win32 threads 147

The Win32 Thread API 148

OWL threads (TThread) 153

TThread API overview 157

TGenericThread: generic thread objects 160

Thread synchronization 161

Win32 synchronization objects and their BIDS equivalents 163, Mutual exclusion objects/TMutex 164, Critical sections/TCriticalSection 168, Semaphores/TCountedSemaphore 170, Events/TEventSemaphore 172, Other BIDS synchronization objects 174, Thread-local storage (TLS) 177, Win32 atomic methods 183

TMsgThread: user-interface threads 186

Conclusion 187

Menus 189

The menubar 190

The menubar--a quick recap 190, One step beyond the basics 191

OWL menu objects 192

TMenu 193, TSystemMenu 197, TPopupMenu 198

Various menu tricks 199

Bitmaps in menus 199, Owner-drawn menus 201, Dialogs with menubars 202, Windows 4.0 shell enhancements 202

Dynamic menu management 203

Manipulating a menu's contents, the hard way 204, Manipulating a menu's contents, the easier way (TMenuDescr) 205

Conclusion 209

Miscellaneous OWL classes 211

Error mode support (TErrorMode) 212

Clipboard support (TClipboard) 216

Basic usage 216, Who's got the clipboard? 218, The implications of owning the clipboard 220, Clipboard formats 221, Same data, different formats 222, Delayed rendering 225, Owner-display format 226, Reading from the clipboard 228, Clipboard viewer windows 229, TClipboard API 231, The clipboard as an IPC mechanism 233

MCI support (TMci) 234

Basic usage 235

UI painting made easy 236

TUIBorder 237, TUIFace 241, TUIHandle 244, TUIPart 245, Other UI classes 247

Conclusion 248

OWL Doc/View architecture 249

The pieces of Doc/View 250

Model/View/Controller--the theory 251

Doc/View and Observer 253

Doc/View == MDI? 254, Doc/View from orbit 255

Documents (TDocument) 255

Data-access methods: Open, Close, Commit, Revert, and the rest 260, Streams 264, Parent and child documents 269, Views and view management 270, Document templates and the document manager 273, Everything that's left--miscellaneous TDocument methods 273, Examples of TDocument in OWL 5.0: TFileDocument 274, Examples of TDocument in OWL 5.0: TStorageDocument 275, Examples of TDocument in OWL 5.0: TOleDocument 276

Views (TView) 276

TView IDs and TView ID management 279, Doc/View events and event-handling 279, Interaction in the OWL window system 281, Examples of TView in OWL 5.0: TEditView 281, Examples of TView in OWL 5.0: TListView 281, Examples of TView in OWL 5.0: TWindowView 282, Ideas for derived TView objects 282

TDocManager and TDocTemplate 282

TDocManager 283, TDocTemplate and TDocTemplateT 296

Properties 302

Putting it all together 309

Starting the application 315, Opening a document 318, Saving the document 324

Conclusion 329

Debugging, exceptions, and error support 331

Assert yourself 332

Tracing application execution without a debugger 334

Ye olde MessageBox trick (formerly ye olde printf trick) 334, Ye olde MessageBeep trick 337, Logging to controls and windows 338, Logging to a file 339, Logging to OutputDebugString 340, Logging to more than one place at a time: tee streams 342, In summary 343

OWL's diagnostic macros 344

OWL.INI 349, Guidelines for using the trace mechanism effectively 350, The other diagnostic macros: CHECK and PRECONDITION 352

Post-mortem tools: Dr. Watson and WinSpector 353

Why do I need a post-mortem tool? 354, How to read Dr. Watson's Win32 autopsy report 354, But I don't have Dr. Watson32 358

Exception handling 361

Disabling exceptions 362

C++ exception handling mechanics 362, ANSI C++'s Exceptions 364, Borland's exceptions 370, OWL's exceptions 372, Exceptions in your code 394, Tips and suggestions 395

Win16 exceptions and Win32 structured exception handling 397

The nature of an error 397, 16-bit fault trapping (TOOLHELP.DLL) 398, 32-bit Fault Trapping (SEH) 402

Conclusion 408

Integrated OWL 409

C 411

Delphi 413

Variable type mappings and calling conventions 414, Calling functions in a DLL 415, Linking C++ code into a Delphi .EXE 415, Linking Delphi code into a C++ .EXE 417, Using a C++ class in Delphi from a .DLL 418, Using a Delphi class in C++ from a .DLL 421, Using a C++ class in Delphi (or vice versa) from a .OBJ 423, Calling into COM objects 423, Conclusion and summary remarks 424

Visual Basic (3.0 and 4.0) 424

Calling into a DLL 425, Calling into COM objects 425

Java 426

Win32 RPC (Remote Procedure Calls) 427

COM 432

The basics of COM 432

Conclusion 434

Q&A 435

Headers 436

What happened to BC5\INCLUDE? 436, How do I use precompiled headers? 437, How can I speed up my Win32 and/or Win16 builds? 441, What are OWLCORE.H, DEFS.H, PCH.H, and OWLALL.H for? 442, What is _OWLCLASS, and what is it doing in all the OWL class declarations? 444, What is _CALLCNVN? 447, What are public_data and protected_data? 449, Why does OWL\DEFS.H #undef MessageBox? 450, How can I develop for the latest Win32 SDK with Borland C++? 453, How can I export a template from a DLL? 454, Why doesn't Visual C++ have a TargetExpert? 458

Doc/View 460

What does Doc/View do for me? 460, When should I think about using Doc/View? 461, Can I combine Doc/View windows with non-Doc/View windows? 461

Conclusion 461

appendix A The new C++ 463

A new Boolean built-in type 466

New allocation functions: operator new[ ] and operator delete[ ] 468

A recap of multiple inheritance: then versus now 470

mutable: When const isn't const anymore 472

Nested classes 474

Namespaces 476

explicit: Closing a hole in C++ semantics 480

Changes to C++ semantics 482

RTTI 486

The new cast syntax 488

The new template specifications 491

The new Standard C++ Library and STL 496

Conclusion 497

appendix B Building the libraries 498

Why on Earth would I want to? 499

Building BIDS 5.0 499

Building OWL 5.0 505

Building BIDS or OWL with other compilers 508

appendix C Guide to the CD 509

Book samples 510

Extras 512

author's resources 516

glossary 524

index 531