Welcome to Visual C++ Windows Shell Programming! With this book, youll learn how to program theWindows Shell, customize its behavior and integrate your applications with it. Youll discover how touse and modify its features to best effect, and the way to call shell API functions whosedocumentation is scant. Programming the shell isnt difficult, but few books explain the subject in itsentirety.This book covers the whole range of API functions in detail, often revealing bugs and undocumentedfeatures. It delves deep into the world of Explorer, bringing to light things like hooks, the registry,browser helper objects, shell extensions, namespace extensions and web views. It also looks atWindows Scripting Host extensions and Shell Scriptable Objects.This book is for professional and home developers alike, and has three main goals:Providing a better understanding of the existing and often poorly documented shell APIGiving ideas for new applicationsShowing whats new in Internet Explorer 4.x, the Active Desktop and Windows 98, and how thesefit with the existing shell. Table of Contents......Page 6 Everything Changes......Page 22 What You Need to Use this Book......Page 23 Tell Us What You Think......Page 24 Support......Page 25 What is the Windows Shell?......Page 26 The Program Manager......Page 27 The Structure of Explorer......Page 28 Why Program the Shell?......Page 29 Where This Book Will Take You......Page 30 The Plethora of Shell Versions......Page 31 Summary......Page 32 The Structure of the Shell......Page 33 The Shell's Namespace......Page 34 The Shell's View......Page 39 The Shell's Taskbar......Page 40 The Shell API Functions......Page 41 General Windows Functions......Page 42 File Functions......Page 43 Folder Functions......Page 44 Shell Interfaces......Page 45 Namespace Interfaces......Page 46 Miscellaneous Interfaces......Page 47 What Changed with Active Desktop......Page 48 The New Shell View Object......Page 49 The New Taskbar Layout......Page 52 Summary......Page 53 Working with Files......Page 54 What Can SHFileOperation() do for You?......Page 55 Available Operations......Page 56 SHFileOperation() Return Values......Page 70 Long File Names......Page 73 File Name Mapping Objects......Page 74 Demonstrating File Mapping......Page 75 Using the Object......Page 77 Further Reading......Page 81 Investigating the Nature of Files......Page 82 How SHGetFileInfo() Works......Page 83 Specifying the Input File......Page 84 The Sample Program......Page 87 The Flags of the Function......Page 91 Getting Attributes for a File......Page 95 Binary Format of Executables......Page 100 SHGetFileInfo() Return Values......Page 102 Summary......Page 103 Further Reading......Page 104 Choosing a Folder......Page 105 A More Modern Approach......Page 106 The Prototype of SHBrowseForFolder()......Page 107 Using SHBrowseForFolder()......Page 108 What the Function Returns......Page 109 Using a Callback Function......Page 110 Customizing the User Interface......Page 112 Specifying the Root Node......Page 117 Putting it all Together......Page 120 Freeing PIDLs......Page 124 How to Use PIDLs......Page 125 The Sample Program......Page 137 System Support for Special Folders......Page 139 Functions......Page 141 SHGetSettings()......Page 142 The Sample Program......Page 145 Setting Preferences......Page 146 Summary......Page 149 Further Reading......Page 150 The Shortest Path to Shortcuts......Page 151 Using the IShellLink Interface......Page 152 Deleting Shortcuts......Page 156 How Explorer Resolves Shortcuts......Page 157 Shortcuts and Special Folders......Page 159 Selecting a Shortcut......Page 160 Displaying the Results......Page 161 Collecting Arguments for Creation......Page 164 The Source Code......Page 165 Creating Shortcuts in System Folders......Page 170 Further Reading......Page 172 Shell Invaders......Page 173 Notification Objects......Page 174 SHChangeNotify()......Page 181 The Brute Force Approach......Page 185 Invited into the Shell's Memory Space......Page 192 A Minimal COM Object......Page 193 Registering the COM Object......Page 196 A Brand New Start Button......Page 199 Creating Owner- Drawn Menus......Page 208 Backward Compatibility......Page 219 Usage......Page 220 Writing a Helper Object......Page 221 Glossary of Techniques for Entering the Shell......Page 227 Further Reading......Page 228 Program Executors......Page 230 A Comparison of WinExec() with CreateProcess()......Page 231 Is CreateProcess() Manna from Heaven?......Page 232 ShellExecute()......Page 233 The Open Operation......Page 234 The Explore Operation......Page 235 The Print Operation......Page 236 The Find Operation......Page 237 More Details of the Verbs......Page 238 Getting the Executable Name for a File......Page 241 ShellExecute() Tips and Tricks......Page 245 ShellExecute() vs. CreateProcess()......Page 247 Extending ShellExecute()......Page 248 ShellExecuteEx()......Page 249 Example: Program Executors......Page 252 Multi-Monitor Support......Page 254 Registering an IShellExecuteHook Handler......Page 255 The IShellExecuteHook Interface......Page 256 Writing an IShellExecuteHook Handler......Page 257 Further Reading......Page 261 Icons and the Windows Taskbar......Page 263 Creating Icons......Page 264 Extracting Icons from Files......Page 266 Assigning Icons to Dialog Boxes......Page 269 Browsing for Icons......Page 270 Putting Icons in the Tray Notification Area......Page 275 Detecting When the Shell Restarts......Page 281 When a Window Goes in the Taskbar......Page 283 Getting the Taskbar's State Programmatically......Page 285 The ITaskbarList Interface......Page 290 An IDL Definition for the Interface......Page 291 ITaskbarList Sample Program......Page 292 Further Reading......Page 299 Windows Helper Libraries......Page 300 DLL Version Information......Page 301 A More General Function......Page 305 Structure of the Recycle Bin......Page 309 Renaming Convention......Page 310 Functions for Interacting with the Recycle Bin......Page 311 Helper Libraries......Page 312 The Registry Shell API......Page 313 Manipulating Strings......Page 314 Manipulating Path Strings......Page 315 What the Function Does......Page 317 A General Approach to Improving System Dialogs......Page 318 Extending the Syntax of SHFormatDrive()......Page 319 An Automatic Function for Formatting Drives......Page 321 The Sample Program......Page 325 Further Reading......Page 326 Exploring the Shell......Page 328 Explorer's Command Line......Page 329 Using Special Folders as the Root......Page 330 What is rundll32.exe?......Page 331 What you can do with rundll32.exe......Page 332 The Explorer's Objects......Page 336 The Control Panel......Page 337 The Printers Folder......Page 342 Dial-Up Networking......Page 343 Scheduled Tasks......Page 344 My Briefcase......Page 345 A New Shortcut Handler......Page 346 The User Interface......Page 347 How to Replace the Windows Wizard......Page 352 Further Reading......Page 354 Scriptable Shell Objects......Page 356 Undocumented Shell Features......Page 357 The Shell Object Model......Page 358 Methods of the Shell Object......Page 360 Using Visual Basic......Page 363 Using C++......Page 367 The Folder Object......Page 369 More on Folder Object Methods......Page 370 Invoking an Item's Verbs......Page 372 The ShellUIHelper Object......Page 374 Putting it all Together......Page 376 Further Reading......Page 382 The Windows Scripting Host......Page 383 Running Scripts at Startup......Page 384 What is the Host?......Page 385 Shell Support for Script Files......Page 386 The Scripting Engine......Page 388 The WScript Object......Page 389 The WshShell Object......Page 391 The WshNetwork Object......Page 392 Helper Objects......Page 393 Accessing the Registry......Page 396 Scripting the Local File System......Page 400 Handling Events with the WSH......Page 402 Adding New Objects to the WSH......Page 403 Defining the Programming Interface......Page 404 Clipboard Support......Page 405 Drive Formatting......Page 406 Browsing for Icons......Page 407 Registry Key Enumeration......Page 409 Hooking a Program's Execution......Page 413 Hints for Improving the WSH......Page 414 Adding User Interface Support......Page 415 Reusability within the WSH......Page 416 Summary......Page 417 Further Reading......Page 418 Designing a Shell-Integrated Application......Page 419 Shell-Integrated Applications......Page 420 Basic Document Functions......Page 421 Registered Document Types......Page 423 How Programs are Affected......Page 425 Creating New Documents......Page 426 The New Menu......Page 427 Application Paths......Page 429 Automatic Startup of Applications......Page 430 Designing a Shell-Integrated Application......Page 434 A Metafile Viewer......Page 435 Adapting the Application......Page 443 Adding Shell Support......Page 447 Drag-and-Drop Support......Page 452 Defining a New Template......Page 453 New Dialog Features......Page 455 Summary......Page 460 Further Reading......Page 461 Shell Extensions......Page 462 What are Shell Extensions?......Page 463 Calling Shell Extensions......Page 464 How Explorer Calls Into Shell Extensions......Page 465 Writing Shell Extensions......Page 466 Initialization of Shell Extensions......Page 467 The IShellExtInit Interface......Page 468 The IShellPropSheetExt Interface......Page 471 Adding a New Property Page......Page 472 Registering Shell Extensions......Page 475 Testing Shell Extensions......Page 477 More on Property Page Shell Extensions......Page 480 Implementing IContextMenu......Page 484 A Dependency List for Executables......Page 488 Adding a New Find Menu......Page 497 IContextMenu2 and IContextMenu3......Page 499 Right-hand Drag & Drop......Page 500 Registering Drag & Drop Handlers......Page 501 Assigning Dynamic Icons......Page 502 Different Icons for Different Color Depths......Page 503 Monitoring Folders through ICopyHook......Page 509 Implementing ICopyHook......Page 510 Monitorable Objects......Page 514 The DropHandler Extension......Page 515 Adding Shell Support to Script Files......Page 521 Dropping Parameters over Script Files......Page 522 DataHandler Shell Extensions......Page 524 A Shell Extension Developer's Handbook......Page 525 File Viewers......Page 526 Starting a Quick View......Page 527 Writing a Quick Viewer......Page 528 Summary......Page 531 Further Reading......Page 532 Namespace Extensions......Page 534 An Overview of Namespace Extensions......Page 535 What Does Writing a Namespace Extension Mean?......Page 536 Primary Interfaces......Page 538 Additional Interfaces......Page 553 The Concept of Folders......Page 555 Flavors of Namespace Extensions......Page 557 Rooted vs. Non-rooted......Page 558 Junction Points......Page 560 Designing Our Namespace Extension......Page 563 Designing the View......Page 564 Common Features of Registry View and Windows View......Page 565 The Windows View Project......Page 566 The PIDL Manager Class......Page 567 The Windows Enumerator......Page 571 The Folder Manager......Page 575 The Window View......Page 580 Giving it a User Interface......Page 588 Menu Modifications......Page 589 Associating a Context Menu with Items......Page 592 Associating an Icon with Items......Page 595 Installing a Namespace Extension......Page 596 A Node on the Desktop......Page 598 Adding an InfoTip......Page 599 Adding a Removal Message......Page 600 Browsing a Custom Folder......Page 601 Summarizing Namespace Extensions......Page 602 What's a Web View?......Page 603 The Shell View ID......Page 604 New Functions in IShellView2......Page 605 How a Web View is Structured......Page 606 Getting in Touch with the Classic View Object......Page 607 From Custom to Customized Folders......Page 608 Folder Customization......Page 609 The Desktop.ini File......Page 610 Creating a New Template......Page 613 Hosting Applications through Namespace Extensions......Page 616 Summary......Page 617 Further Reading......Page 618 Final Thoughts......Page 619 The Custom AppWizard......Page 621 A Quick Tour of a Custom AppWizard......Page 622 The Wrox AppWizard......Page 624 System Macros......Page 631 Finalizing the Process......Page 632 A Minimal Dialog-based Application......Page 635 A Generic DLL......Page 639 The Rest of the Code......Page 640 Further Reading......Page 645 Index A......Page 646 Index B......Page 650 Windows 98 is the culmination of many improvements to what is now a fully-fledged, 32-bit, COM-based operating system. With suitable instruction, you can push the Windows shell to performing complex actions, and customize it using C++/ATL programs. Until now, the documentation for Windows shell programming has been poor. This book is about telling you exactly how to use the tools available, and when each tool is appropriate. There's coverage of the Windows API, the Windows Scripting Host, and shell and namespace extensions that use ATL and the shell's COM object model. Information on these topics at this level has been scarce, but the author brings them all together in this volume.