|
-
May 29th, 2006, 09:15 PM
#1
Thread Starter
Addicted Member
mouse move
I have a program where you move the mouse on the form to work it. I want to be able to detect when i'm not on the form such as the when the mouse is on the blue bar on the top or on the taskbar or around the window. How can i do this?
Resizing
System Balloons
If your question is answered, please mark the thread resolved by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button.
Remember to rate a post if you find it helpful 
-
May 30th, 2006, 06:13 AM
#2
Re: mouse move
Is this what you mean?
VB Code:
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function GetCapture Lib "user32" () As Long
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (X < 0) Or (Y < 0) Or (X > Form1.Width) Or (Y > Form1.Height) Then
ReleaseCapture
Label1.Caption = "Mouse is no longer over the form"
ElseIf GetCapture() <> Form1.hwnd Then
SetCapture Form1.hwnd
Label1.Caption = "Mouse is over the form"
End If
End Sub
-
May 30th, 2006, 10:00 AM
#3
Re: mouse move
that's what i was going to suggest - but every control on the form needs to be clicked twice before it responds as the first click is sent to the Form (you can detect it with the mouse_up / mouse_down events)
-
May 30th, 2006, 11:31 AM
#4
Re: mouse move
Subclass the form and trap WM_NCMOUSEMOVE and/or WM_NCMOUSELEAVE messages.
VB Code:
'[b]In Form1[/b]
Option Explicit
Private Sub Form_Load()
' Redirect messages to our new handler in the module and
' save the pointer to the old handler
pOldWindPoc = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf WndProc)
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Me.Caption = "Mouse is on client area"
End Sub
Private Sub Form_Unload(Cancel As Integer)
' Restore the previously saved message handler
SetWindowLong Me.hwnd, GWL_WNDPROC, pOldWindPoc
End Sub
VB Code:
'[b]In a module[/b]
Option Explicit
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 SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
' A pointer to the old window procedure
Public pOldWindPoc As Long
Private Const WM_NCMOUSELEAVE As Long = &H2A2
Private Const WM_NCMOUSEMOVE As Long = &HA0
Public Const GWL_WNDPROC& = (-4)
' Our new window procedure
Public Function WndProc(ByVal hwnd As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Select Case uMsg
Case WM_NCMOUSELEAVE:
Form1.Caption = "WM_NCMOUSELEAVE"
' [b]Here you can use GetCursorPos to check[/b]
' [b]if the mouse is over the form[/b]
Case WM_NCMOUSEMOVE:
Form1.Caption = "WM_NCMOUSEMOVE"
End Select
WndProc = CallWindowProc(pOldWindPoc, hwnd, uMsg, wParam, lParam)
End Function
Last edited by iPrank; May 30th, 2006 at 11:36 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|