Страница: 1 | 2 |
Вопрос: Как решить данную проблему?
Добавлено: 14.03.10 18:14
Номер ответа: 16Автор ответа: Alex111
Вопросов: 1Ответов: 13
Профиль | | #16
Добавлено: 16.03.10 19:47
А в маленьком тексбоксе все ОК. Спасибо вам.
Ответить
Номер ответа: 17Автор ответа: Winand
Вопросов: 87Ответов: 2795
Web-сайт: winandfx.narod.ru Профиль | | #17
Добавлено: 17.03.10 00:17
Арх! ну вот проверил, это последняя функция, которую я забыл)
Public Sub lngToArr(ByRef arrTo() As Byte , ByRef lng As Long , ByRef pos As Long )
CopyMemory arrTo(pos), ByVal VarPtr(lng), 4
pos = pos + 4
End Sub
hwnd - хендл формы в коде которой написан этот код (для обозначения окна где будет располагаться текстбокс)
10, 10, 200, 20 - left, top, width, height
TxtEdit.init hwnd, 10, 10, 200, 20
Ответить
Номер ответа: 18Автор ответа: Alex111
Вопросов: 1Ответов: 13
Профиль | | #18
Добавлено: 17.03.10 18:11
Привет, все сделал. А TxtEdit не могу поставить в Multiline. Пишу TxtEdit.Multiline = true Ругается.
Ответить
Номер ответа: 19Автор ответа: Winand
Вопросов: 87Ответов: 2795
Web-сайт: winandfx.narod.ru Профиль | | #19
Добавлено: 18.03.10 00:01
Естественно, ведь там же нет таких функций. Я их не стал писать, ибо не нужно было
Но раз уж понадобилось) Мультилайн можно указать последним параметром init, а еще можно изменять управляя свойством Multiline во время выполнения программы. Как вы знаете, в обычном текстбоксе этого делать низя
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal length As Long )
Private Declare Function OleTranslateColor Lib "oleaut32.dll" (ByVal lOleColor As Long , ByVal lHPalette As Long , ByRef lColorRef As Long ) As Long
Private Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Long , ByVal nCmdShow As Long ) As Long
Dim m_Font As IFont
Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long ) As Long
Private Declare Function CreateBrushIndirect Lib "gdi32.dll" (ByRef lpLogBrush As LOGBRUSH) As Long
Private Type LOGBRUSH
lbStyle As Long
lbColor As Long
lbHatch As Long
End Type
Private m_BackColor As Long
Private m_BackColorColor As Long
Private m_ForeColor As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long , ByRef lpRect As RECT) As Long
Private Declare Function GetClientRect Lib "user32.dll" (ByVal hwnd As Long , ByRef lpRect As RECT) As Long
Private Declare Function SetBkColor Lib "gdi32.dll" (ByVal hdc As Long , ByVal crColor As Long ) As Long
Private Declare Function SetTextColor Lib "gdi32.dll" (ByVal hdc As Long , ByVal crColor As Long ) As Long
Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExW" (ByVal dwExStyle As Long , ByVal lpClassName As Long , _
ByVal lpWindowName As Long , ByVal dwStyle As Long , ByVal x As Long , ByVal y As Long , _
ByVal nWidth As Long , ByVal nHeight As Long , ByVal hWndParent As Long , _
ByVal hMenu As Long , ByVal hInstance As Long , lpParam As Any) As Long
Private Declare Function DestroyWindow Lib "user32.dll" (ByVal hwnd As Long ) As Long
Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongW" (ByVal hwnd As Long , ByVal nIndex As Long , ByVal dwNewLong As Long ) As Long
Private Const GWL_WNDPROC As Long = -4
Private Declare Function DefWindowProc Lib "user32.dll" Alias "DefWindowProcW" (ByVal hwnd As Long , ByVal wMsg As Long , ByVal wParam As Long , ByVal lParam As Long ) As Long
Private Declare Function CallWindowProc Lib "user32.dll" Alias "CallWindowProcW" (ByVal lpPrevWndFunc As Long , ByVal hwnd As Long , ByVal msg As Long , ByVal wParam As Long , ByVal lParam As Long ) As Long
Private Const WS_EX_WINDOWEDGE As Long = &H100&
Private Const WS_EX_CLIENTEDGE As Long = &H200&
Private Const WS_EX_OVERLAPPEDWINDOW As Long = (WS_EX_WINDOWEDGE Or WS_EX_CLIENTEDGE)
Private Const WS_VISIBLE As Long = &H10000000
Private Const WS_CHILD As Long = &H40000000
Private Const ES_AUTOHSCROLL As Long = &H80&
Private Const ES_NOHIDESEL As Long = &H100&
Private Const ES_MULTILINE As Long = &H4&
Private Const ES_AUTOVSCROLL As Long = &H40&
Private Const WS_VSCROLL As Long = &H200000
Private Declare Function MoveWindow Lib "user32.dll" (ByVal hwnd As Long , ByVal x As Long , ByVal y As Long , ByVal nWidth As Long , ByVal nHeight As Long , ByVal bRepaint As Long ) As Long
Const AsmMain As String = "558BEC83C4FC8D45FC50FF7514FF7510FF750CFF75086800000000B800000000FFD08B45FCC9C21000"
Private ASMArr() As Byte
Private editproc As Long
Private editwnd As Long
Private prtproc As Long
Private prtwnd As Long
Private parent As Long
Private multilined As Boolean
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageW" (ByVal hwnd As Long , ByVal wMsg As Long , ByVal wParam As Long , lParam As Any) As Long
Private Const EM_LIMITTEXT As Long = &HC5
Private Const EM_SETSEL As Long = &HB1
Private Const EM_LINELENGTH As Long = &HC1
Private Const EM_GETLINE As Long = &HC4
Private Const WM_SETFONT As Long = &H30
Private Const WM_NCPAINT = &H85
Private Const WM_ERASEBKGND = &H14
Private Const WM_PAINT = &HF
Private Const WM_NCHITTEST = &H84
Private Const WM_SETCURSOR = &H20
Private Const WM_NCMOUSEMOVE = &HA0
Private Const WM_MOUSEMOVE = &H200
Private Const WM_KEYDOWN As Long = &H100
Private Const WM_KEYUP As Long = &H101
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_RBUTTONDOWN = &H204
Private Const WM_LBUTTONUP = &H202
Private Const WM_RBUTTONUP = &H205
Private Const WM_CHAR As Long = &H102
Private Const WM_SETFOCUS As Long = &H7
Private Const WM_KILLFOCUS As Long = &H8
Private Const WM_DESTROY As Long = &H2
Private Const WM_IME_SETCONTEXT As Long = &H281
Private Const WM_IME_NOTIFY As Long = &H282
Private Const WM_NCDESTROY As Long = &H82
Private Const WM_CTLCOLOREDIT As Long = &H133
Private Const WM_SETTEXT As Long = &HC
Private Const WM_COMMAND As Long = &H111
Private Const EN_CHANGE As Long = &H300
Public Event KeyDown(ByRef KeyCode As Long , ByRef lParam As Long )
Public Event KeyUp(ByRef KeyCode As Long , ByRef lParam As Long )
Public Event MouseDown(ByVal Button As Long )
Public Event MouseUp(ByVal Button As Long )
Public Event GotFocus()
Public Event Changed()
Public Function EditWindowProc(ByVal hwnd As Long , ByVal uMsg As Long , ByVal wParam As Long , ByVal lParam As Long ) As Long
Select Case uMsg
Case WM_SETFOCUS: RaiseEvent GotFocus
Case WM_KEYDOWN: RaiseEvent KeyDown(wParam, lParam)
Case WM_KEYUP: RaiseEvent KeyUp(wParam, lParam)
Case WM_LBUTTONDOWN: RaiseEvent MouseDown(vbLeftButton)
Case WM_RBUTTONDOWN: RaiseEvent MouseDown(vbRightButton)
Case WM_LBUTTONUP: RaiseEvent MouseUp(vbLeftButton)
Case WM_RBUTTONUP: RaiseEvent MouseUp(vbRightButton)
Case WM_CTLCOLOREDIT:
SetBkColor wParam, m_BackColorColor
SetTextColor wParam, m_ForeColor
EditWindowProc = m_BackColor
Exit Function
Case WM_COMMAND:
Select Case wParam \ &H10000
Case EN_CHANGE:
RaiseEvent Changed
End Select
Case WM_PAINT:
EditWindowProc = CallWindowProc(editproc, hwnd, uMsg, wParam, lParam)
EditWindowProc = DefWindowProc(hwnd, uMsg, wParam, lParam)
Exit Function
End Select
EditWindowProc = CallWindowProc(editproc, hwnd, uMsg, wParam, lParam)
End Function
Public Sub Move(Optional ByVal pLeft As Long = -1, Optional ByVal pTop As Long = -1, Optional ByVal pWidth As Long = -1, Optional ByVal pHeight As Long = -1)
Dim rc As RECT, rcp As RECT
GetWindowRect parent, rcp
GetWindowRect prtwnd, rc
MoveWindow prtwnd, IIf(pLeft <> -1, pLeft, rc.Left - rcp.Left), _
IIf(pTop <> -1, pTop, rc.Top - rcp.Top), _
IIf(pWidth <> -1, pWidth, rc.Right - rc.Left), _
IIf(pHeight <> -1, pHeight, rc.Bottom - rc.Top), 1
MoveWindow editwnd, 0, 0, _
IIf(pWidth <> -1, pWidth, rc.Right - rc.Left), _
IIf(pHeight <> -1, pHeight, rc.Bottom - rc.Top), 1
End Sub
Private Sub StartSubclass(ByRef ASM() As Byte , ByVal hwnd As Long , ByRef OldWndProc As Long , Optional ByVal ProcNumber As Long )
Dim lng As Long , tPtr As Long
lng = Len(AsmMain) \ 2&
ReDim ASM(0 To lng - 1)
For lng = 0 To lng - 1
ASM(lng) = val("&H" & Mid$(AsmMain, (lng) * 2& + 1, 2&))
Next lng
Call CopyMemory(tPtr, ByVal ObjPtr(Me ), 4&)
Call CopyMemory(lng, ByVal tPtr + &H1C + (4& * ProcNumber), 4&)
Call CopyMemory(ASM(23), ObjPtr(Me), 4&)
Call CopyMemory(ASM(28), lng, 4&)
OldWndProc = SetWindowLong(hwnd, &HFFFC, VarPtr(ASM(0)))
End Sub
Private Sub StopSubclass(ByVal hwnd As Long , ByVal OldWndProc As Long )
Call SetWindowLong(hwnd, &HFFFC, OldWndProc)
End Sub
Public Sub init(ByVal hParent As Long , Optional ByVal pLeft As Long = 0, Optional ByVal pTop As Long = 0, Optional ByVal pWidth As Long = 200, Optional ByVal pHeight As Long = 20, Optional ByVal multi As Boolean = False )
parent = hParent
multilined = multi
prtwnd = CreateWindowEx(0, StrPtr("STATIC" ), StrPtr("" ), _
WS_VISIBLE Or WS_CHILD, _
pLeft, pTop, pWidth, pHeight, hParent, 0&, App.hInstance, ByVal 0&)
editwnd = CreateWindowEx(0, StrPtr("EDIT" ), StrPtr("" ), _
WS_VISIBLE Or WS_CHILD Or ES_AUTOHSCROLL Or ES_NOHIDESEL Or IIf(multi, ES_MULTILINE Or ES_AUTOVSCROLL Or WS_VSCROLL, 0), _
0, 0, pWidth, pHeight, prtwnd, 0, App.hInstance, ByVal 0&)
Call StartSubclass(ASMArr, prtwnd, prtproc)
Call StartSubclass(ASMArr, editwnd, editproc)
Dim c1 As Long , c2 As Long
If OleTranslateColor(vbWindowBackground, 0, c1) Then BackColor = vbBlack Else BackColor = c1
If OleTranslateColor(vbWindowText, 0, c2) Then ForeColor = vbWhite Else ForeColor = c2
Set m_Font = New StdFont
m_Font.name = "Verdana"
SendMessage editwnd, WM_SETFONT, m_Font.hFont, ByVal 1
End Sub
Private Sub Class_Terminate()
If editproc Then Call StopSubclass(editwnd, editproc): editproc = 0
If prtproc Then Call StopSubclass(prtwnd, editproc): prtproc = 0
DestroyWindow editwnd
DestroyWindow prtwnd
DeleteObject m_BackColor
DeleteObject m_ForeColor
Call m_Font.ReleaseHfont(m_Font.hFont)
End Sub
Public Sub SelectText(Optional ByVal pStart As Long = 0, Optional ByVal pFinish As Long = -1)
SendMessage editwnd, EM_SETSEL, 0, ByVal -1
End Sub
Public Property Let TextLimit(ByVal maxlen As Long )
SendMessage editwnd, EM_LIMITTEXT, maxlen, ByVal 0
End Property
Public Property Let Font(ByVal fontname As String )
m_Font.name = fontname
SendMessage editwnd, WM_SETFONT, m_Font.hFont, ByVal 1
End Property
Public Property Get length() As Long
length = SendMessage(editwnd, EM_LINELENGTH, 0, ByVal 0)
End Property
Public Property Get Text() As String
Dim textlen As Long , copied As Long
If b(textlen, length) Then
ReDim buf(textlen * 2 - 1) As Byte
lngToArr buf, textlen, 0
copied = SendMessage(editwnd, EM_GETLINE, 0, buf(0))
Text = MidB(buf, 1, copied * 2)
End If
End Property
Public Property Let Text(ByRef txt As String )
Call SendMessage(editwnd, WM_SETTEXT, 0, ByVal StrPtr(txt))
End Property
Public Property Get Width() As Long
Dim rc As RECT
GetWindowRect editwnd, rc
Width = rc.Right - rc.Left
End Property
Public Property Get Height() As Long
Dim rc As RECT
GetWindowRect editwnd, rc
Height = rc.Bottom - rc.Top
End Property
Public Property Get Left() As Long
Dim rc As RECT, rcp As RECT
GetWindowRect parent, rcp
GetWindowRect prtwnd, rc
Left = rc.Left - rcp.Left
End Property
Public Property Get Top() As Long
Dim rc As RECT, rcp As RECT
GetWindowRect parent, rcp
GetWindowRect prtwnd, rc
Top = rc.Top - rcp.Top
End Property
Public Property Let BackColor(ByVal Color As Long )
Dim lb As LOGBRUSH
lb.lbColor = Color
lb.lbStyle = 0
lb.lbHatch = 0
m_BackColor = CreateBrushIndirect(lb)
m_BackColorColor = Color
End Property
Public Property Let ForeColor(ByVal Color As Long )
m_ForeColor = Color
End Property
Public Property Let Visible(ByVal bool As Boolean )
Const SW_SHOW = &H5
Const SW_HIDE = &H0
ShowWindow prtwnd, IIf(bool , SW_SHOW, SW_HIDE)
End Property
Public Property Let Multiline(ByVal bool As Boolean )
Dim l As Long , t As Long , W As Long , H As Long , txt As String
l = Left
t = Top
W = Width
H = Height
txt = Text
Class_Terminate
init parent, l, t, W, H, bool
Text = txt
multilined = bool
End Property
Public Property Get Multiline() As Boolean
Multiline = multilined
End Property
Private Function b(p1 As Long , p2 As Long ) As Boolean
p1 = p2
b = CBool (p1)
End Function
Public Sub lngToArr(ByRef arrTo() As Byte , ByRef lng As Long , ByRef pos As Long )
CopyMemory arrTo(pos), ByVal VarPtr(lng), 4
pos = pos + 4
End Sub
Ответить
Номер ответа: 20Автор ответа: Alex111
Вопросов: 1Ответов: 13
Профиль | | #20
Добавлено: 18.03.10 02:02
А что эта за константа? Const AsmMain As String = "558BEC83C4FC8D45FC50FF7514FF7510FF750CFF75086800000000B800000000FFD08B45FCC9C21000"
Ответить
Номер ответа: 22Автор ответа: Winand
Вопросов: 87Ответов: 2795
Web-сайт: winandfx.narod.ru Профиль | | #22
Добавлено: 23.03.10 02:12
обнаружил две проблемы
-свойство Text возвращает только первую строку мультилайнового текста
-ReDim buf(textlen * 2 - 1 ) As Byte заставляет программу периодически падать)
Вот багфикс
Private Const EM_GETLINECOUNT As Long = &HBA
Private Const EM_LINEINDEX As Long = &HBB
Public Property Get Text() As String
Dim textlen As Long , lineCount As Long , firstchar As Long
Dim copied As Long , i As Long
If multilined Then
lineCount = SendMessage(editwnd, EM_GETLINECOUNT, 0, 0&)
ReDim res(lineCount - 1) As String
For i = 0 To lineCount - 1
firstchar = SendMessage(editwnd, EM_LINEINDEX, i, ByVal 0)
If b(textlen, SendMessage(editwnd, EM_LINELENGTH, firstchar, ByVal 0)) Then
ReDim buf(textlen * 2) As Byte
lngToArr buf, textlen, 0
copied = SendMessage(editwnd, EM_GETLINE, i, buf(0))
res(i) = MidB(buf, 1, copied * 2)
End If
Next i
Text = Join$(res, vbNewLine)
Else
If b(textlen, length) Then
ReDim buf(textlen * 2) As Byte
lngToArr buf, textlen, 0
copied = SendMessage(editwnd, EM_GETLINE, i, buf(0))
Text = MidB(buf, 1, copied * 2)
End If
End If
End Property
Ответить
Страница: 1 | 2 |
Поиск по форуму