Window messages in windows application with no window

前端 未结 3 909
走了就别回头了
走了就别回头了 2021-02-06 18:09

I have an application that I want to run in the background with no visible windows or consoles. To accomplish this, I create a windows application but I do not create a window.

3条回答
  •  礼貌的吻别
    2021-02-06 18:34

    To create an application that runs in the background, create a service. A service can respond to the ServiceMain calls.

    If you insist on creting a front end application, there are basically no legit reasons for applications to try to hide their main window. You executable image can be either GUI (IMAGE_SUBSYSTEM_WINDOWS_GUI) or console (IMAGE_SUBSYSTEM_WINDOWS_CUI), and you cannot mix them, see How do I write a program that can be run either as a console or a GUI application. If you choose a GUI application then you are expected to create a message pump. You may choose to create a hidden window as your 'main' window. You will get WM_QUERYENDSESSION and WM_ENDSESSION on this hidden window (which are the messages you're interested in, not WM_CLOSE).

    On the other hand a console app will have to handle signals, like Andon already showed you.

    Choose your poison. I strongly suggest to go the service route, as is the proper avenue for a 'background' application.

提交回复
热议问题