Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get window handle from window class name

I'm trying to get a window handle on a child window in my process and the only information I have is the window class name. Are there any win32 functions I can use for that? I'm doing this from C#.

A bit more detail: This is a Visual Studio plugin, written in C#. So my process is visual studio, which has lots of windows. One of them has a window class "VsTipWindow". I don't know the immediate parent window of that window, all I have is the class name. Is there any way for me to get the window handle from just that?

like image 374
Einar Egilsson Avatar asked May 31 '10 13:05

Einar Egilsson


People also ask

How do I find my windows handle?

The Win32 API provides no direct method for obtaining the window handle associated with a console application. 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.

How do you get a handle of window on MFC?

Either you want to take handle of your Own Application or some third party application if it is third party application then you can use FindWindow() function with window class name or by Window Name .

What is window handle in C++?

A Windows window is identified by a "window handle" ( HWND ) and is created after the CWnd object is created by a call to the Create member function of class CWnd . The window may be destroyed either by a program call or by a user's action. The window handle is stored in the window object's m_hWnd member variable.


2 Answers

FindWindow is the Win32 call you want for this (or FindWindowEx if there's more than one window with that particular class name, and FindWindow isn't returning the one you're looking for).

like image 87
MusiGenesis Avatar answered Sep 23 '22 11:09

MusiGenesis


just additional information..
maybe it's useful to know that you can get the handle of a window from a point
WindowFromPoint
http://msdn.microsoft.com/en-us/library/ms633558(VS.85).aspx

like image 20
OlimilOops Avatar answered Sep 23 '22 11:09

OlimilOops