Private Declare Function ReleaseDC Lib "user32.dll" _
(ByVal hWnd As Long, ByVal hdc As Long) As Long
Private Declare Function LineTo Lib "gdi32.dll" _
(ByVal hdc As Long, ByVal nXEnd As Long, ByVal nYEnd As Long) As Long
Private Declare Function MoveToEx Lib "gdi32.dll" _
(ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpCoord As Long) As Long
Private Declare Function GetDC Lib "user32.dll" (ByVal hWnd As Long) As Long
Private Declare Function CreatePen Lib "gdi32.dll" _
(ByVal fnPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Private Const PS_SOLID = 0
Private Const PS_DASH = 1
Private Const PS_DOT = 2
Private Const PS_DASHDOT = 3
Private Const PS_DASHDOTDOT = 4
Private Const PS_NULL = 5
Private Const PS_INSIDEFRAME = 6
Private Declare Function DeleteObject Lib "gdi32.dll" _
(ByVal hObject As Long) As Long
Private Declare Function SelectObject Lib "gdi32.dll" _
(ByVal hdc As Long, ByVal hgdiobj As Long) As Long
Private Declare Function SendMessageAny Lib "user32.dll" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal MSG As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const EM_SETTABSTOPS = &HCB
Private Const EM_POSFROMCHAR = &HD6
Private Type POINTAPI
x As Long
y As Long
End Type
Dim Tabstops(3) As Long, TabstopsPOS(3) As POINTAPI
Private Sub Form_Load()
Dim rc As Long, x As Long, y As Long
Tabstops(0) = 30
Tabstops(1) = 20
Tabstops(2) = 40
Tabstops(3) = 30
Call SendMessageAny(Me.Text1.hWnd, EM_SETTABSTOPS, 3, Tabstops(0))
Me.Text1.Text = vbTab & vbTab & vbTab & vbTab
For a = 0 To 3
rc = SendMessageAny(Me.Text1.hWnd, EM_POSFROMCHAR, a, ByVal 0)
TabstopsPOS(a).x = LWORD(rc)
TabstopsPOS(a).y = HWORD(rc)
Next
End Sub
Private Sub Text1_Change()
Call DrawLine
End Sub
Private Function LWORD(ByVal LongValue As Long) As Integer
If (LongValue And &HFFFF&) > &H7FFF Then
LWORD = (LongValue And &HFFFF&) - &H10000
Else
LWORD = LongValue And &HFFFF&
End If
End Function
Private Function HWORD(ByVal LongValue As Long) As Integer
HWORD = (LongValue And &HFFFF0000) \ &H10000
End Function
Private Sub Text1_Click()
Call DrawLine
End Sub
Private Sub DrawLine()
Dim hdc As Long, hPen As Long, hOldPen As Long
hdc = GetDC(Me.Text1.hWnd)
hPen = CreatePen(PS_DOT, 1, vbRed)
hOldPen = SelectObject(hdc, hPen)
For a = 0 To 3
Call MoveToEx(hdc, TabstopsPOS(a).x, TabstopsPOS(a).y, 0)
Call LineTo(hdc, TabstopsPOS(a).x, Me.Text1.Height)
Next
Call SelectObject(hdc, hPen)
Call ReleaseDC(Me.Text1.hWnd, hdc)
Call DeleteObject(hPen)
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Call DrawLine
End Sub |