How can I prevent my program from closing when a open console window is closed?

后端 未结 2 456
难免孤独
难免孤独 2020-12-11 06:56

I am trying to open the console from my main program (Win32). I found some code, and it works, but I don\'t understand it. The problem I\'m happening is that when I click X

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-11 07:12

    One thing you can do is disable the close button on the console window:

    HWND hwnd = ::GetConsoleWindow();
    if (hwnd != NULL)
    {
       HMENU hMenu = ::GetSystemMenu(hwnd, FALSE);
       if (hMenu != NULL) DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND);
    }
    

提交回复
热议问题