How do I shut a program automatically?

Deepak

B3D Yoddha
Veteran
I am using WinxP.

Like I have scheduled my PC to switch OFF automatically at a particular time (using scheduler in control panel), can I make a program like F@H to switch itself OFF automatically at a fixed time daily??? Is there a tool or something...I am sure there must be....

NEED HELP.

Thanks.
 
If you know the class name and window name for an app then you can get its handle, when you have it's handle then you can send it a message.


You can use Microsoft Spy, which is one of the tools installed with Visual Studio to get the class name and window name.


Code would look something like this.
Code:
#include <windows.h>

int _tmain(int argc, _TCHAR* argv[])
{
	_TCHAR* classname;
	_TCHAR* windowname;
	HWND hWnd=NULL; 
	LRESULT	lRes;

	
	
	if(argc<3)
	{
		printf("Classname and WindowTitle Required\n");
	}
	classname=argv[1];
	windowname=argv[2];
	hWnd=FindWindow(classname,windowname); 
	if(hWnd)
	{
		lRes=SendMessage(hWnd,WM_CLOSE,0,0); 
		// Check for failure here.
	}
	else
	{
		// Window not found, best not to do anything.
	}
	
	return 0;
}

Their is almost certainly a more elegant solution, but I don't know what it is, and my Windows API knowledge is minimal at best.
You may need to mess around with what message you send, and the parent window to send to might be a bit tricky to find.


CC
 
Not really, their are only two function calls.
The first gets a handle to a window with the title and classname (not a C++ classname, but an identifier that windows uses) that you specify on the command line.
The second uses that handle to send the WM_CLOSE message to that window.

You can find out more about what they do on the msdn website (don't have to be an msdn subscriber)
http://msdn.microsoft.com/library/d...indowreference/windowfunctions/findwindow.asp

[edit] Instead of SendMessage use PostMessage [/edit]

CC
 
Back
Top