C # getwindowthreadprocessid usage

Source: Internet
Author: User

Function: This function returns the ID of the process that creates the specified window thread and the process that creates the window. The last one is optional.

Function prototype; DWORD getwindowthreadprocessld (hwnd, lpdword lpdwprocessld );

Parameters:

Hwnd: Window handle.

Lpdwprocessld: the address that receives the 32-bit value of the Process Identity. If this parameter is not null, getwindwthreadprocessld copies the process identifier to the 32-bit value. Otherwise, the process identifier is not copied.

Return Value: the return value is the thread ID of the window to be created.


Use this function in C # To first import the namespace:

Using system. runtime. interopservices;

Then write the code of the API reference and put it into the class.
[Dllimport ("user32.dll", charset = charset. Auto)]
Public static extern int getwindowthreadprocessid (intptr hwnd, out int ID );


This function has two parameters. The first parameter is the window handle obtained by findwindow, and the second parameter is the variable that stores the process ID. For example:

// Obtain the calculator window handle
Intptr hwnd = findwindow (null, "Calculator ");
If (hwnd! = Intptr. Zero)
{
Int calcid;
// Obtain the process ID
Getwindowthreadprocessid (hwnd, out calcid );
MessageBox. Show (calcid. tostring ());
}
Else
{
MessageBox. Show ("No calculator window found ");
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.