前面已经讲过VC下的自定义符号方法了,这里再讲一个VB下自定义符号的应用实例,那就是将点显示为一个水池,如下图所示

罗嗦的话就不说了,直接贴代码:

Option Explicit

Implements AFCustom.ICustomMarker

' data members
Private m_pen As Long
Private m_oldPen As Long
Private m_size As Long
Private m_Style As WsNodeStyle

' win32 api functions
Private Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long

Private Declare Function LineTo Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function MoveToEx Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, lpPoint As Long) As Long
Private Declare Function Ellipse Lib "gdi32" (ByVal hDC As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As Long

Private Sub Class_Initialize()
  m_Style = WsWaterTankNode
End Sub

Public Property Let SymbolStyle(ByVal vData As WsNodeStyle)
    m_Style = vData
End Property

Public Property Get SymbolStyle() As WsNodeStyle
    SymbolStyle = m_Style
End Property

Public Sub ICustomMarker_Draw(ByVal hDC As Long, ByVal x As Long, ByVal y As Long)
  Select Case m_Style
  Case WsWaterTankNode '水池
    MoveToEx hDC, x - m_size, y - m_size, 0
    LineTo hDC, x - m_size, y
    LineTo hDC, x + m_size, y
    LineTo hDC, x + m_size, y - m_size
    MoveToEx hDC, x - m_size, Int(y - m_size * 2 / 5), 0
    LineTo hDC, x + m_size, Int(y - m_size * 2 / 5)
  Case Else
    Ellipse hDC, x - m_size, y - m_size, x + m_size, y + m_size
  End Select
End Sub

Public Sub ICustomMarker_ResetDC(ByVal hDC As Long)
  SelectObject hDC, m_oldPen
  DeleteObject m_pen
End Sub

Public Sub ICustomMarker_SetupDC(ByVal hDC As Long, ByVal dpi As Double, ByVal pBaseSym As Object)
  m_pen = CreatePen(0, 1, pBaseSym.Color)
  m_oldPen = SelectObject(hDC, m_pen)
  m_size = pBaseSym.Size
End Sub

posted on 2005-10-09 15:35  刘民  阅读(936)  评论(0编辑  收藏  举报