Thursday, July 15, 2010

Select Window With FindWindow()

With .Net you can select a specific running process by the functions System.Diagnostics.Process.GetProcessesByName() and System.Diagnostics.Process.GetProcessesById(). You then get an instance of the class Process containig it. This variable then can be manipulated, for example you can termine it or read-out its ID.
Unfortunately these functions do not always suffice.
A process can have multiple windows, as for example a C# application can have many forms. If we want to select a specific window and not just the whole process, we have to use the WinAPI.
This library provides the function FindWindow().
The function expects 2 strings as parameter: The first is called className and specifies the class name of the process / window. The second parameter, windowText, describes the title of the window. If none is given, all windows are selected.
An example will follow in the next post, where this function is used to hide the taskbar.
With System.Diagnostics.Process.GetProcessesByName() this cannot be achieved, since the taskbar is contained in the process "explorer.exe". But with the right parameters in FindWindow(), it can be found and separated.

No comments:

Post a Comment