📄 dragfeedback.cls
字号:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "DragFeedback"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
' WinAPI function declarations and constants
Private Declare Function Rectangle 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 Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hDC As Long) As Long
Private Declare Function SetROP2 Lib "gdi32" (ByVal hDC As Long, ByVal nDrawMode As Long) As Long
Private Const R2_NOTXORPEN = 10
Dim m_map As Object
' variables that keep track of moving the indicator
Dim m_hDC As Long ' a DC to draw into
Dim m_hWnd As Long ' window handle
Dim m_xMin As Integer, m_yMin As Integer ' drag indicator
Dim m_xMax As Integer, m_yMax As Integer ' drag indicator
Dim m_xPrev As Integer ' click location
Dim m_yPrev As Integer ' click location
Function DragFinish(x As Single, y As Single) As Rectangle
Rectangle m_hDC, m_xMin, m_yMin, m_xMax, m_yMax
ReleaseDC m_hWnd, m_hDC
' return the rectangle
Dim r As New Rectangle
PixelsRectToMap m_xMin, m_yMin, m_xMax, m_yMax, r
Set DragFinish = r
End Function
Function DragMove(x As Single, y As Single) As Rectangle
' current position
xNext = x / 15 ' convert to pixels
yNext = y / 15 ' convert to pixels
Rectangle m_hDC, m_xMin, m_yMin, m_xMax, m_yMax
m_xMin = m_xMin + (xNext - m_xPrev)
m_xMax = m_xMax + (xNext - m_xPrev)
m_yMin = m_yMin + (yNext - m_yPrev)
m_yMax = m_yMax + (yNext - m_yPrev)
Rectangle m_hDC, m_xMin, m_yMin, m_xMax, m_yMax
m_xPrev = xNext
m_yPrev = yNext
' return the rectangle
Dim r As New Rectangle
PixelsRectToMap m_xMin, m_yMin, m_xMax, m_yMax, r
Set DragMove = r
End Function
Sub DragStart(rect As Rectangle, map As Object, x As Single, y As Single)
Set m_map = map
' initialize the hwnd and hdc variables
m_hWnd = m_map.hwnd
m_hDC = GetDC(m_hWnd)
SetROP2 m_hDC, R2_NOTXORPEN ' raster op for inverting
MapRectToPixels rect, m_xMin, m_yMin, m_xMax, m_yMax
' draw the rectangle
Rectangle m_hDC, m_xMin, m_yMin, m_xMax, m_yMax
' remember the click position
m_xPrev = x / 15 ' convert to pixels
m_yPrev = y / 15 ' convert to pixels
End Sub
Private Sub MapRectToPixels(r As Rectangle, xMin As Integer, yMin As Integer, xMax As Integer, yMax As Integer)
Dim p As New Point
Dim xc As Single, yc As Single
p.x = r.Left
p.y = r.Top
m_map.FromMapPoint p, xc, yc
xMin = xc / 15 ' convert to pixels
yMin = yc / 15 ' convert to pixels
p.x = r.Right
p.y = r.Bottom
m_map.FromMapPoint p, xc, yc
xMax = xc / 15 ' convert to pixels
yMax = yc / 15 ' convert to pixels
End Sub
Sub PixelsRectToMap(xMin As Integer, yMin As Integer, xMax As Integer, yMax As Integer, r As Rectangle)
Dim xc As Single, yc As Single
xc = 15 * xMin ' convert to twips
yc = 15 * yMin ' convert to twips
Set p = m_map.ToMapPoint(xc, yc)
r.Left = p.x
r.Top = p.y
xc = 15 * xMax ' convert to twips
yc = 15 * yMax ' convert to twips
Set p = m_map.ToMapPoint(xc, yc)
r.Right = p.x
r.Bottom = p.y
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -