Visual Basic, .NET, ASP, VBScript
 

   
   
     

Форум - Общий форум

Страница: 1 | 2 |

 

  Вопрос: Как решить данную проблему? Добавлено: 14.03.10 18:14  

Автор вопроса:  Alex111

Ответить

  Ответы Всего ответов: 22  

Номер ответа: 16
Автор ответа:
 Alex111



Вопросов: 1
Ответов: 13
 Профиль | | #16 Добавлено: 16.03.10 19:47
А в маленьком тексбоксе все ОК. Спасибо вам.

Ответить

Номер ответа: 17
Автор ответа:
 Winand



Вопросов: 87
Ответов: 2795
 Web-сайт: winandfx.narod.ru
 Профиль | | #17
Добавлено: 17.03.10 00:17
Арх! ну вот проверил, это последняя функция, которую я забыл)
  1. 'Write lng to pos in byte array
  2. Public Sub lngToArr(ByRef arrTo() As Byte, ByRef lng As Long, ByRef pos As Long)
  3.     CopyMemory arrTo(pos), ByVal VarPtr(lng), 4
  4.     pos = pos + 4
  5. End Sub


hwnd - хендл формы в коде которой написан этот код (для обозначения окна где будет располагаться текстбокс)
10, 10, 200, 20 - left, top, width, height
  1. 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 во время выполнения программы. Как вы знаете, в обычном текстбоксе этого делать низя
  1. '    Copyright 2009, 2010 Makarov Andrey
  2. '
  3. '    This file is part of Audica - Open Simple Audio Player.
  4. '
  5. '    Audica is free software: you can redistribute it and/or modify
  6. '    it under the terms of the GNU General Public License as published by
  7. '    the Free Software Foundation, either version 3 of the License, or
  8. '    (at your option) any later version.
  9. '
  10. '    Audica is distributed in the hope that it will be useful,
  11. '    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. '    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. '    GNU General Public License for more details.
  14. '
  15. '    You should have received a copy of the GNU General Public License
  16. '    along with Audica.  If not, see <http://www.gnu.org/licenses/>.
  17.  
  18. Option Explicit
  19. Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal length As Long)
  20. Private Declare Function OleTranslateColor Lib "oleaut32.dll" (ByVal lOleColor As Long, ByVal lHPalette As Long, ByRef lColorRef As Long) As Long
  21.  
  22. Private Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
  23. Dim m_Font As IFont
  24. Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
  25. Private Declare Function CreateBrushIndirect Lib "gdi32.dll" (ByRef lpLogBrush As LOGBRUSH) As Long
  26. Private Type LOGBRUSH
  27.     lbStyle As Long
  28.     lbColor As Long
  29.     lbHatch As Long
  30. End Type
  31. Private m_BackColor As Long
  32. Private m_BackColorColor As Long
  33. Private m_ForeColor As Long
  34.  
  35. Private Type RECT
  36.     Left As Long
  37.     Top As Long
  38.     Right As Long
  39.     Bottom As Long
  40. End Type
  41. Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, ByRef lpRect As RECT) As Long
  42. Private Declare Function GetClientRect Lib "user32.dll" (ByVal hwnd As Long, ByRef lpRect As RECT) As Long
  43.  
  44. Private Declare Function SetBkColor Lib "gdi32.dll" (ByVal hdc As Long, ByVal crColor As Long) As Long
  45. Private Declare Function SetTextColor Lib "gdi32.dll" (ByVal hdc As Long, ByVal crColor As Long) As Long
  46. Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExW" (ByVal dwExStyle As Long, ByVal lpClassName As Long, _
  47.                         ByVal lpWindowName As Long, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, _
  48.                         ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, _
  49.                         ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
  50. Private Declare Function DestroyWindow Lib "user32.dll" (ByVal hwnd As Long) As Long
  51. Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongW" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  52. Private Const GWL_WNDPROC As Long = -4
  53. 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
  54. 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
  55. Private Const WS_EX_WINDOWEDGE As Long = &H100&
  56. Private Const WS_EX_CLIENTEDGE As Long = &H200&
  57. Private Const WS_EX_OVERLAPPEDWINDOW As Long = (WS_EX_WINDOWEDGE Or WS_EX_CLIENTEDGE)
  58. Private Const WS_VISIBLE As Long = &H10000000
  59. Private Const WS_CHILD As Long = &H40000000
  60. Private Const ES_AUTOHSCROLL As Long = &H80&
  61. Private Const ES_NOHIDESEL As Long = &H100&
  62. Private Const ES_MULTILINE As Long = &H4&       'Multiline
  63. Private Const ES_AUTOVSCROLL As Long = &H40&    '
  64. Private Const WS_VSCROLL As Long = &H200000     '
  65. 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
  66. Const AsmMain As String = "558BEC83C4FC8D45FC50FF7514FF7510FF750CFF75086800000000B800000000FFD08B45FCC9C21000"
  67. Private ASMArr() As Byte
  68. Private editproc As Long
  69. Private editwnd As Long
  70. Private prtproc As Long
  71. Private prtwnd As Long
  72. Private parent As Long
  73. Private multilined As Boolean
  74.  
  75. 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
  76. Private Const EM_LIMITTEXT As Long = &HC5
  77. Private Const EM_SETSEL As Long = &HB1
  78. Private Const EM_LINELENGTH As Long = &HC1
  79. Private Const EM_GETLINE As Long = &HC4
  80. Private Const WM_SETFONT As Long = &H30
  81.  
  82. Private Const WM_NCPAINT = &H85
  83. Private Const WM_ERASEBKGND = &H14
  84. Private Const WM_PAINT = &HF
  85.  
  86. Private Const WM_NCHITTEST = &H84
  87. Private Const WM_SETCURSOR = &H20   'if the mouse causes the cursor to move within a window and mouse input is not captured
  88. Private Const WM_NCMOUSEMOVE = &HA0 'MouseMove nonclient area
  89. Private Const WM_MOUSEMOVE = &H200  'MouseMove client area
  90.  
  91. Private Const WM_KEYDOWN As Long = &H100
  92. Private Const WM_KEYUP As Long = &H101
  93. Private Const WM_LBUTTONDOWN = &H201
  94. Private Const WM_RBUTTONDOWN = &H204
  95. Private Const WM_LBUTTONUP = &H202
  96. Private Const WM_RBUTTONUP = &H205
  97. Private Const WM_CHAR As Long = &H102
  98. Private Const WM_SETFOCUS As Long = &H7
  99. Private Const WM_KILLFOCUS As Long = &H8
  100. Private Const WM_DESTROY As Long = &H2
  101. Private Const WM_IME_SETCONTEXT As Long = &H281
  102. Private Const WM_IME_NOTIFY As Long = &H282
  103. Private Const WM_NCDESTROY As Long = &H82
  104. Private Const WM_CTLCOLOREDIT As Long = &H133
  105. Private Const WM_SETTEXT As Long = &HC
  106.  
  107. Private Const WM_COMMAND As Long = &H111
  108. Private Const EN_CHANGE As Long = &H300
  109.  
  110. Public Event KeyDown(ByRef KeyCode As Long, ByRef lParam As Long)
  111. Public Event KeyUp(ByRef KeyCode As Long, ByRef lParam As Long)
  112. Public Event MouseDown(ByVal Button As Long)
  113. Public Event MouseUp(ByVal Button As Long)
  114. Public Event GotFocus()
  115. Public Event Changed()
  116.  
  117. Public Function EditWindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  118.     Select Case uMsg
  119.     Case WM_SETFOCUS: RaiseEvent GotFocus
  120.     Case WM_KEYDOWN: RaiseEvent KeyDown(wParam, lParam)
  121.     Case WM_KEYUP: RaiseEvent KeyUp(wParam, lParam)
  122.     Case WM_LBUTTONDOWN: RaiseEvent MouseDown(vbLeftButton)
  123.     Case WM_RBUTTONDOWN: RaiseEvent MouseDown(vbRightButton)
  124.     Case WM_LBUTTONUP: RaiseEvent MouseUp(vbLeftButton)
  125.     Case WM_RBUTTONUP: RaiseEvent MouseUp(vbRightButton)
  126.     Case WM_CTLCOLOREDIT:
  127.         SetBkColor wParam, m_BackColorColor
  128.         SetTextColor wParam, m_ForeColor
  129.         EditWindowProc = m_BackColor
  130.         Exit Function
  131.     Case WM_COMMAND:
  132.         Select Case wParam \ &H10000 'HiWord
  133.         Case EN_CHANGE:
  134.             RaiseEvent Changed
  135.         End Select
  136.     Case WM_PAINT:  'Без этого может прекратиться перерисовка родительского окна
  137.         EditWindowProc = CallWindowProc(editproc, hwnd, uMsg, wParam, lParam)   '???
  138.         EditWindowProc = DefWindowProc(hwnd, uMsg, wParam, lParam)
  139.         Exit Function
  140.     End Select
  141.     EditWindowProc = CallWindowProc(editproc, hwnd, uMsg, wParam, lParam)
  142. End Function
  143.  
  144. 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)
  145.     Dim rc As RECT, rcp As RECT
  146.     GetWindowRect parent, rcp
  147.     GetWindowRect prtwnd, rc
  148.     MoveWindow prtwnd, IIf(pLeft <> -1, pLeft, rc.Left - rcp.Left), _
  149.                         IIf(pTop <> -1, pTop, rc.Top - rcp.Top), _
  150.                         IIf(pWidth <> -1, pWidth, rc.Right - rc.Left), _
  151.                         IIf(pHeight <> -1, pHeight, rc.Bottom - rc.Top), 1
  152.     MoveWindow editwnd, 0, 0, _
  153.                         IIf(pWidth <> -1, pWidth, rc.Right - rc.Left), _
  154.                         IIf(pHeight <> -1, pHeight, rc.Bottom - rc.Top), 1
  155. End Sub
  156.  
  157. Private Sub StartSubclass(ByRef ASM() As Byte, ByVal hwnd As Long, ByRef OldWndProc As Long, Optional ByVal ProcNumber As Long)                 ' Сабклассинг с пом. ASM (автора не знаю...)
  158.     Dim lng As Long, tPtr As Long
  159.     lng = Len(AsmMain) \ 2&
  160.     ReDim ASM(0 To lng - 1)
  161.     For lng = 0 To lng - 1
  162.         ASM(lng) = val("&H" & Mid$(AsmMain, (lng) * 2& + 1, 2&))
  163.     Next lng
  164.     Call CopyMemory(tPtr, ByVal ObjPtr(Me), 4&)
  165.     Call CopyMemory(lng, ByVal tPtr + &H1C + (4& * ProcNumber), 4&)
  166.     Call CopyMemory(ASM(23), ObjPtr(Me), 4&)
  167.     Call CopyMemory(ASM(28), lng, 4&)
  168.     OldWndProc = SetWindowLong(hwnd, &HFFFC, VarPtr(ASM(0)))
  169. End Sub
  170.  
  171. Private Sub StopSubclass(ByVal hwnd As Long, ByVal OldWndProc As Long)
  172.     Call SetWindowLong(hwnd, &HFFFC, OldWndProc)
  173. End Sub
  174.  
  175. 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)
  176.     parent = hParent
  177.     multilined = multi
  178.     prtwnd = CreateWindowEx(0, StrPtr("STATIC"), StrPtr(""), _
  179.                 WS_VISIBLE Or WS_CHILD, _
  180.                 pLeft, pTop, pWidth, pHeight, hParent, 0&, App.hInstance, ByVal 0&)
  181.     editwnd = CreateWindowEx(0, StrPtr("EDIT"), StrPtr(""), _
  182.                 WS_VISIBLE Or WS_CHILD Or ES_AUTOHSCROLL Or ES_NOHIDESEL Or IIf(multi, ES_MULTILINE Or ES_AUTOVSCROLL Or WS_VSCROLL, 0), _
  183.                 0, 0, pWidth, pHeight, prtwnd, 0, App.hInstance, ByVal 0&)
  184.     Call StartSubclass(ASMArr, prtwnd, prtproc)
  185.     Call StartSubclass(ASMArr, editwnd, editproc)
  186.  
  187.     Dim c1 As Long, c2 As Long
  188.     If OleTranslateColor(vbWindowBackground, 0, c1) Then BackColor = vbBlack Else BackColor = c1
  189.     If OleTranslateColor(vbWindowText, 0, c2) Then ForeColor = vbWhite Else ForeColor = c2
  190.     
  191.     Set m_Font = New StdFont
  192.     m_Font.name = "Verdana"
  193.     SendMessage editwnd, WM_SETFONT, m_Font.hFont, ByVal 1
  194. End Sub
  195.  
  196. Private Sub Class_Terminate()
  197.     If editproc Then Call StopSubclass(editwnd, editproc): editproc = 0
  198.     If prtproc Then Call StopSubclass(prtwnd, editproc): prtproc = 0
  199.     DestroyWindow editwnd
  200.     DestroyWindow prtwnd
  201.     DeleteObject m_BackColor
  202.     DeleteObject m_ForeColor
  203.     Call m_Font.ReleaseHfont(m_Font.hFont)
  204. End Sub
  205.  
  206. Public Sub SelectText(Optional ByVal pStart As Long = 0, Optional ByVal pFinish As Long = -1)
  207.     SendMessage editwnd, EM_SETSEL, 0, ByVal -1
  208. End Sub
  209.  
  210. Public Property Let TextLimit(ByVal maxlen As Long)
  211.     SendMessage editwnd, EM_LIMITTEXT, maxlen, ByVal 0
  212. End Property
  213.  
  214. Public Property Let Font(ByVal fontname As String)
  215.     m_Font.name = fontname
  216.     SendMessage editwnd, WM_SETFONT, m_Font.hFont, ByVal 1
  217. End Property
  218.  
  219. Public Property Get length() As Long
  220.     length = SendMessage(editwnd, EM_LINELENGTH, 0, ByVal 0)
  221. End Property
  222.  
  223. Public Property Get Text() As String
  224.     Dim textlen As Long, copied As Long
  225.     If b(textlen, length) Then
  226.         ReDim buf(textlen * 2 - 1) As Byte
  227.         lngToArr buf, textlen, 0
  228.         copied = SendMessage(editwnd, EM_GETLINE, 0, buf(0))
  229.         Text = MidB(buf, 1, copied * 2)
  230.     End If
  231. End Property
  232.  
  233. Public Property Let Text(ByRef txt As String)
  234.     Call SendMessage(editwnd, WM_SETTEXT, 0, ByVal StrPtr(txt))
  235. End Property
  236.  
  237. Public Property Get Width() As Long
  238.     Dim rc As RECT
  239.     GetWindowRect editwnd, rc
  240.     Width = rc.Right - rc.Left
  241. End Property
  242.  
  243. Public Property Get Height() As Long
  244.     Dim rc As RECT
  245.     GetWindowRect editwnd, rc
  246.     Height = rc.Bottom - rc.Top
  247. End Property
  248.  
  249. Public Property Get Left() As Long
  250.     Dim rc As RECT, rcp As RECT
  251.     GetWindowRect parent, rcp
  252.     GetWindowRect prtwnd, rc
  253.     Left = rc.Left - rcp.Left
  254. End Property
  255.  
  256. Public Property Get Top() As Long
  257.     Dim rc As RECT, rcp As RECT
  258.     GetWindowRect parent, rcp
  259.     GetWindowRect prtwnd, rc
  260.     Top = rc.Top - rcp.Top
  261. End Property
  262.  
  263. Public Property Let BackColor(ByVal Color As Long)
  264.     Dim lb As LOGBRUSH
  265.     lb.lbColor = Color
  266.     lb.lbStyle = 0
  267.     lb.lbHatch = 0
  268.     m_BackColor = CreateBrushIndirect(lb) 'brush with new background color of editbox
  269.     m_BackColorColor = Color
  270. End Property
  271.  
  272. Public Property Let ForeColor(ByVal Color As Long)
  273.     m_ForeColor = Color
  274. End Property
  275.  
  276. Public Property Let Visible(ByVal bool As Boolean)
  277.     Const SW_SHOW = &H5
  278.     Const SW_HIDE = &H0
  279.     ShowWindow prtwnd, IIf(bool, SW_SHOW, SW_HIDE)
  280. End Property
  281.  
  282. Public Property Let Multiline(ByVal bool As Boolean)
  283.     Dim l As Long, t As Long, W As Long, H As Long, txt As String
  284.     l = Left
  285.     t = Top
  286.     W = Width
  287.     H = Height
  288.     txt = Text
  289.     Class_Terminate
  290.     init parent, l, t, W, H, bool
  291.     Text = txt
  292.     multilined = bool
  293. End Property
  294.  
  295. Public Property Get Multiline() As Boolean
  296.     Multiline = multilined
  297. End Property
  298.  
  299. 'Присвоение p2 к p1 с проверкой результата на равенство нулю
  300. Private Function b(p1 As Long, p2 As Long) As Boolean
  301.     p1 = p2
  302.     b = CBool(p1)
  303. End Function
  304.  
  305. 'Write lng to pos in byte array
  306. Public Sub lngToArr(ByRef arrTo() As Byte, ByRef lng As Long, ByRef pos As Long)
  307.     CopyMemory arrTo(pos), ByVal VarPtr(lng), 4
  308.     pos = pos + 4
  309. End Sub

Ответить

Номер ответа: 20
Автор ответа:
 Alex111



Вопросов: 1
Ответов: 13
 Профиль | | #20 Добавлено: 18.03.10 02:02
А что эта за константа?
  1. Const AsmMain As String = "558BEC83C4FC8D45FC50FF7514FF7510FF750CFF75086800000000B800000000FFD08B45FCC9C21000"

Ответить

Номер ответа: 21
Автор ответа:
 Winand



Вопросов: 87
Ответов: 2795
 Web-сайт: winandfx.narod.ru
 Профиль | | #21
Добавлено: 18.03.10 03:27
Это ассемблерный код, который выполняется для того, чтобы системные сообщения приходили в процедуру EditWindowProc

Ответить

Номер ответа: 22
Автор ответа:
 Winand



Вопросов: 87
Ответов: 2795
 Web-сайт: winandfx.narod.ru
 Профиль | | #22
Добавлено: 23.03.10 02:12
обнаружил две проблемы
-свойство Text возвращает только первую строку мультилайнового текста
-ReDim buf(textlen * 2 - 1) As Byte заставляет программу периодически падать)
Вот багфикс
  1. Private Const EM_GETLINECOUNT As Long = &HBA
  2. Private Const EM_LINEINDEX As Long = &HBB


  1. Public Property Get Text() As String
  2.     Dim textlen As Long, lineCount As Long, firstchar As Long
  3.     Dim copied As Long, i As Long
  4.     If multilined Then
  5.         lineCount = SendMessage(editwnd, EM_GETLINECOUNT, 0, 0&)
  6.         ReDim res(lineCount - 1) As String
  7.         For i = 0 To lineCount - 1
  8.             firstchar = SendMessage(editwnd, EM_LINEINDEX, i, ByVal 0)
  9.             If b(textlen, SendMessage(editwnd, EM_LINELENGTH, firstchar, ByVal 0)) Then
  10.                 ReDim buf(textlen * 2) As Byte
  11.                 lngToArr buf, textlen, 0
  12.                 copied = SendMessage(editwnd, EM_GETLINE, i, buf(0))
  13.                 res(i) = MidB(buf, 1, copied * 2)
  14.             End If
  15.         Next i
  16.         Text = Join$(res, vbNewLine)
  17.     Else
  18.         If b(textlen, length) Then
  19.             ReDim buf(textlen * 2) As Byte
  20.             lngToArr buf, textlen, 0
  21.             copied = SendMessage(editwnd, EM_GETLINE, i, buf(0))
  22.             Text = MidB(buf, 1, copied * 2)
  23.         End If
  24.     End If
  25. End Property

Ответить

Страница: 1 | 2 |

Поиск по форуму



© Copyright 2002-2011 VBNet.RU | Пишите нам