home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.UserControl AXButtonCtl
- CanGetFocus = 0 'False
- ClientHeight = 2610
- ClientLeft = 0
- ClientTop = 0
- ClientWidth = 3135
- ClipControls = 0 'False
- ForwardFocus = -1 'True
- LockControls = -1 'True
- PropertyPages = "AXButton.ctx":0000
- ScaleHeight = 2610
- ScaleWidth = 3135
- Begin VB.Line lnRight
- BorderColor = &H00808080&
- BorderWidth = 2
- Visible = 0 'False
- X1 = 3030
- X2 = 3030
- Y1 = 60
- Y2 = 2520
- End
- Begin VB.Line lnBottom
- BorderColor = &H00808080&
- BorderWidth = 2
- Visible = 0 'False
- X1 = 60
- X2 = 3030
- Y1 = 2520
- Y2 = 2520
- End
- Begin VB.Line lnTop
- BorderColor = &H80000014&
- BorderWidth = 2
- Visible = 0 'False
- X1 = 60
- X2 = 2970
- Y1 = 60
- Y2 = 60
- End
- Begin VB.Line lnLeft
- BorderColor = &H80000014&
- BorderWidth = 2
- Visible = 0 'False
- X1 = 60
- X2 = 60
- Y1 = 60
- Y2 = 2490
- End
- End
- Attribute VB_Name = "AXButtonCtl"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = True
- Attribute VB_PredeclaredId = False
- Attribute VB_Exposed = True
- Option Explicit
- '------------------------------------------------------------------
- ' API Declares...
- '------------------------------------------------------------------
- Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
- Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
- Private Declare Function ReleaseCapture Lib "user32" () As Long
-
- '------------------------------------------------------------------
- ' Private Variables...
- '------------------------------------------------------------------
- Dim MouseDown As Boolean ' Flag - set when left button is pressed down
- Dim MouseOver As Boolean ' Flag - set when mouse pointer is over button
- Dim MouseCaptured As Boolean ' Flag - set when mouse pointer is captured by button control
- Dim ClearURLOnly As Boolean '
- Dim ClearPictureOnly As Boolean '
-
- Dim StaticWidth As Long
- Dim StaticHeight As Long
- Dim gPicture As StdPicture ' Global picture property variable
- Dim gURLPicture As String ' Global URL picture property string variable
-
- Const pPICTURE = "Picture" ' Picture property name constant
- Const pURLPICTURE = "URLPicture" ' URLPicture property name constant
- Const Bdr = 10
- Const SND_ASYNC = &H1
- Const EVENT_MenuCommand = "MenuCommand" ' Sound event name for button mousedown event
- Const EVENT_MenuPopup = "MenuPopup" ' Sound event name for button enterover event
-
- '------------------------------------------------------------------
- ' Private Enum...
- '------------------------------------------------------------------
- Enum ButtonState
- Up = 0 ' Draw button raised up border
- Down = 1 ' Draw button sunken down border
- Flat = 2 ' Draw button flat - no border
- End Enum
-
- '------------------------------------------------------------------
- ' Container Event Declarations:
- '------------------------------------------------------------------
- Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
- Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
- Event MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
- Event Click()
-
- '------------------------------------------------------------------
- Private Sub UserControl_Click()
- '------------------------------------------------------------------
- RaiseEvent Click ' Dispatch click event to container.
- '------------------------------------------------------------------
- End Sub
- '------------------------------------------------------------------
-
- '------------------------------------------------------------------
- Private Sub UserControl_Initialize()
- '------------------------------------------------------------------
- StaticWidth = UserControl.Width ' Get default button size
- StaticHeight = UserControl.Height
- '------------------------------------------------------------------
- End Sub
- '------------------------------------------------------------------
-
- '------------------------------------------------------------------
- Private Sub UserControl_AsyncReadComplete(AsyncProp As AsyncProperty)
- '------------------------------------------------------------------
- On Error GoTo ErrorHandler
-
- If (AsyncProp.PropertyName = pPICTURE) Then ' Picture download is complete
- ClearPictureOnly = True
- Set Picture = AsyncProp.Value ' Store picture data to property...
- End If
- '------------------------------------------------------------------
- ErrorHandler:
- '------------------------------------------------------------------
- ClearPictureOnly = False
- '------------------------------------------------------------------
- End Sub
- '------------------------------------------------------------------
-
- '------------------------------------------------------------------
- Private Sub UserControl_InitProperties()
- '------------------------------------------------------------------
- SetButtonState Up ' Draw button flat
- '------------------------------------------------------------------
- End Sub
- '------------------------------------------------------------------
-
- '------------------------------------------------------------------
- Private Sub UserControl_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
- '------------------------------------------------------------------
- If ((Button And vbLeftButton) = vbLeftButton) Then ' Only do if left mouse button was pressed
- MouseDown = True ' Set MouseDown state flag
- SetButtonState Down ' Draw button down
- PlaySound EVENT_MenuCommand, 0, SND_ASYNC ' Play event sound for mousedown...
- End If
- RaiseEvent MouseDown(Button, Shift, X, Y) ' Dispatch mousedown event to container.
- '------------------------------------------------------------------
- End Sub
- '------------------------------------------------------------------
-
- '------------------------------------------------------------------
- Private Sub UserControl_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
- '------------------------------------------------------------------
- If ((Button And vbLeftButton) = vbLeftButton) Then ' Only do if left mouse button was pressed
- MouseDown = False ' Clear MouseDown flag
- SetButtonState Up ' Draw button up
- End If
-
- MouseCaptured = True ' Reset MouseCaptured flag
- SetCapture UserControl.hWnd ' ReCapture Mouse, Click seems to disable previous captures...
- RaiseEvent MouseUp(Button, Shift, X, Y) ' Dispatch mouseup event to container.
- '------------------------------------------------------------------
- End Sub
- '------------------------------------------------------------------
-
- '------------------------------------------------------------------
- Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
- '------------------------------------------------------------------
- With UserControl
- ' Determine if mouse is currently moving over button.
- MouseOver = (0 <= X) And (X <= .Width) And (0 <= Y) And (Y <= .Height)
-
- ' Determine if left mouse button is down
- MouseDown = ((Button And vbLeftButton) = vbLeftButton)
-
- If MouseOver Then
- If MouseDown Then
- SetButtonState Down ' Draw button down...
- Else
- SetButtonState Up ' Draw button up
- End If
- If Not MouseCaptured Then ' Mouse captured
- PlaySound EVENT_MenuPopup, 0, SND_ASYNC ' Play mouse move enter event sound
- SetCapture .hWnd ' Capture all mouse movements and send to UserControl
- MouseCaptured = True ' Set MouseCaptured flag
- End If
- Else
- If MouseDown Then
- SetButtonState Up ' Draw button up
- Else
- SetButtonState Flat ' Draw button flat
- If MouseCaptured Then
- ReleaseCapture ' Release outside capture of mouse button
- MouseCaptured = False ' Turn capture flag off...
- End If
- End If
- End If
- End With
- RaiseEvent MouseMove(Button, Shift, X, Y) ' Dispatch mousemove event to container
- '------------------------------------------------------------------
- End Sub
- '------------------------------------------------------------------
-
- '------------------------------------------------------------------
- Private Sub SetButtonState(State As ButtonState)
- '------------------------------------------------------------------
- Select Case State ' Determine draw state
- Case Up ' Draw button up
- lnTop.BorderColor = vb3DHighlight ' Set appropriate color for lines...
- lnLeft.BorderColor = vb3DHighlight
- lnBottom.BorderColor = vb3DShadow
- lnRight.BorderColor = vb3DShadow
- Case Down ' Draw button down
- lnTop.BorderColor = vb3DShadow ' Set appropriate color for lines...
- lnLeft.BorderColor = vb3DShadow
- lnBottom.BorderColor = vb3DHighlight
- lnRight.BorderColor = vb3DHighlight
- End Select
-
- lnBottom.Visible = (State <> Flat) ' Show or Hide lines based on state of button
- lnTop.Visible = (State <> Flat)
- lnLeft.Visible = (State <> Flat)
- lnRight.Visible = (State <> Flat)
- '------------------------------------------------------------------
- End Sub
- '------------------------------------------------------------------
-
- '------------------------------------------------------------------
- Public Property Let URLPicture(Url As String)
- Attribute URLPicture.VB_ProcData.VB_Invoke_PropertyPut = ";Misc"
- '------------------------------------------------------------------
- If (gURLPicture <> Url) Then ' Do only if value has changed...
- ClearPictureOnly = Not ClearURLOnly ' If Picture property is not being set by the URLPicture _
- property then clear the URLPicture value...
- gURLPicture = Url ' Save url string value to global variable
- PropertyChanged pURLPICTURE ' Notify property bag of property change
-
- If Not ClearURLOnly Then
- On Error GoTo ErrorHandler ' Handle Error if URL is unavailable or Invalid...
- If (Url <> "") Then
- UserControl.AsyncRead Url, vbAsyncTypePicture, pPICTURE ' Begin async download of picture file...
- Else
- Set Picture = Nothing
- End If
- End If
- End If
- '------------------------------------------------------------------
- ErrorHandler:
- '------------------------------------------------------------------
- ClearPictureOnly = False
- '------------------------------------------------------------------
- End Property
- '------------------------------------------------------------------
-
- '------------------------------------------------------------------
- Public Property Get URLPicture() As String
- '------------------------------------------------------------------
- URLPicture = gURLPicture ' Return URL string value
- '------------------------------------------------------------------
- End Property
- '------------------------------------------------------------------
-
- '------------------------------------------------------------------
- Public Property Set Picture(ByVal Image As Picture)
- '------------------------------------------------------------------
- If Not ClearPictureOnly Then
- ClearURLOnly = True ' If Picture property is not being set by the URLPicture
- URLPicture = "" ' property then clear the URLPicture value...
- ClearURLOnly = False ' If Picture property is not being set by the URLPicture
- End If
-
- If (Not Image Is Nothing) Then
- If (Image.Handle = 0) Then Set Image = Nothing
- End If
- Set gPicture = Image ' Store image to global variable
-
- With UserControl
- If Not Image Is Nothing Then ' Check for Null picture value
- StaticWidth = .ScaleX(gPicture.Width, vbHimetric, vbTwips) ' Save size of bitmap
- StaticHeight = .ScaleY(gPicture.Height, vbHimetric, vbTwips)
- End If
- .Cls ' Clear previous picture image...
- End With
-
- UserControl_Resize ' Resize button to fit image
- UserControl_Paint ' Refresh image on button...
- PropertyChanged pPICTURE ' Notify property bag of property change
- '------------------------------------------------------------------
- End Property
- '------------------------------------------------------------------
-
- '------------------------------------------------------------------
- Public Property Get Picture() As Picture
- Attribute Picture.VB_ProcData.VB_Invoke_Property = "StandardPicture"
- '------------------------------------------------------------------
- Set Picture = gPicture ' Return value of picture property
- '------------------------------------------------------------------
- End Property
- '------------------------------------------------------------------
-
- '------------------------------------------------------------------
- Private Sub UserControl_Paint()
- '------------------------------------------------------------------
- If (gPicture Is Nothing) Then Exit Sub ' Don't draw if picture is invalid...
-
- ' Draw picture from property to usercontrol...
- With UserControl
- .PaintPicture gPicture, _
- .ScaleX(lnLeft.BorderWidth, vbTwips, vbHimetric), _
- .ScaleY(lnTop.BorderWidth, vbTwips, vbHimetric), _
- .ScaleX(.Width - (2 * lnLeft.BorderWidth), vbTwips, vbHimetric), _
- .ScaleY(.Height - (2 * lnTop.BorderWidth), vbTwips, vbHimetric), _
- 0, _
- 0, _
- gPicture.Width, _
- gPicture.Height
- End With
- '------------------------------------------------------------------
- End Sub
- '------------------------------------------------------------------
-
- '------------------------------------------------------------------
- Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
- '------------------------------------------------------------------
- Dim Pic As StdPicture
- Dim Url As String
- '------------------------------------------------------------------
- On Error GoTo ErrorHandler ' Handler weird host problems
-
- If UserControl.Ambient.UserMode Then ' Are we hosted in an IDE ???
- SetButtonState Flat ' Draw button flat
- Else
- SetButtonState Up ' Draw button flat
- End If
-
- ' Read in the properties that have been saved into the PropertyBag...
- With PropBag
- Url = .ReadProperty(pURLPICTURE, "") ' Read URLPicture property value
- If (Url <> "") Then ' If a URL has been entered...
- URLPicture = Url ' Attempt to download it now, URL may be unabailable at this time
- Else
- Set Pic = .ReadProperty(pPICTURE, Nothing) ' Read Picture property value
- If Not (Pic Is Nothing) Then ' URL is not available
- Set Picture = Pic ' Use existing picture (This is used only if URL is empty)
- End If
- End If
- End With
- '------------------------------------------------------------------
- ErrorHandler:
- '------------------------------------------------------------------
- ' Just quit nicely...
- '------------------------------------------------------------------
- End Sub
- '------------------------------------------------------------------
-
- '------------------------------------------------------------------
- Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
- '------------------------------------------------------------------
- On Error GoTo ErrorHandler ' Handler weird host problems
- With PropBag
- .WriteProperty pURLPICTURE, gURLPicture ' Write URLPicture property to propertybag
- .WriteProperty pPICTURE, gPicture ' Write Picture property to propertybag
- End With
- '------------------------------------------------------------------
- ErrorHandler:
- '------------------------------------------------------------------
- ' Just quit nicely...
- '------------------------------------------------------------------
- End Sub
- '------------------------------------------------------------------
-
- '------------------------------------------------------------------
- Private Sub UserControl_Resize()
- '------------------------------------------------------------------
- Dim W As Long, H As Long, L As Long, T As Long
- '------------------------------------------------------------------
- L = 1 ' Set default left position
- T = 1 ' Set default top positon
- With UserControl
- If gPicture Is Nothing Then ' If picture is invalid valid
- StaticWidth = .Width ' Update static width size
- StaticHeight = .Height ' Update static height size
- Else ' Picture is valid...
- .Width = StaticWidth ' Fix control size to picture width
- .Height = StaticHeight ' ...
- End If
- W = .ScaleWidth - Bdr ' Calculate w position for lines
- H = .ScaleHeight - Bdr ' Calculate h position for lines
- End With
- With lnLeft
- .X1 = L: .X2 = L: .Y1 = T: .Y2 = H ' Move lines to new positions
- End With
- With lnRight
- .X1 = W: .X2 = W: .Y1 = T: .Y2 = H
- End With
- With lnTop
- .X1 = L: .X2 = W: .Y1 = T: .Y2 = T
- End With
- With lnBottom
- .X1 = L: .X2 = W: .Y1 = H: .Y2 = H
- End With
- '------------------------------------------------------------------
- End Sub
- '------------------------------------------------------------------
-