472,807 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,807 software developers and data experts.

find process by moving target over form window

I found this code(vb only) and it does about the same thing(in vb, not vb .NET 2005)
Expand|Select|Wrap|Line Numbers
  1. Attribute VB_Name = "Form1"
  2. Attribute VB_GlobalNameSpace = False
  3. Attribute VB_Creatable = False
  4. Attribute VB_PredeclaredId = True
  5. Attribute VB_Exposed = False
  6. Option Explicit
  7. 'Api Spy Example by PAT or JK
  8. 'Webpage: http://www.patorjk.com/
  10. 'This is just a small example on how to do a drap and drop
  11. 'api spy.
  13. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
  14. Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
  15. Private Declare Function GetModuleFileName Lib "Kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
  16. Private Declare Function GetWindowWord Lib "user32" (ByVal hwnd As Long, ByVal nIndex As Long) As Integer
  17. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  18. Private Declare Function getparent Lib "user32" Alias "GetParent" (ByVal hwnd As Long) As Long
  19. Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
  20. Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
  21. Private Declare Function GetActiveWindow Lib "user32" () As Long
  22. Private Declare Function SetActiveWindow Lib "user32" (ByVal hwnd As Long) As Long
  23. Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
  25. Private Const SWP_NOMOVE = 2
  26. Private Const SWP_NOSIZE = 1
  27. Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
  28. Private Const HWND_TOPMOST = -1
  29. Private Const HWND_NOTOPMOST = -2
  31. Private Type POINTAPI
  32.     x As Long
  33.     Y As Long
  34. End Type
  36. Public Sub StayOnTop(Frm As Form)
  37. Call SetWindowPos(Frm.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
  38. End Sub
  40. Function MakeOne(Text As String) As String
  41.     ' this sub just takes all the Chr(13) and Chr(10) out of
  42.     ' the text. I know I could have written a sub that was quicker
  43.     ' using the Instr function, but when I used this it seemed
  44.     ' pretty fast so I just left it this way.
  45.     Dim i As Integer, t$, BadChr(1 To 2) As String
  46.     For i = 1 To Len(Text)
  47.         If Mid$(Text, i, 1) <> Chr$(13) And Mid$(Text, i, 1) <> Chr$(10) Then
  48.             t$ = t$ & Mid$(Text, i, 1)
  49.         End If
  50.         MakeOne = t$
  51.     Next
  52. End Function
  55. Private Sub Command1_Click()
  56. MsgBox "Drag and drop the ring onto the window you want to find the information on.", 32, "PAT or JK"
  57. End Sub
  59. Private Sub Command2_Click()
  60. MsgBox "Example By: PAT or JK" & Chr(13) & "Webpage: http://www.patorjk.com/", 32, "PAT or JK"
  61. End Sub
  63. Private Sub Command3_Click()
  64. End
  65. End Sub
  67. Private Sub Form_Load()
  68. StayOnTop Me 'set form on top
  69. Picture1.Picture = Picture2.Picture ' give picture1 the ring picture
  70. End Sub
  72. Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
  73. Picture1.Picture = Me.Picture ' set the picture to nothing
  74. Picture1.MousePointer = 99 ' set the mousepointer to the ring
  75. End Sub
  77. Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
  78. If Button = 1 Then ' if the mouse button is down then
  79.     Call ApiSpyStuff ' spy on the windows
  80. End If
  81. End Sub
  83. Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, x As Single, Y As Single)
  84. Picture1.MousePointer = 0 ' set the mouse pointer back to normal
  85. Picture1.Picture = Picture2.Picture ' give picture1 the ring picture
  86. Call ApiSpyStuff ' get the info from the window
  87. End Sub
  89. Sub ApiSpyStuff()
  90. ' This sub does all the "api spy stuff"
  91. Dim CursorPos As POINTAPI, WinOver As Long
  92. Dim WinText As String, Z As Long, WinClassName As String
  93. Dim WinParent As Long, ParentWindowText As String
  94. Dim ParentClassName As String
  95. Static WinPrevious As Long
  97. ' find where your cursor is
  98. Call GetCursorPos(CursorPos)
  99. ' get the x and y points from that position
  100. WinOver = WindowFromPoint(CursorPos.x, CursorPos.Y)
  102. ' Make sure the window is a different window
  103. If WinOver <> WinPrevious Then
  104.     ' set the old window equal to the new window (for next time)
  105.     WinPrevious = WinOver
  106.     ' Window Handle
  107.     Label7.Caption = WinOver
  109.     ' Window Text
  110.     WinText = String(100, Chr(0))
  111.     Z = GetWindowText(WinOver, WinText, 100)
  112.     Label8.Caption = Chr$(34) & MakeOne(Left(WinText, Z)) & Chr$(34)
  114.     ' Window Class Name
  115.     WinClassName = String(100, Chr(0))
  116.     Z = GetClassName(WinOver, WinClassName, 100)         ' Window Class
  117.     Label9.Caption = Chr$(34) & Left(WinClassName, Z) & Chr$(34)
  119.     ' Parent Window Handle
  120.     WinParent = getparent(WinOver)
  122.     If WinParent <> 0 Then
  123.         ' Parent window handle
  124.         Label10.Caption = WinParent
  126.         ' Parent Window Text
  127.         ParentWindowText = String(100, Chr(0))
  128.         Z = GetWindowText(WinParent, ParentWindowText, 100)
  129.         Label11.Caption = Chr$(34) & Left(ParentWindowText, Z) & Chr$(34)
  131.         ' Parent Window Class
  132.         ParentClassName = String(100, Chr(0))
  133.         Z = GetClassName(WinParent, ParentClassName, 100)
  134.         Label12.Caption = Chr$(34) & Left(ParentClassName, Z) & Chr$(34)
  135.     Else
  136.         Label10.Caption = "NONE"
  137.         Label11.Caption = "NONE"
  138.         Label12.Caption = "NONE"
  139.     End If
  140. End If
  141. End Sub 
