Click to Rate and Give Feedback
MSDN
MSDN Library
User Interface
Windowing
Windows
Windows Reference
Functions
 FindWindow Function
FindWindow Function

The FindWindow function retrieves a handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows. This function does not perform a case-sensitive search.

To search child windows, beginning with a specified child window, use the FindWindowEx function.

Syntax

HWND FindWindow(      
    LPCTSTR lpClassName,     LPCTSTR lpWindowName );

Parameters

lpClassName
[in] Pointer to a null-terminated string that specifies the class name or a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the low-order word of lpClassName; the high-order word must be zero.

If lpClassName points to a string, it specifies the window class name. The class name can be any name registered with RegisterClass or RegisterClassEx, or any of the predefined control-class names.

If lpClassName is NULL, it finds any window whose title matches the lpWindowName parameter.

lpWindowName
[in] Pointer to a null-terminated string that specifies the window name (the window's title). If this parameter is NULL, all window names match.

Return Value

If the function succeeds, the return value is a handle to the window that has the specified class name and window name.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Remarks

If the lpWindowName parameter is not NULL, FindWindow calls the GetWindowText function to retrieve the window name for comparison. For a description of a potential problem that can arise, see the Remarks for GetWindowText.

To check if the Microsoft IntelliType version 1.x software is running, call FindWindow as follows:

FindWindow("MSITPro::EventQueue",NULL);   

To check if the IntelliType version 2.0 software is running, call FindWindow as follows:

FindWindow("Type32_Main_Window", NULL);   

If the IntelliType software is running, it sends WM_APPCOMMAND messages to the application. Otherwise the application must install a hook to receive WM_APPCOMMAND messages.

Microsoft Windows 95 or later: FindWindowW is supported by the Microsoft Layer for Unicode (MSLU). To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.

Example

For an example, see Retrieving the Number of Mouse Wheel Scroll Lines.

Function Information

Minimum DLL Versionuser32.dll
HeaderDeclared in Winuser.h, include Windows.h
Import libraryUser32.lib
Minimum operating systems Windows 95, Windows NT 3.1
UnicodeImplemented as ANSI and Unicode versions.

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
vb.net syntax      Đonny ... dmex   |   Edit   |   Show History
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Public Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function
Flag as ContentBug
C# syntax      dmex   |   Edit   |   Show History
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
Tags What's this?: c# (x) syntax (x) Add a tag
Flag as ContentBug
error C2664: 'FindWindowW' : cannot convert parameter 1 from 'const char [19]' to 'LPCWSTR'      Mahdi Golestaneh   |   Edit   |   Show History

1>c:\documents and settings\m\my documents\visual studio 2008\projects\0\0\0.cpp(11) : error C2664: 'FindWindowW' : cannot convert parameter 1 from 'const char [19]' to 'LPCWSTR'
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker