CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2007
    Posts
    68

    Question Getting thread id of a process

    I have created a process using ShellExecute and i have the process handle.
    I need to get the PROCESS_INFORMATION of that process.

    Some body please help me
    Last edited by zuhrs; December 4th, 2008 at 04:35 AM.

  2. #2
    Join Date
    May 2006
    Location
    Norway
    Posts
    1,709

  3. #3
    Join Date
    Apr 2007
    Posts
    68

    Re: Getting thread id of a process

    If i use CreateProcess API I can get PROCESS_INFORMATION structure, but my question is
    is there any way so that i get the PROCESS_INFORMATION from the process handle or process id

    we can get process ID if we have process handle as
    processID = GetProcessId(processhandle);

    I need to get the thread ID

  4. #4
    Join Date
    May 2006
    Location
    Norway
    Posts
    1,709

  5. #5
    Join Date
    Apr 2007
    Posts
    68

    Re: Getting thread id of a process

    I have created a process using ShellExecuteEx and to get the handle of the window I have created , ihave done the following code
    SHELLEXECUTEINFO ExecuteInfo = {0};
    memset(&ExecuteInfo, 0, sizeof(ExecuteInfo));

    ExecuteInfo.cbSize = sizeof(ExecuteInfo);
    ExecuteInfo.fMask = SEE_MASK_DOENVSUBST | SEE_MASK_NOCLOSEPROCESS ;
    ExecuteInfo.hwnd = 0;
    ExecuteInfo.lpVerb = L"open";
    ExecuteInfo.nShow = SW_SHOW;
    ExecuteInfo.lpFile = szExe.GetString();
    ExecuteInfo.lpParameters = szPath.GetString();
    ExecuteInfo.lpDirectory = 0;
    ExecuteInfo.hInstApp = AfxGetInstanceHandle();

    if (::ShellExecuteEx(&ExecuteInfo))
    {
    if( ExecuteInfo.hProcess != NULL )
    {
    WaitForInputIdle(ExecuteInfo.hProcess, WAIT_FOR_INPUT_TIMEOUT);
    }

    DWORD processID = GetProcessId(ExecuteInfo.hProcess);

    int count = 0;
    HWND hwnd = ::GetTopWindow(0 );
    while ( hwnd )
    {
    DWORD pid;
    DWORD dwTheardId = ::GetWindowThreadProcessId( hwnd,&pid);
    if (processID == pid)
    {
    count++;
    MessageBox("window title");
    }
    hwnd = ::GetNextWindow( hwnd , GW_HWNDNEXT);
    }
    }

    After this execution, count is 3. There are three handles.
    Actually i am opening another application using the create process.
    When i open the mspaint, i get three conditions meeting the above handles
    How can i ensure which is the main handle of the created application . eg : mspaint
    Initially it is giving GDI as handle and then it gives the oroginal handle of the mspaint

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Getting thread id of a process

    Use Spy++ to know what threads/windows (and how many) are created when you start MsPaint.
    Victor Nijegorodov

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

Featured