I want to do the same thing, I can't find API spy, also, when this gets near done; what code would be required for the user to click on a button(that has transparency) like a target then click on a window and will return the point coords. of the top left corner to the program?

-- yes, i have tried this, i don't know vb, but have attempted to replicate this in .NET but was a falure.
Dec 29 '06 #1
0 1822

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Rui Pestana | last post by:
Hello all, I want to use the POST method to submit the form and then grab the parameters in the asp file with request.form("parm"). The problem is that I am using the _search target to open...
by: Federico Bari | last post by:
Hi all, does somebody know how to target the answer of a form to an iframe (in ie expecially)???? I use iframe as temporary object to redirect the content do a layer built with a <div...> tag;...
by: Matt | last post by:
In the following code, page1.asp is inside the frame of main.html. When the user click submit button in page1.asp, it will submit the form and open a new window called page2.asp. When the user...
by: Simon Wigzell | last post by:
I just want my form target to be another page but open it in the same window. Here is my code for the 2 pages : -------------------------------form1.htm------------------------------------...
by: Saurabh Sharma | last post by:
Hi I found a particular process that is running on my machine. I have th eprocess ID for that how to set Focus to that Process Regards Saurabh
by: msnews.microsoft.com | last post by:
I want to redirect the user to a url outside of our website but I want it to preserve our application's window by opening a new window. We have a datagrid that has five hyperlink columns containing...
by: crater | last post by:
I have a web form with several "submit" buttons. One of these uploads a file, and I want to validate the user input prior to submitting the form. I have an event handler specified with the...
by: Bryan | last post by:
Hi , I am using ADO (ADODB) with access database. Not sure what I am doing wrong.here. Can anyone please help me? string mdbFile = System.IO.Directory.GetCurrentDirectory() +" \\bTrack.mdb;"...
by: Erwin Moller | last post by:
Hi group, I encoutered page validation error, but I don't know a way around. The page has the following doctype: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: lllomh | last post by:
How does React native implement an English player?
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.