VB and VBA Users Source Code: Test if the cursor/mouse in over a specified window/dialog
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Test if the cursor/mouse in over a specified window/dialog
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Thursday, September 26, 2002
Hits:
853
Category:
Windows API
Article:
The following code tests to see if the mouse/cursor is over a specific window. Option Explicit Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Type POINTAPI X As Long Y As Long End Type Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long 'Purpose : Test if the cursor is in a specific window 'Inputs : lWinHwnd The window handle to test to see if the cursor is in it. 'Outputs : Returns True if the cursor is over the specified window 'Author : Andrew Baker 'Date : 20/Sep/2002 18:17 'Notes : 'Revisions : 'Assumptions : Function CursorInWindow(lWinHwnd As Long) As Boolean Dim tWinRec As RECT, tCurPos As POINTAPI GetCursorPos tCurPos GetWindowRect lWinHwnd, tWinRec If tCurPos.Y < tWinRec.Bottom And tCurPos.Y > tWinRec.Top And tCurPos.X < tWinRec.Right And tCurPos.X > tWinRec.Left Then CursorInWindow = True Else CursorInWindow = False End If End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder