Home > Software engineering >  VB how to determine the application under the mouse
VB how to determine the application under the mouse

Time:09-17

Like my mouse on A program window can I get A process of PID and the path

CodePudding user response:

Since the process name, PID, path, these have been, then don't know is which "program", to determine what...

CodePudding user response:

I mainly want to the movement of the mouse hover to judge the program position so easily such as judged by double coordinates of the mouse coordinates of the window handle in clauses take pid handle process

CodePudding user response:

Don't want to do the task manager that the enumeration process

CodePudding user response:

Zha say is the fact that determine if the mouse left to the desktop window so the result should be explorer. Exe this meaning

CodePudding user response:

Make along while, you are "want to be" the mouse which is the window of the program, is not you "have made"...


Give you a reference method:
1. The GetCursorPos () to obtain the mouse coordinates,
2. WindowFromPoint () to obtain the mouse in the window handle,
Note that access to could be control handle, or child window handle,
This is will be "up to find" parent window, until its "parent window" is "desktop",
3. Press the "top window" of the handle, with GetWindowThreadProcessId belongs to process PID () to get to the window,

With "PID", the rest of the things, has a variety of methods to deal with the N, search for the related API yourself...

CodePudding user response:

Use Spy++ software,

CodePudding user response:

GetForegroundWindow for current top window

GetCursorPos () to obtain the coordinates of the mouse is currently

Whether the mouse in this place in front of the form
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Another kind of method USES WindowFromPoint with GetCursorPos both API

Private Sub Timer1_Timer ()
The GetCursorPos Pt
HwndVal=WindowFromPoint (Pt) X, Pt. Y)
If HwndVal=Me. HWnd Then
Me. The Caption="the mouse on the form"
ElseIf HwndVal=Picture1. The hWnd Then
Me. The Caption="the mouse in the picture box"
ElseIf HwndVal=Text1. The hWnd Then
Me. The Caption="the mouse in the text box"
End the If
End Sub

CodePudding user response:

 'according to the window handle to get the application path 
The Public Function AppPath (Optional ByVal hwn1) As String
Dim dwProcessID As Long, hProcess As Long, hModule As Long
Dim nSize As Long
If IsMissing (hwn1) Then 'If you don't write represents handle to deal with the current store
If hWnd_ & gt; 0 Then dwProcessID=ProcessID () 'GetWindowThreadProcessId hWnd_, dwProcessID
The Else
DwProcessID=ProcessID (hwn1)
End the If
HProcess=OpenProcess (PROCESS_ALL_ACCESS, 0, dwProcessID)
AppPath=Space (255)
NSize=GetModuleFileNameEx (hProcess, 0, StrPtr (AppPath), 255)
AppPath=Mid (AppPath, 1, nSize)
Call the CloseHandle (hProcess)
End Function
the handle is obtained by WindowFromPoint (no controls or window) path can be directly introduced into the Function program, relevant API functions and constants declared himself to supplement, Function is from clswindow class, if don't find statement can directly download, and then call,

W.h Wnd=332302 'own through WindowFromPoint
MsgBox w. ppName
  • Related