You are previewing VB Shell Programming.
O'Reilly logo
VB Shell Programming

Book Description

Visual Basic's outstanding set of resources for rapidly developing stand-alone applications doesn't include shell extensions for integrating those applications or their data files with the Windows shell. Typically, such extensions as customized context menu handlers, per instance icons (such as a data file icon that's based on the contents of the file), and customized property sheets are written in C++, and all of the available documentation focuses on using C++ for shell extensions. But even C++ programmers find the task rough going, given the woefully inadequate state of the documentation. Very few programmers know that writing shell extensions is not tied to a single language or development environment, and that Visual Basic is an excellent tool for creating shell extensions that more closely tie an application to the Windows shell. That, however, is precisely the focus of Visual Basic Shell Programming. It shows how to take advantage of shell services to develop shell extensions and it provides the basic documentation needed for accomplishing this. Each major type of shell extension gets attention, including:

  • Context menu handlers that can add items to the popup menu that appears when the user right clicks a file.

  • con handlers for displaying per instance icons that, like the standard Recycle Bin icon, vary depending on some condition

  • Property sheet pages, which appear when the user selects the Properties option from a file's context menu.

  • InfoTip handlers, which display tooltips, or "info" tips for a file object on a per instance basis.

  • Pointers. Since VB tends to hide pointers from the programmer, Hamilton shows how to take advantage of the undocumented VarPtr, StrPtr, and ObjPtr functions, as well as the Win32

  • RtlMoveMemory function.

  • Using class identifiers (CLSIDs) from Visual Basic.

  • VTable modification, which allows control of the HRESULT (or status code) returned by a call to a COM method.

  • In showing how to integrate applications with the Windows shell by building shell extensions, author J.P. Hamilton provides a concrete tutorial on COM programming with Visual Basic. And while developing their own shell extensions, readers get to learn advanced VB concepts and techniques such as:

    Visual Basic Shell Programming ventures where none have gone before by giving readers both the know-how to develop shell extensions and an advanced treatment of COM programming with Visual Basic.

    Table of Contents

    1. VB Shell Programming
      1. Preface
        1. The Book’s Audience
        2. Developing Your Own Shell Extensions
        3. Organization of This Book
        4. Software Requirements
        5. Obtaining the Sample Code
        6. The VB Shell Type Library
        7. Conventions Used in This Book
        8. Request for Comments
        9. Acknowledgments
      2. I. Introduction to the Shell and the Basics of COM
        1. 1. Introduction
          1. COM and the Shell
          2. Programming for the Shell
          3. Kinds of Shell Extensions
          4. Conclusion
        2. 2. COM Basics
          1. What Is COM?
          2. Interfaces
          3. Classes
            1. Interface Identifiers
            2. Versions
            3. Class Identifiers
          4. Type Libraries
            1. Interface Definition Language
              1. Attributes
              2. _ Animal
              3. HRESULTs
          5. IUnknown
            1. QueryInterface
            2. AddRef and Release
          6. IDispatch
            1. GetTypeInfoCount
            2. GetTypeInfo
            3. GetIDsOfNames
            4. Invoke
          7. Conclusion
        3. 3. Shell Extensions
          1. Folders and File Objects
          2. Shell Extensions
            1. Context Menu Handler
            2. Icon Handler
            3. Property Sheet Handler
            4. Data Handler
            5. Drop Handler
            6. Copy Hook Handler
            7. Drag-and-Drop Handler
          3. Registry Settings
            1. File Associations
            2. Scope
          4. The .rad File
            1. Registering the .rad File
          5. The Shell Extension Project
          6. Restarting the Shell
          7. When the Shell Crashes
      3. II. Shell Extensions
        1. 4. Context Menu Handlers
          1. Static Context Menus
          2. Static Context Menus in IE 5.0
          3. Dynamic Context Menus
          4. Context Menu Handler Interfaces
            1. IShellExtInit
            2. IDataObject
            3. IContextMenu
              1. GetCommandString
              2. InvokeCommand
              3. QueryContextMenu
          5. Creating a Context Menu Handler
            1. Type Library
            2. The Project
              1. Implementing IShellExtInit
              2. Implementing IContextMenu
            3. Registration and Operation
        2. 5. Icon Handlers
          1. How Icon Handlers Work
          2. Icon Handler Interfaces
            1. IPersistFile
              1. Load
            2. IExtractIcon
              1. GetIconLocation
              2. Extract
          3. Creating an Icon Handler
            1. Implementing IPersistFile
            2. Implementing IExtractIcon
              1. [in, out] parameters
            3. Stubs
            4. Registration
        3. 6. Property Sheet Handlers
          1. How Property Sheet Handlers Work
          2. Property Sheet Handler Interface
            1. IShellExtInit
            2. IShellPropSheetExt
              1. AddPages
              2. ReplacePage
              3. Implementing IShellPropSheetExt
          3. Creating a Property Sheet Handler
            1. Implementing IShellExtInit
            2. Creating a Dialog Resource
            3. Implementing IShellPropSheetExt
              1. AddPages
            4. PropSheetCallbackProc
            5. PropSheetDlgProc
              1. WM_INITDIALOG
              2. WM_NOTIFY
              3. WM_DESTROY
          4. Registering the Property Sheet Handler
        4. 7. Drop Handlers
          1. How Drop Handlers Work
          2. Drop Handler Interfaces
            1. IDropTarget
              1. DragEnter
              2. DragOver
              3. DragLeave
              4. Drop
            2. IPersistFile
          3. Creating a Drop Handler
            1. Implementing IPersistFile
            2. Implementing IDropTarget
              1. DragEnter
              2. Drop
          4. Registering the Drop Handler
        5. 8. Data Handlers
          1. How Data Handlers Work
          2. Data Handler Interfaces
            1. IDataObject
              1. QueryGetData
              2. EnumFormatEtc
              3. GetData
          3. Creating a Data Handler
            1. Implementing IPersistFile
              1. Load
            2. Implementing IDataObject
              1. QueryGetData
              2. EnumFormatEtc
              3. GetData
            3. Registration and Operation
          4. Adding Additional Formats
        6. 9. Copy Hook Handlers
          1. How Copy Hook Handlers Work
          2. Copy Hook Handler Interface: ICopyHook
          3. Implementing ICopyHook
          4. Registering Copy Hook Handlers
          5. Testing the Handler
            1. Boom!
            2. The Workaround
            3. Revisiting CopyCallback
            4. Reregister Everything
        7. 10. InfoTip Handler
          1. How InfoTip Handlers Work
          2. InfoTip Interfaces
            1. GetInfoTip
          3. The Project
            1. Registration and Operation
      4. III. Namespace Extensions
        1. 11. Namespace Extensions
          1. Namespace Fundamentals
            1. Rooted vs. Non-rooted
            2. Junction Points
              1. Using a file type
              2. Using a directory desktop.ini
              3. Using a directory and the CLSID
              4. Using an existing namespace
          2. Explorer Architecture
          3. The PIDL
          4. Namespace Interfaces
            1. IPersistFolder
              1. GetClassID
              2. Initialize
            2. IShellFolder
              1. BindToObject
              2. CompareIDs
              3. CreateViewObject
              4. EnumObjects
              5. GetAttributesOf
              6. GetDisplayNameOf
              7. GetUIObjectOf
            3. IShellView
              1. CreateViewWindow
              2. DestroyViewWindow
              3. GetCurrentInfo
              4. GetWindow
              5. Refresh
              6. UIActivate
            4. IEnumIDList
            5. Additional Interfaces
          5. Creating the Namespace Extension
            1. ShellFolder
              1. GetClassID
              2. CreateViewObject
            2. Creating the View
              1. CreateViewWindow
              2. The View window
              3. Back to ShellView
              4. DestroyWindow
              5. GetCurrentInfo
              6. GetWindow
              7. Refresh
            3. Enumerating Shell Items
              1. CreateEnumList
              2. A linked list in VB?
              3. AddToEnumList
              4. Next
          6. The PIDL Manager
            1. Delete
            2. Copy
            3. Create
            4. GetAttributesOf
            5. GetDisplayNameOf
            6. CompareIDs
            7. GetUIObjectOf
            8. ExtractIcon
              1. GetIconLocation
              2. Extract
            9. FillList
            10. Finishing the View Object
            11. BindToObject
          7. Registering DemoSpace
          8. Practical Coding Examples
            1. RegSpace
            2. ROTSpace
      5. IV. Browser Extensions
        1. 12. Browser Extensions
          1. Browser Helper Objects
            1. How BHOs Work
            2. Browser Helper Interfaces
              1. GetSite
              2. SetSite
            3. The Project
            4. Registration
            5. IWebBrowser2
            6. Events
          2. Browser Extensions
            1. How Browser Extensions Work
            2. Browser Extension Interfaces
              1. IOleCommandTarget
                1. QueryStatus
                2. Exec
              2. IServiceProvider
                1. QueryService
            3. SetSite Revisited
            4. Adding the Menu Item
            5. Adding the Toolbar Button
            6. QueryStatus
            7. Exec
        2. 13. Band Objects
          1. How Band Objects Work
          2. Band Object Interfaces
            1. IDeskband
              1. ShowDW
              2. CloseDW
              3. GetBandInfo
            2. IInputObject
              1. HasFocusIO
              2. TranslateAcceleratorIO
              3. UIActivateIO
          3. The Project: FileSpider
            1. Class_Initialize/Class_Terminate
            2. IObjectWithSite
            3. IInputObject
            4. IDeskBand
            5. The Band Form
            6. The Preferences Dialog
          4. Registry
          5. Tool Bands
        3. 14. Docking Windows
          1. How Docking Windows Work
          2. Docking Window Interfaces
            1. IObjectWithSite
            2. IDockingWindow
            3. IDockingWindowFrame
              1. AddToolbar
              2. FindToolbar
              3. RemoveToolbar
            4. IDockingWindowSite
              1. GetBorderDW
              2. RequestBorderSpaceDW
              3. SetBorderSpaceDW
          3. The Project
            1. Primary Component
            2. Docking Window Component
              1. SetSite
              2. GetSite
              3. The docking window form
              4. CloseDW
              5. GetWindow
              6. ResizeBorderDW
              7. ShowDW
          4. Registration
      6. V. Appendixes
        1. A. VBShell Library Listing
        2. B. Pointers
          1. CopyMemory
          2. The Undocumented VBA Functions
            1. VarPtr
            2. StrPtr
            3. ObjPtr
          3. Some CopyMemory Examples
            1. Example 1
            2. Example 2
            3. Example 3
      7. Index
      8. Colophon