Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the handle of window in C#

Tags:

c#

winforms

I'm trying to do some P/Invoke stuff and need the handle of the current window.

I found Getting the handle of window in C#

But it appears that only works in WPF. Is there a winForms equivalent?

like image 314
Joel Barsotti Avatar asked Sep 10 '09 00:09

Joel Barsotti


People also ask

How do I find my window handles?

However, you can obtain the window handle by calling FindWindow() . This function retrieves a window handle based on a class name or window name. Call GetConsoleTitle() to determine the current console title. Then supply the current console title to FindWindow() .

How do I get the handle of window in CPP?

The proper way, in my humble opinion, is handle=FindWindowW(NULL, L"Calculator"); (using UNICODE) or handle=FindWindowA(NULL, "Calculator");(using ANSI). Even better, use instead FindWindow macro to avoid know what character set is used in the project, so make your code "agnostic" to character set.

What is a handle to a window?

A window handle is a short length of material that attaches to a window in order to aid rotation of the hinge and therefore opening and closing of the window.

What is window handle C#?

Once the Selenium WebDriver instance is instantiated, a unique alphanumeric id is assigned to the window. This is called window handle and is used to identify browser windows. Since the id is unique, it is used by the Selenium WebDriver to switch between different windows (or tabs).


1 Answers

Control.Handle

An IntPtr that contains the window handle (HWND) of the control.

like image 77
dtb Avatar answered Oct 06 '22 15:10

dtb