Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleMake an ActiveX control that display standard system images (min, max, restore, help, scroll arrows, etc.)
Keywordsframe, draw frame, buttons, help, close, min, max, restore, scroll
CategoriesGraphics, Windows, ActiveX, ActiveX Controls, Controls
 
Use the DrawFrameControl API function to draw the button. It takes as parameters a device context on which to draw, a RECT structure indicating where to draw, a frame image type, and a frame image state. The state may include a modifier indicating disabled, pushed, etc.

The DrawFrame subroutine shown in the following code wraps this API call.

 
' Draw a frame control image.
Private Sub DrawFrame(ByVal hDC As Long, ByVal X As Long, _
    ByVal Y As Long, ByVal wid As Long, ByVal hgt As Long, _
    ByVal frame_type As Long, ByVal frame_state As Long, _
    Optional ByVal frame_status As Long = 0)
Dim r As RECT

    With r
        .Left = X
        .Right = X + wid
        .Top = Y
        .Bottom = Y + hgt
    End With

    DrawFrameControl hDC, r, frame_type, frame_state Or _
        frame_status
End Sub
 
The control uses the DrawControl function to draw the control with various property values and in different states.
 
Private Sub DrawControl()
Dim frame_status As Long

    If Not Enabled Then frame_status = frame_status Or _
        DFCS_INACTIVE
    If m_Pressed Then frame_status = frame_status Or _
        DFCS_PUSHED

    If m_Hot Then frame_status = frame_status Or DFCS_HOT
    If m_Flat Then frame_status = frame_status Or DFCS_FLAT
    If m_Mono Then frame_status = frame_status Or DFCS_MONO
    If m_Checked Then frame_status = frame_status Or _
        DFCS_CHECKED

    DrawFrame UserControl.hDC, 0, 0, _
        ScaleWidth, ScaleHeight, _
        m_ButtonStyle, m_ButtonType, _
        frame_status
End Sub
 
The control uses the following event handlers to draw the button pushed or released as the user clicks on it.
 
' Start a button press.
Private Sub UserControl_MouseDown(Button As Integer, Shift _
    As Integer, X As Single, Y As Single)
    m_Pressing = True
    m_Pressed = True
    DrawControl
End Sub

' Continue a button press.
Private Sub UserControl_MouseMove(Button As Integer, Shift _
    As Integer, X As Single, Y As Single)
Dim new_pressed As Boolean

    If Not m_Pressing Then Exit Sub

    ' See if the mouse is over the control.
    new_pressed = (X >= 0 And X <= ScaleWidth And _
        Y >= 0 And Y <= ScaleHeight)

    ' Redraw the control if necessary.
    If m_Pressed <> new_pressed Then
        m_Pressed = new_pressed
        DrawControl
    End If
End Sub

' Stop a button press.
Private Sub UserControl_MouseUp(Button As Integer, Shift As _
    Integer, X As Single, Y As Single)
    ' Raise the Click event if the button
    ' is currently pressed.
    If m_Pressed Then RaiseEvent Click

    ' Stop the press.
    m_Pressing = False
    m_Pressed = False

    DrawControl
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated