Страница: 1 | 2 |
|
Вопрос: Вопрос по vb.net
|
Добавлено: 14.02.09 15:44
|
|
Номер ответа: 25 Автор ответа: fAndOrIn
Вопросов: 5 Ответов: 344
|
Профиль | | #25
|
Добавлено: 18.02.09 20:29
|
manssika, как будто для тебя лично Father не так давно подкинул основу для этого ответа. Я сам не до конца понял, как это работает, однако... работает
На форму положить Label и вставить код- Option Explicit
- Public Sub Hover()
-
- End Sub
- Public Sub Leave()
-
- Label1 = "Курсор за пределами формы"
- End Sub
- Private Sub Form_Load()
- Label1.Left = 0: Label1.Width = Me.Width
- SetProp Me.hwnd, "OBJPTR", ObjPtr(Me)
- SetProp Me.hwnd, "FATHER", SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WndProc)
- End Sub
- Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
- Label1 = "X=" & X & " Y=" & Y
- End Sub
В отдельный модуль вставить следующее- Option Explicit
-
- Public Type TME
- cbSize As Long
- dwFlags As Long
- hwndTrack As Long
- dwHoverTime As Long
- End Type
-
- Public Declare Function TrackMouseEvent Lib "user32" (lpEventTrack As TME) As Long
- Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
- Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
- Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
- Public Declare Function SetProp Lib "user32" Alias "SetPropA" (ByVal hwnd As Long, ByVal lpString As String, ByVal hData As Long) As Long
- Public Declare Function GetProp Lib "user32" Alias "GetPropA" (ByVal hwnd As Long, ByVal lpString As String) As Long
- Public Declare Function RemoveProp Lib "user32" Alias "RemovePropA" (ByVal hwnd As Long, ByVal lpString As String) As Long
- Public Declare Sub PutMem4 Lib "msvbvm60" (Destination As Any, ByVal Source As Long)
-
- Public Const GWL_WNDPROC = (-4)
- Public Const WM_DESTROY = &H2
- Public Const WM_MOUSEMOVE = &H200
- Public Const WM_MOUSELEAVE = &H2A3
- Public Const TME_LEAVE = &H2
-
- Public Function WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
- On Error Resume Next
- Dim frm As Object
- PutMem4 frm, GetProp(hwnd, "OBJPTR")
- Select Case Msg
- Case WM_DESTROY
- RemoveProp hwnd, "BHOVER"
- RemoveProp hwnd, "OBJPTR"
- RemoveProp hwnd, "FATHER"
- Case WM_MOUSEMOVE
- If Not CBool(GetProp(hwnd, "BHOVER")) Then
- Dim tm As TME
- SetProp hwnd, "BHOVER", True
- frm.Hover
- tm.cbSize = LenB(tm)
- tm.hwndTrack = hwnd
- tm.dwFlags = TME_LEAVE
- TrackMouseEvent tm
- End If
- Case WM_MOUSELEAVE
- SetProp hwnd, "BHOVER", False
- frm.Leave
- End Select
- PutMem4 frm, 0&
- WndProc = CallWindowProc(GetProp(hwnd, "FATHER"), hwnd, Msg, wParam, lParam)
- End Function
Наверняка здесь много лишнего, но как говорят - из песни слов не выкинешь. Кстати, что-то давно Fhater не показывается... (может тоже в засаде сидит)
Ответить
|
Страница: 1 | 2 |
Поиск по форуму