How to get process id and thread id from a Window Handle in .NET CF?

By 42Gears Team
using System.Runtime.InteropServices;
GetWindowThreadProcessId
[DllImport("coredll.dll")] private static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
Description:
  • hWnd is the window handle
  • lpdwProcessId stores the process identifier after the method returns
  • return value of the function is the id of the thread that created the window
Calling GetWindowThreadProcessId via P/Invoke: // Set the hWnd value below with window handle of your interest IntPtr hWnd = this.Handle; uint processid = 0; uint threadid = GetWindowThreadProcessId((IntPtr)hWnd, out processid);

“Written with expertise and passion to help you understand the topic better.”

4
42Gears Team – Content Author
Published on: May 10, 2010

Subscribe to our newsletter

Stay updated with the latest news, articles, and resources on enterprise mobility.

Weekly articles
Actionable insights delivered once a week. No noise.
No spam
Your privacy matters. Unsubscribe anytime.