Other Properties and Methods


The Create and Draw methods are the heart of the CPictureGlass class, but the class also needs to supply other properties and methods so that users can move the transparent picture. I chose member names based on the familiar ones used by the PictureBox control. Figure 7-10 on the following page shows a diagram of the CPictureGlass class.


Let’s start with the Move method, which is interesting more for how it handles optional arguments than for how it handles the image:

Public Sub Move(xLeftA As Long, Optional yTopA As Long = -1)
With cvsDst
BugAssert fExist
xLeft = .ScaleX(xLeftA, .ScaleMode, vbPixels)
If yTopA <> -1 Then yTop = .ScaleY(yTopA, .ScaleMode, vbPixels)
Draw
End With
End Sub


Figure 7-10. A diagram of CPictureGlass.


Most Move methods have two additional arguments, Width and Height. But using these arguments changes the size of the object. I suppose I could have made CPictureGlass resizable by using StretchBlt instead of BitBlt, but I’ll leave that to you. For now you can’t change the size, so these arguments aren’t implemented. Because the Move method changes the position of the object, it calls the Draw method to erase the last image and redraw the new one.


The Left and Top Property Let procedures are implemented in the same way as Move. The Width and Height Property Let procedures aren’t implemented, for the same reason that Move’s Width and Height parameters aren’t implemented. The Property Get routines for Left, Top, Width, and Height simply pass back the internal variables representing these properties. Since position and size properties are maintained in pixels, the numbers need to be scaled:

Property Get Left() As Single
BugAssert fExist
Left = cvsDst.ScaleX(xLeft, vbPixels, cvsDst.ScaleMode)
End Property

The Visible property sets or returns the internal fVisible variable. The MaskColor property returns the clrMask variable. I don’t provide a Property Let for Mask­Color, but you could add one. You’d need to create a new mask (hdcMask) whenever a user changed the property.


Hardcore Painting


Help is available for all you hardcore programmers who want to do tricks with bitmaps, but I can’t even tell you the names of all the APIs, much less how to use them from Visual Basic. Start with DirectX. You might also want to think about Direct3D and ActiveMovie. Those three should provide enough fodder for three books the size of this one. Good luck. You’re going to need it because from my preliminary look, these APIs were specifically not designed with Visual Basic programmers in mind. There is at least one commercial control available that attempts to wrap DirectX up in a Basic-friendly wrapper, but I can’t say more because I haven’t tried it.