473,386 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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/
  9.  
  10. 'This is just a small example on how to do a drap and drop
  11. 'api spy.
  12.  
  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
  24.  
  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
  30.  
  31. Private Type POINTAPI
  32.     x As Long
  33.     Y As Long
  34. End Type
  35.  
  36. Public Sub StayOnTop(Frm As Form)
  37. Call SetWindowPos(Frm.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
  38. End Sub
  39.  
  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
  53.  
  54.  
  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
  58.  
  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
  62.  
  63. Private Sub Command3_Click()
  64. End
  65. End Sub
  66.  
  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
  71.  
  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
  76.  
  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
  82.  
  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
  88.  
  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
  96.  
  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)
  101.  
  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
  108.  
  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)
  113.  
  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)
  118.  
  119.     ' Parent Window Handle
  120.     WinParent = getparent(WinOver)
  121.  
  122.     If WinParent <> 0 Then
  123.         ' Parent window handle
  124.         Label10.Caption = WinParent
  125.  
  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)
  130.  
  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 1861

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

Similar topics

7
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...
1
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;...
2
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...
3
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------------------------------------...
3
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
8
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...
1
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...
7
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;"...
92
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"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.