Module:
Public Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Integer, ByVal yPoint As Integer) As IntPtr
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As UInteger, ByRef lpdwProcessId As IntPtr) As IntPtr
Dim PhandleA As IntPtr
Public Structure POSSITION
Dim X As Single
Dim Y As Single
End Structure
Public Function WindowPointXY(ByVal xPoint As UInteger, ByVal yPoint As UInteger) As UInteger
Dim hwnd As UInteger
Dim PidPoint As UInteger
hwnd = WindowFromPoint(xPoint, yPoint)
GetWindowThreadProcessId(hwnd, PidPoint)
Return PidPoint
End Function
Form:
Private Sub PictureBox1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
PictureBox1.Cursor = New Cursor(New Bitmap(My.Resources.Bee).GetHicon())
PictureBox1.Image = Nothing
End Sub
Private Sub PictureBox1_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
Phandle = WindowPointXY((Windows.Forms.Cursor.Position.X), (Windows.Forms.Cursor.Position.Y))
PictureBox1.Image = My.Resources.Bee
PictureBox1.Cursor = Cursors.Arrow
Label1.Text = "讀取到的進程名稱:" & Process.GetProcessById(Phandle).ProcessName
End Sub