Solved

Declare Function GetCursorPos Lib "user32 mouse position

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

707 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

16 Experts available now in Live!

Get 1:1 Help Now