Close some other Application without directly interacting with it in C#.net 2.0.
Author: DevAsp Team
Download Source Code : 688_CloseotherWindow.zip
: In this simple article you will learn how you can close some other Application without directly interacting with it.
Simply just create New Project of C#.
Firstly Add Reference of System.Runtime.InteropServices.
Now drag one Button, two TextBox and two Labels on the form
First there is concept to interact with any application directly, if we have Handle of any window we can do any thing with that window. Windows (Operating System) do all working through Messages. So in this article we use same technique to interact with other window.
We get handle of any window by giving it Class Name and its Text, we take here example of Notepad. Class name of Notepad is Notepad and you can see its text on top of window.
Firstly import these DLLs
FindWindow(… method return you handle of the window………
SendMessage(… is use to send message to Specific window……
Define some global Variables these are Predefined Message of Windows (OS)
Now just write code on Form Load Event
Now write this very simple code on Button Click Event
When you run application before click on this button first run a new instance of Notepad this application will close that window.