O'Reilly logo

VB Shell Programming by J.P. Hamilton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a Drop Handler

We need to add a new class to the RadEx project that will implement IPersistFile and IDropTarget. Call the file clsDropHandler.cls. Its declarations section begins as follows:

'clsDropHandler.cls

Implements IDropTarget
Implements IPersistFile

Implementing IPersistFile

The only method that we need to implement on this interface is Load. The code is the same as the code we used to create the icon handler back in Chapter 5. Example 7.1 contains the implementation.

Example 7-1. IPersistFile::Load Implementation

'clsDropHandler.cls

Private m_sTargetFile As String

Private Sub IPersistFile_Load(
    ByVal pszFileName As VBShellLib.LPCOLESTR, _ 
    ByVal dwMode As VBShellLib.DWORD)

    m_sTargetFile = Space(255)
    CopyMemory ByVal StrPtr(m_sTargetFile), _ 
               ByVal pszFileName, _ 
               Len(m_sTargetFile)
    
End Sub

Implementing IDropTarget

The most interesting aspect of implementing the IDropTarget interface (and, in particular, its DragEnter method) concerns the POINTL parameter to the DragEnter method. Notice from our earlier presentation of the method’s syntax that it is an [in] parameter; therefore, it is not a pointer. We have a slight problem here, because Visual Basic does not allow UDTs to be passed ByVal, which is what is going on here. POINTL is a structure that contains the location of the mouse in the drop area. It is defined like this:

typedef struct _POINTL { 
    LONG x; 
    LONG y; 
} POINTL;

Fortunately, we do not need this point information, so there is a simple workaround. Instead ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required