Results 1 to 15 of 15

Thread: Spy

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2009
    Posts
    489

    Spy

    this is a utilty i started to wrote to some application with many floating windows, (the app didn't gave much ability to handle them).

    then it become a general purpose utilty, it can work with any running application.
    I always try to use only API, because i always have "convert basic to other language" in mind, so there are many APIs here.

    please fill free to post any comment you like.
    Attached Files Attached Files
    Last edited by whatsup; May 2nd, 2010 at 02:42 AM. Reason: Removed Compiled EXE from attachment

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Spy

    In accordance with this CodeBank policy regarding attachments, I have edited yours and removed all compiled files.

    Please post only source code in any CodeBank attachment.

    Thank you.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2009
    Posts
    489

    Re: Spy

    I'm sorry,
    i did it in the first time i tried to post (on my computer), but then i changed something, and forgot that.

  4. #4
    New Member
    Join Date
    Feb 2010
    Posts
    1

    Re: Spy

    Quote Originally Posted by whatsup View Post
    this is a utilty i started to wrote to some application with many floating windows, (the app didn't gave much ability to handle them).

    then it become a general purpose utilty, it can work with any running application.
    I always try to use only API, because i always have "convert basic to other language" in mind, so there are many APIs here.

    please fill free to post any comment you like.
    Good one Spy, have been trying this line of coding for sometime now (when ever I get it).
    I am new here, I hope that I am allowed to modify the code to my liking.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2009
    Posts
    489

    Re: Spy

    I hope that I am allowed to modify the code to my liking
    yes, you are.
    you can also post any questions you like.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2009
    Posts
    489

    Re: Spy

    update
    now it can determine not just parent,
    but parent process as well.

  7. #7
    Junior Member
    Join Date
    Apr 2010
    Location
    CT
    Posts
    16

    Re: Spy

    WhatsUp, works great but it would be nice to have the information in other places. Do you want me to update program or do you may feel free to add the following. I have only done the basics right now?

    To get information for window displays from handles (ALL Window and Application Windows TAB)
    vb Code:
    1. 'Use the following for main window
    2.     lngThreadId = GetWindowThreadProcessId(hwnd, lngProcessId)
    3. ' then call function lngParnetPID = MyGetParentPID(lngProcessId)
    4.  
    5. 'Add the following to Sub HoverIt1()
    6.     lngThreadID = GetWindowThreadProcessId(HwndOver, lngProcessID)
    7.     .lblHover1 = .lblHover1 & "Window Process ID: " & CStr(lngProcessID) & vbCrLf ' Display window process ID
    8.     .lblHover1 = .lblHover1 & "Window Thread ID: " & CStr(lngThreadID) & vbCrLf ' Display window thread ID
    9.  
    10.     lngParentProcID = MyGetParentPID(lngProcessID)
    11.     .lblHover1 = .lblHover1 & "Parent Process ID:" & lngParentProcID & vbCrLf
    12.  
    13. 'Create a new function (beware I have not removed unused variables yet)
    14.  
    15. Public Function MyGetParentPID(lpID As Long) As Long
    16.     Dim lSnapShotP As Long
    17.     Dim hProcess As Long
    18.     Dim lNextProcess As Long
    19.     Dim tPE As PROCESSENTRY32
    20.     Dim tME As MODULEENTRY32
    21.     Dim lvwListItem As ListItem
    22.     Dim ModuleName As String * MAX_PATH
    23.     Dim sModName As String
    24.     Dim sExe As String
    25.     Dim lRet As Long
    26.  
    27.     MyGetParentPID = 9999
    28.    
    29.     ' Create snapshot
    30.     lSnapShotP = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
    31.     If lSnapShotP <> INVALID_HANDLE_VALUE Then
    32.         ' Length of the structure
    33.         tPE.dwSize = Len(tPE)
    34.  
    35.         ' Find first process
    36.         lNextProcess = Process32First(lSnapShotP, tPE)
    37.         Do While lNextProcess
    38.             ' must reset every cycle
    39.             sModName = ""
    40.             hProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, 0, tPE.th32ProcessID)
    41.  
    42.             'Get the module file name
    43.             lRet = GetModuleFileNameExA(hProcess, 0, ModuleName, MAX_PATH)
    44.  
    45.             'Get the module file name out of the buffer, lRet is how
    46.             'many characters the string is, the rest of the buffer is spaces
    47.             sModName = RTrimNull$(ModuleName)
    48.             sExe = RTrimNull$(tPE.szExeFile)
    49.  
    50.             sModName = ReplacePathSystem(sModName, sExe)
    51.  
    52.             Call CloseHandle(hProcess)
    53.  
    54.             ' Found specified process
    55.             If lpID = tPE.th32ProcessID Then
    56.                 MyGetParentPID = tPE.th32ParentProcessID
    57.                 Exit Do
    58.             End If
    59.  
    60.             ' Get next process
    61.             lNextProcess = Process32Next(lSnapShotP, tPE)
    62.         Loop
    63.         Call CloseHandle(lSnapShotP)
    64.     End If
    65. End Function
    Last edited by Hack; Apr 30th, 2010 at 10:53 AM. Reason: Added Highlight Tags

  8. #8
    Junior Member
    Join Date
    Apr 2010
    Location
    CT
    Posts
    16

    Re: Spy

    Since there might be multiple windows associated with a single process ID, we will need to deteremine the owner of the process ID. Then we will be able to determine the unique parent process. I have just started to look into this but someone else out there might have already determined how to perform this function.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2009
    Posts
    489

    Re: Spy

    do you mean if a window has childs , each child has the same process ID ?
    if so, this is already handled.

    if you mean that different apps can have the same processID
    i don't think it's true.

  10. #10
    Junior Member
    Join Date
    Apr 2010
    Location
    CT
    Posts
    16

    Re: Spy

    Quote Originally Posted by whatsup View Post
    do you mean if a window has childs , each child has the same process ID ?
    if so, this is already handled.
    Yes this is what I mean but you can see in SPY++ that only one of the processes is the owner and all the other process which shares the same process ID all point to the common owner.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2009
    Posts
    489

    Re: Spy

    you can see which is child window
    you even has a special tab(the second), that only one app and all its childs are displayed.

    EDIT: maybe i add a process column to the windows list, not a problem.
    Last edited by whatsup; Apr 30th, 2010 at 10:48 AM.

  12. #12
    Junior Member
    Join Date
    Apr 2010
    Location
    CT
    Posts
    16

    Re: Spy

    I missed that. It looks like the last entry in the "Application Window" is the owner of the process ID. Is this correct?

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2009
    Posts
    489

    Re: Spy

    no, you can see which is child, on the child coloumn
    there can be two or more none-childs in one app
    and all these windows are with the same Process ID

    i'll check if i can give more details about what is the main window.

  14. #14
    Junior Member
    Join Date
    Apr 2010
    Location
    CT
    Posts
    16

    Re: Spy

    Found what I was looking for GETWINDOW(hWnd,GW_OWNER) where GW_OWNER=4. This function will return the owner of each handle. Since you could have every process without a parent indicator you can use this to determine the main window in the group. Sometime it may be invisible in the listing. Hopefully this is the last key I needed, all I need to do now is create an algorthm which puts all the information together and presents it back to the user in a simple form.

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2009
    Posts
    489

    Re: Spy

    this will give you only the immediate owner, not the top most window of the app.
    PSpy has a function to get the top most window, and in app mode, it shows the title of that top most
    in the header.

    i updated now with:
    the handle number of the topmost window is display along with the title
    in the process tab:
    parent name column, so you can see the parent name of each process along with its ID number

    the last updates before these were:
    in the windows tab:
    process column
    kill process tree

    i think you can find every thing you need in the code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width