using sendmessage to send wm_close to another process

后端 未结 3 606
清酒与你
清酒与你 2020-12-03 19:43

I want to send wm_close to another process, with which i want end that process safely.

int _tmain(int argc, _TCHAR* argv[])
{

    DWORD SetOfPID;
    SetOfP         


        
相关标签:
3条回答
  • 2020-12-03 20:01

    If the application does not process WM_CLOSE the DefWindowProc should handle this (by gracefully closing the application), however if the application is handling WM_CLOSE then it simply can choose to ignore it. Try sending the WM_DESTROY and WM_NCDESTROY messagees instead.

    0 讨论(0)
  • 2020-12-03 20:04

    I would attempt to close a (Process with) Window(s) in the following order:

    1. WM_CLOSE

    2. WM_QUIT

    3. WM_DESTROY

    4. TerminateProcess().

    Just my take as I am handling (disabling) WM_CLOSE for a Window and having difficulty distinguishing between User Close and close messages send by another master task. WM_QUIT seems to resolve my problem without using a custom WM_APP_CLOSE of my own. TerminateProcess is very much a last resort unclean exit to be avoided at all costs (it may leave handles (e.g. COM etc) and memory etc unfreed).

    0 讨论(0)
  • 2020-12-03 20:06

    Are you sure that the window you are finding is the correct one? You can check easily with Spy++. Moreover, when searching for a window, I think it's better to use EnumWindows. I'm not sure your method is correct.

    0 讨论(0)
提交回复
热议问题