Solved

Declare Function GetCursorPos Lib "user32 mouse position

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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…

733 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