Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy

Search Results for "FindWindow" in [All]

user32

.

    static extern System.IntPtr FindWindow(string lpClassName, string lpWindowName);

.

    static extern System.IntPtr FindWindowEx(System.IntPtr hwndParent, System.IntPtr hwndChildAfter,

.

        FindWindowEx(FindWindow("Shell_TrayWnd", null), System.IntPtr.Zero, "TrayNotifyWnd", null);

.

    int FindWindow(String^ lpClassName, String^ lpWindowName);

.

    int FindWindowEx(int hwndParent, int hwndChildAfter,

.

    int hWnd=FindWindowEx(FindWindow("Shell_TrayWnd", nullptr), 0, "TrayNotifyWnd", nullptr);

.

IntPtr hwnd = FindWindowByCaption((IntPtr)null, "Untitled - Notepad");

.

        // This is different from FindWindow() in that the code below allows partial matches

.
Summary
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.
.

///     <see cref="!:https://msdn.microsoft.com/en-us/library/windows/desktop/ms633500%28v=vs.85%29.aspx">FindWindowEx</see>

.

///     Go to https://msdn.microsoft.com/en-us/library/windows/desktop/ms633499%28v=vs.85%29.aspx for FindWindow

.

///     FindWindowEx

.

///     If the lpWindowName parameter is not NULL, FindWindow calls the <see cref="M:GetWindowText" /> function to

.

static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

.

[DllImport("user32.dll", EntryPoint="FindWindow", SetLastError = true)]

.

static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);

.

// You can also call FindWindow(default(string), lpWindowName) or FindWindow((string)null, lpWindowName)

.

Private Shared Function FindWindow( _

.

<DllImport("user32.dll", EntryPoint:="FindWindow", SetLastError:=True, CharSet:=CharSet.Auto)> _

.

Private Shared Function FindWindowByClass( _

.

<DllImport("user32.dll", EntryPoint:="FindWindow", SetLastError:=True, CharSet:=CharSet.Auto)> _

.

Private Shared Function FindWindowByCaption( _

.

class method FindWindow(lpClassName, lpWindowName: String): IntPtr; external;

.

VB Signature (use "FindWindowA" for ANSI return value or "FindWindowW" for Unicode return value) :

.

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (

.

Private Declare Function FindWindow Lib "user32" Alias "FindWindowW" (

.

static def FindWindow(lpClassName as string, lpWindowName as string) as IntPtr:

.

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

.

Works hand-in-hand with FindWindowEx

.

*If lpClassName is NULL FindWindow will search for the window by the lpWindowName (window's title) only. This is useful if the class of a particular window is variable.

.

Sometimes stored as FindWindowA in DLL

.

        public static int FindWindow(string windowName, bool wait)

.

            int hWnd = FindWindow(null, windowName);

.

                hWnd = FindWindow(null, windowName);

.

            int hWnd = FindWindow(windowName, wait);

.

ParenthWnd = FindWindow(lpszParentClass,lpszParentWindow);

.

     hWnd = FindWindowEx(ParenthWnd,hWnd,lpszClass,"");

.

ParenthWnd = FindWindow(lpszParentClass, lpszParentWindow)

.

    hWnd = FindWindowEx(ParenthWnd, hWnd, lpszClass, "")

.

C# Managed Code Alternative to avoid Native calls to FindWindow:

.

You can avoid using FindWindow which is a native code by calling a combination of Process.GetProcessesByName and Process.MainWindowHandle. This article describes how to do that:

.

    nWnd = FindWindow(Nothing, Wnd_name)

.

    Public Class FindWindowHandle

.

    Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As Integer

.

    Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, ByVal childAfter As IntPtr, _

.

        Return FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Progman", vbNullString)

.

        Return FindWindow("Shell_traywnd", vbNullString)

.

        Return FindWindow("Button", vbNullString)

.

            Return FindWindow(ClassName, vbNull)

.

            Return FindWindow(vbNull, WindowName)

.

            Return FindWindow(ClassName, WindowName)

.

            Return FindWindowEx(IntPtr.Zero, ChildHandle, vbNullString, vbNullString)

.

            Return FindWindowEx(ParentHandle, IntPtr.Zero, vbNullString, vbNullString)

.

            Return FindWindowEx(IntPtr.Zero, ChildHandle, ClassName, vbNullString)

.

            Return FindWindowEx(IntPtr.Zero, ChildHandle, vbNullString, WindowName)

.

            Return FindWindowEx(IntPtr.Zero, ChildHandle, ClassName, WindowName)

.

            Return FindWindowEx(ParentHandle, IntPtr.Zero, ClassName, vbNullString)

.

            Return FindWindowEx(ParentHandle, IntPtr.Zero, vbNullString, WindowName)

.

            Return FindWindowEx(ParentHandle, IntPtr.Zero, ClassName, WindowName)

.

            Return FindWindowEx(IntPtr.Zero, IntPtr.Zero, ClassName, vbNullString)

.

            Return FindWindowEx(IntPtr.Zero, IntPtr.Zero, vbNullString, WindowName)

.

            Return FindWindowEx(IntPtr.Zero, IntPtr.Zero, ClassName, WindowName)

.

            Return FindWindowEx(HWND_MESSAGE, IntPtr.Zero, ClassName, vbNullString)

.

            Return FindWindowEx(HWND_MESSAGE, ChildHandle, ClassName, vbNullString)

.

            Return FindWindowEx(HWND_MESSAGE, IntPtr.Zero, vbNullString, WindowName)

.

            Return FindWindowEx(HWND_MESSAGE, ChildHandle, vbNullString, WindowName)

.

            Return FindWindowEx(HWND_MESSAGE, IntPtr.Zero, ClassName, WindowName)

.

            Return FindWindowEx(HWND_MESSAGE, ChildHandle, ClassName, WindowName)

.

static extern TODO FindWindowA(TODO);

.

Declare Function FindWindowA Lib "user32.dll" (TODO) As TODO

.
Documentation
[FindWindowA] on MSDN
.
Summary
.

static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

.

public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className,  string windowTitle);

.

Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, _

.

    childHandle = FindWindowEx(

.

    childHandle = FindWindowEx(windowHandle,IntPtr.Zero,"WorkerW",IntPtr.Zero);

.

        childHandle = FindWindowEx(childHandle,IntPtr.Zero,"ReBarWindow32",IntPtr.Zero);

.

            childHandle = FindWindowEx(childHandle, IntPtr.Zero, "ComboBoxEx32", IntPtr.Zero);

.

                childHandle = FindWindowEx(childHandle, IntPtr.Zero, "ComboBox", IntPtr.Zero);

.

                    childHandle = FindWindowEx(childHandle, IntPtr.Zero, "Edit", IntPtr.Zero);

.

Referrel URL : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/findwindowex.asp

.
Documentation
[FindWindowEx] on MSDN
.

Dim hwndMain as IntPtr = FindWindowEx(intptr.Zero,intptr.Zero,vbNullString,"My Window Title") 'Get the Window Handle

.

Dim hwndMain as IntPtr = FindWindowEx(intptr.Zero,intptr.Zero,vbNullString,"My Window Title") 'Get the Window Handle

.

IntPtr hWnd = FindWindow("WindowClass", "WindowName");

.

Dim hwndMain as IntPtr = FindWindowEx(intptr.Zero,intptr.Zero,vbNullString,"My Window Title") 'Get the Window Handle

.

        public static extern IntPtr FindWindow( string sClsName , string sWndName );

.

            IntPtr Hwnd = FindWindow( null , "Form1" );

.

Use FindWindow and SetForegroundWindow to direct input to the desired window.

.

  SetForegroundWindow (FindWindow('Untitled - Notepad'))

.

    'Note: this example also uses API calls to FindWindow, GetDlgItemText, and SetActiveWindow.

.

    theDialogBoxHandle = FindWindow(theDialogBoxClassName, theDialogBoxTitle)

.

   var hWindow = Api.user32.FindWindow("notepad", null);

.

            int hWnd = FindWindow(windowName, wait);

.

        // THE FOLLOWING METHOD REFERENCES THE FindWindowAPI

.

        public static int FindWindow(string windowName, bool wait)

.

            int hWnd = FindWindow(null, windowName);

.

                hWnd = FindWindow(null, windowName);

.

Here is an alternative Managed API to FindWindow, The article also describes a way to CloseWindow of another process like notepad, not sure if there is such thing in Win32 API, but at least you can do it in .NET! Here is the article:

.

    /*SetParent(FindWindow(vbnullstring,"notepad.exe"),me.handle)

.

    static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

.

    ParentHWnd = FindWindow(lpszClass, lpszWindow);

kernel32

coredll

.

[DllImport("coredll.dll", EntryPoint="FindWindowW", SetLastError=true)]

.

private static extern IntPtr FindWindowCE(string lpClassName, string lpWindowName);

.

Public Declare Function FindWindow Lib "Coredll" Alias "FindWindowW" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr

.

        handle = FindWindowCE("HHTaskBar", null);

.

        handle = FindWindowCE("HHTaskBar", null);

.
Documentation
[FindWindowW] on MSDN
.

        handle = FindWindowW("HHTaskBar", null);

.

        handle = FindWindowW("HHTaskBar", null);

shell32

.

    Private Declare Auto Function FindWindow Lib "user32" ( ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr

.

    'abd.hWnd = FindWindow("Shell_TrayWnd", "") 'Tasbar Handle

.

        ABD.hWnd = FindWindow("Shell_TrayWnd", "")


 
Access PInvoke.net directly from VS: