VC: close an application

Source: Internet
Author: User

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

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.