系统提供方法
FindWindow
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.
该函数是返回类名和窗口名都符合传入参数的窗体句柄。当然这个函数也不区分大小写。当然你如果想从指定的子窗体查找窗体那么你可以使用另外的函数FindWindowEX函数。
HWND FindWindow( LPCTSTR lpClassName, // class name 类名 LPCTSTR lpWindowName // window name 窗体名字 );Parameters
lpClassName 这个参数是调用 RegisterClass或RegisterClassEx函数创建的时指定的类名字,已给。
- [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.
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.If lpClassName is 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.
这个参数指定要搜索窗体的名字。
以上两个参数都是以空为结束。
Return Values
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