Usage of findwindow () function. To use this API in C #, write the findwindow () function declaration:
[Dllimport ("coredll. dll", entrypoint = "findwindow")]
Private extern static intptr findwindow (string lpclassname, string lpwindowname );
This function has two parameters: the first is the class of the window to be searched, and the second is the title of the window to be searched. You may not know either of them when searching, but at least you must know one of them. Some window titles are relatively easy to get, such as "Calculator", so you should use titles to search. However, some software titles are not fixed, such as "Notepad". If the opened files are different and the window titles are different, it is easier to use window-Class search. If a window that meets the conditions is found, this function returns the handle of the window; otherwise, 0 is returned.
Look at the example
Intptr parenthwnd = New Intptr ( 0 ); Parenthwnd = Findwindow ( Null , " Word mobile " ); // Determine whether the form is valid If (Parenthwnd! = Intptr. Zero) {MessageBox. Show ( " Find window " );} Else {MessageBox. Show ( " No window found " );}
From the above discussion, we can see that if you want to search for externalProgramThe window title is relatively easy to obtain, and the problem is relatively simple. But if the title of the window is not fixed or there is no title at all, how can we get the class of the window? If you have installed visual c ++, you can use the spy in it. In spy ++, there is a findwindow tool that allows you to select a window with the mouse, then spy ++ will display the class of this window.
There is also a find‑wex In the Win32 API, which is very suitable for finding subwindows.
Address: http://blog.csdn.net/enginetanmary/article/details/1572319