Solved

Declare Function GetCursorPos Lib "user32 mouse position

Posted on 2007-03-23
5
2,376 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

932 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now