Hwnd =: findwindow (null, _ T ("msdn library Visual Studio 6.0"); // note: this is the title Text of the window.
If (null! = Hwnd ){
: Sendmessage (hwnd, wm_close, 0, 0 );
}
// ANOTHER METHOD
DWORD id_num;
Hwnd =: findwindow (null, _ T ("msdn library Visual Studio 6.0 "));
Getwindowthreadprocessid (hwnd, & id_num); // Note: The second parameter is the process ID, and the return value is the thread ID.
Handle Hd = OpenProcess (process_all_access, false, id_num );
Terminateprocess (HD, 0 );
If the window text changes, you can use the first parameter of findwindow: The Class Name of the application.
You can use the spy ++ software provided by VC to obtain the classname.
From the Start Menu-> Ms 6.0 tools-> spy ++, find out the program you want to close, such as spy ++. Double-click it and check that the class name of the class option is afx: 400000: 8: 10011: 0: 1550db.
Then:
Hwnd =: findwindow (_ T ("afx: 400000: 8: 10011: 0: 1550db"), null );
Getwindowthreadprocessid (hwnd, & id_num); // Note: The second parameter is the process ID, and the return value is the thread ID.
Handle Hd = OpenProcess (process_all_access, false, id_num );
Terminateprocess (HD, 0 );
Form: http://hi.baidu.com/hundreds/item/6a9954eb97049a3a86d9defe