Results 1 to 3 of 3

Thread: How can I use the Windows API to get the threadID for a foreign app

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Location
    Glendale, Ca USA
    Posts
    2

    Post

    Can anyone tell me how to obtain the threadID for the main window of a foreign application? I need to disable keyboard input temporarily so that the user doesn't interfere with an automated process. I've done this in the past for the current application, but now one of our projects has the requirement that I replace a portion of a data entry application's user interface with a customized form and I need to disallow user keyboard input to the data entry application while still allowing mouse input to it during a period when I'm directing keyboard input to my custom form.


    I'm working in VB and know how to lock and unlock kybd input for a particular thread using WinAPI calls as follows:

    Dim hHook As Long

    'disable keyboard input
    hHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardProc, 0&, ThreadID)

    'Do something while keyboard is disabled

    'enable keyboard input
    Call UnhookWindowsHookEx(hHook)

    where KeyboardProc is a callback routine that I've coded to throw out the keyboard input.

    The problem is with ThreadID. I can get this to work for an app which I've written (in VB I can use App.ThreadID), but I can't figure out how to get the threadID for a foreign application's main window. I've spent hours querying the Win32 SDK references and MSDN trying to find a way to get a threadID. All I can find are variations of FindWindow (which returns a window handle, not the threadID) along with various methods of obtaining threadIDs for the application one is coding.

    Any ideas would be greatly appreciated, thanks!



    ------------------
    Tom R. Valdez
    Senior Analyst
    General Networks Corp.
    [email protected]
    818-249-1962 Ext. 743

  2. #2
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263

    Post

    I think this is what you're looking for chief, assuming you can get the handle:

    Code:
    Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
    
    Dim GetProcId As Long
    Dim WindowThreadID As Long
    
    WindowThreadID = GetWindowThreadProcessId(hwnd, GetProcId)

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Location
    Glendale, Ca USA
    Posts
    2

    Post

    Thanks alot. I should be able to get the handle via the FindWindow() call...

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