How do i get the threadid of a window.
I know it explains a bit "(HANDLE Thread)" but still how?

Regards,
Prosammer

Do you mean thread ID or window id? All the windows in the same thread of the same thread ID, but each one has its own Window ID (or HWND handle).

Do you mean thread ID or window id? All the windows in the same thread of the same thread ID, but each one has its own Window ID (or HWND handle).

ThreadID sir.
i know each windows has hes own window id where you can get that with GetWindowsThreadID

but what i'm looking for is how to get the ThreadID (GetThreadId) "of" the window.
Most of the time i get them by using Spy++. but i also wanted to learn how i can get it trough Visual Studio.

Edited 5 Years Ago by Prosammer: n/a

GetCurrentThread( ) will return the HANDLE of the current thread, which you can pass to GetThreadId ().

Look for example MSN:
Caption: L"Windows Live Messenger"
Class: L"MSBLWindowClass"

part of Getting HANDLE and Process ID

// example
	hW = FindWindow(L"MSBLWindowClass",L"Windows Live Messenger");
	GetWindowThreadProcessId(hW,&pID); // get the things...
	

	int (__cdecl *pHandle)(DWORD) = (int(__cdecl*)(DWORD))hW;
	int (__cdecl *pRocess)(DWORD) = (int(__cdecl*)(DWORD))pID;

	// p_s is my printout function..
	p_s("Handle: %p (0x%X)",pHandle,pHandle);
	p_s("Process: %p (0x%X)",pRocess,pRocess);

(when you debug you'll get the results..)


Now looking with Spy++
Handle of the window: (000)10372
Process ID of the window: (thats not changing when it's active unless you restart the pgoram): (00000)E68
Thread ID of the window (what im currently looking to get (samething above 'restart cetera..')): (00000)E6C

P.S The GetCurrentThread combination of passing it to GetThreadId didn't work out

HANDLE _eng; // global
	_eng = GetCurrentThread();
	p_s("%p",GetThreadId(_eng));

Hmmm?

Edited 5 Years Ago by Prosammer: n/a

>> Thread ID of the window (what im currently looking to get

So, if you want to know the window's thread identifier then you could give this a try

#include <windows.h>
#include <tchar.h>

int main()
{
  HWND hW = FindWindow(_T("MSBLWindowClass"), _T("Windows Live Messenger"));

  if(hW != NULL)
  {
    // Process identifier.
    DWORD PID;
    // Thread identifier.
    DWORD TID = GetWindowThreadProcessId(hW, &PID);

    // ... use PID/TID here ... 

  }
}

>> Thread ID of the window (what im currently looking to get

So, if you want to know the window's thread identifier then you could give this a try

#include <windows.h>
#include <tchar.h>

int main()
{
  HWND hW = FindWindow(_T("MSBLWindowClass"), _T("Windows Live Messenger"));

  if(hW != NULL)
  {
    // Process identifier.
    DWORD PID;
    // Thread identifier.
    DWORD TID = GetWindowThreadProcessId(hW, &PID);

    // ... use PID/TID here ... 

  }
}

Works.

Thank you *all you guys*
(I guess i'm on the right spot to be posting and helping people out on this community)

Edited 5 Years Ago by Prosammer: n/a

This question has already been answered. Start a new discussion instead.