简体   繁体   English

在Visual Studio中创建非GUI服务器应用程序

[英]Make Non-GUI server application in Visual Studio

I did a project of Server Socket in Visual studio in C++ MFC based. 我在基于C ++ MFC的Visual Studio中做了一个Server Socket项目。 Now, after debugging the project, server GUI opens, then after clicking on the CONNECT button on server GUI, you can connect the clients to that server and so on. 现在,在调试项目之后,服务器GUI打开,然后在单击服务器GUI上的CONNECT按钮后,您可以将客户端连接到该服务器,依此类推。

Now I want to use that server exe file in some other computer. 现在我想在其他计算机上使用该服务器exe文件。 So that whenever that computer starts, that server exe automatically starts. 因此,无论何时该计算机启动,该服务器exe都会自动启动。 so for this i need to disable the connect button, so that after debugging, server GUi opens and connected automatically. 所以为此我需要禁用连接按钮,以便在调试后,服务器GUi自动打开并连接。 But i don't want that server GUI opens in another computer in autostart as well. 但我不希望服务器GUI在自动启动中的另一台计算机上打开。 i want to disable that server GUI. 我想禁用该服务器GUI。

I got an idea of modalless dialog to work on it. 我想到了无模式对话框来处理它。 Is it good or what approach should I use ? 它是好还是我应该使用什么方法?

You probably want to separate GUI part and server part of your application. 您可能希望将应用程序的GUI部件和服务器部分分开。 Ideally, if your server is actually a server, you should start it as service . 理想情况下,如果您的服务器实际上是服务器,则应将其作为服务启动。 Then you will have separate GUI tool to control it. 然后你将有单独的GUI工具来控制它。

Another approach is to have command line argument that determines whether server should be started with GUI enabled or disabled. 另一种方法是使用命令行参数来确定是应该在启用GUI还是禁用GUI的情况下启动服务器。

The only professional and stable solution of such an application is, to splitt it in a console part, which you put under the control of service control and a gui part wich the user can start when he wants. 这种应用程序唯一专业和稳定的解决方案是将其分解为控制台部分,您可以将其置于服务控制的控制之下,以及用户可以随时启动的gui部分。

I tried solutions like yours and so I can tell you from my own experience, that you will face a lot of problems. 我试过像你这样的解决方案,所以我可以根据自己的经验告诉你,你会遇到很多问题。

However, a possible solution would be to hide the window and lay the app down to systray and this is a very interesting discussion about hinding windows. 但是,一个可能的解决方案是隐藏窗口并将应用程序放到系统托盘上是一个关于隐藏窗口的非常有趣的讨论。

Additionaly I have two good advices in case of MFC: 另外,对于MFC,我有两个好的建议:

  1. Never ever just "copy-past" code without to know what MFC is doing in the background (Win32api). 永远不要只是“复制过去”代码而不知道MFC在后台做什么(Win32api)。
  2. Do not use MFC. 不要使用MFC。 Have a closer look at QT or wxWidges when you need windows, to shortcut encapsulation of win32api also have a look at boost library. 当你需要windows时,仔细看看QT或wxWidges,快速封装win32api也看看boost库。 It is realy worth the time you spend on! 真的值得你花时间!

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM