Usage of findwindow in C #

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.