1
votes

I did a project of Server Socket in Visual studio in C++ MFC based. 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.

Now I want to use that server exe file in some other computer. So that whenever that computer starts, that server exe automatically starts. so for this i need to disable the connect button, so that after debugging, server GUi opens and connected automatically. But i don't want that server GUI opens in another computer in autostart as well. i want to disable that server GUI.

I got an idea of modalless dialog to work on it. Is it good or what approach should I use ?

2
Please don't misuse the caps lock button - especially for titles. - Mysticial
If your program is suffering from magic pushbuttons, a ShowWindow(SW_HIDE) could achieve what you want without refactoring the code. However, a proper solution would involve separating GUI from core, like @Lol4t0 suggested. - Anonymous Coward
i didnot use ShowWindow in my project. I used modal dialog. may be you are talking about modeless dialog. IF so, then should i need to make a totally new project based on modeless dialog ? And how to seperate GUI from core. I dont have this idea. kindly tell plz - Nabeel
ShowWindow() simply controls the visibility of a window (a dialog is a window too). As for refactoring, move your socket server code to its own class if that's not the case already and use it in your CWinApp based class or directly in WinMain. To debug it, you could create another project that uses your class in a dialog. - Anonymous Coward

2 Answers

3
votes

You probably want to separate GUI part and server part of your application. Ideally, if your server is actually a server, you should start it as service. Then you will have separate GUI tool to control it.

Another approach is to have command line argument that determines whether server should be started with GUI enabled or disabled.

1
votes

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.

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:

  1. Never ever just "copy-past" code without to know what MFC is doing in the background (Win32api).
  2. Do not use 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. It is realy worth the time you spend on!

Good luck!