Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Activate applications with mouse hover?

Status
Not open for further replies.

rdgerken

Technical User
Jul 8, 2002
108
Would it be possible to activate (bring them to the top, give them focus, whatever you want to call it) different applications I have open on my desktop when I hover over them with my mouse? (These applications would just be running, not ones started by my VB app).

Thanks for any ideas/suggestions
 

Yes it could be possible between tracking where the mouse is, where the windows are and thier order let along their handles and the effect that you will get may make doing something like this more trouble than its worth.

Take for example that you are typing in word and then you want to reread what you just typed so you move the mouse and activate another application which in turn covers up what you were woring on. So then you have to move the mouse again over word but not over the reading area ...

Good Luck

 
Yes this does seem like a strange request and I have been a contract programmer for 15 years.

Yes it is possible but you will need to get in the the Windows API's and let me tell you, it is more trouble than its worth.


AGIMA - professional web hosting is our business.

AGIMA Computing
 
Strange? Not really; this sort of window behaviour is a fairly common option in things like Sun's CDE and GNOME. It's just less well known in the Windows world

I also vaguely recall that this sort of feature might have been available in one of the TweakUI releases.

However, as vb5 and AGIMA suggest, whilst certainly possible to implement using VB it is likely to be more trouble than it is worth
 
Ok, thanks for the feedback.

Sounds as if it might be out of my league.

I know it might have been a strange request, but necessary for the tool I wanted to create.
 
Hmm...

It was actually pretty easy to do. Got some help from AllAPI.net


Option Explicit

Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Dim mWndTitle As String
Dim mWndLastTitle As String

Private Sub Timer1_Timer()
Dim Pt As POINTAPI
Dim mWnd As Long

GetCursorPos Pt
mWnd = WindowFromPoint(Pt.X, Pt.Y)

If Not IsNull(mWnd) Then
mWndTitle = String(100, Chr$(0))
GetWindowText mWnd, mWndTitle, 100
mWndTitle = Left$(mWndTitle, InStr(mWndTitle, Chr$(0)) - 1)
If mWndTitle <> &quot;&quot; And mWndTitle <> &quot;0&quot; And mWndTitle <> mWndLastTitle Then
On Error GoTo skip
mWndLastTitle = mWndTitle
AppActivate mWndTitle
skip:
On Error Resume Next
End If
End If

End Sub
 
I think you'll find that you get some strange behaviour from that in W2K/XP/W2003
 
Strong,

I'm using XP and it actually works quite well. The only addition to the code that I had to make was some revisions to allow the parent windows to be found if you were hovering over a child window. However, I do agree, that is it ugly. I wish I could find an example of a better implementation.

Thanks for the feedback.
 
This works much better.

Private Sub WindowFocus_Timer()
Dim Pt As POINTAPI
Dim mWnd As Long
Dim nWnd As Long

On Error Resume Next

GetCursorPos Pt
mWnd = WindowFromPoint(Pt.X, Pt.Y)

If Not IsNull(mWnd) Then
mWnd = SetForegroundWindow(mWnd)
End If

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top