?
Solved

Declare Function GetCursorPos Lib "user32 mouse position

Posted on 2007-03-23
5
Medium Priority
?
2,560 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 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 500 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 86

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

741 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