Solved

Declare Function GetCursorPos Lib "user32 mouse position

Posted on 2007-03-23
5
2,411 Views
Last Modified: 2008-02-07
Hi Experts
I have got the following code from you guys to simulate the mouse move on a combo box for my tooltips.
I am trying to modify it where the tooltip will be dislayed on the entire combobox not just the dropdown arrow or the very beggining.
I am trying to trap the whole width of the combobox by using something like:
cboLeft = combo.left
cblRight = cboleft + combo.width
The problem is different measurments or ?
Rect.left gives 549 and combo.left gives 6540
How can i code this?

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

Private Sub Timer1_Timer()
Dim lCmbHwnd As Long, lRet As Long
Dim rRect As RECT, mPoint As POINTAPI

lCmbHwnd = Combo1.hwnd

If (GetWindowRect(lCmbHwnd, rRect)) Then
    GetCursorPos mPoint
   
    If (rRect.Left <= mPoint.x And rRect.Right >= mPoint.x) And _
       (rRect.Top <= mPoint.y And rRect.Bottom >= mPoint.y) Then
            'user is in the region of the combo box
            MsgBox "Hello"
    End If
End If

End Sub
0
Comment
Question by:isnoend2001
  • 2
  • 2
5 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 125 total points
ID: 18784050
Use the PtInRect() API:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/rectangl_1644.asp

For VB6 declaration:

    Private Declare Function PtInRect Lib "user32" (lpRect As RECT, ByVal ptx As Long, ByVal pty As Long) As Long

Then something like:

    If (GetWindowRect(lCmbHwnd, rRect)) Then
        GetCursorPos mPoint
   
        If PtInRect(rRect, mPoint.x, mPoint.Y) <> 0 Then
            'user is in the region of the combo box
            MsgBox "Hello"
        End If
    End If
0
 
LVL 22

Assisted Solution

by:danaseaman
danaseaman earned 125 total points
ID: 18784069
API WindowFromPoint will also work:

Option Explicit

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 WindowFromPoint Lib "user32.dll" (ByVal xPoint As Long, ByVal yPoint As Long) As Long

Private Sub Form_Load()
   Dim i As Long
   For i = 1 To 10
      Combo1.AddItem "Item " & i
   Next
   Combo1.ListIndex = 0
End Sub

Private Sub Timer1_Timer()
   Dim mPoint As POINTAPI
   GetCursorPos mPoint
   If WindowFromPoint(mPoint.x, mPoint.y) = Combo1.hwnd Then
      MsgBox "Hello"
   End If
End Sub

0
 

Author Comment

by:isnoend2001
ID: 18784268
Thanks guys
I have noticed i have asked 156 questions in the last couple years and when i see you guys names i
pay attention. thanks for the 2 fast and accurate answers
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18784293
Thanx for the compliment...and you're welcome!  Glad you split points as danaseaman gave a great answer as well.  =)
0
 

Author Comment

by:isnoend2001
ID: 18784334
Went thru all that and forgot my custom tool.tips need a hwnd, oh well may a message box
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question