I may be approaching this in completely the wrong way as I am pretty new to the C++ language and the overall way this kind of application should be structured, but I hope to confirm the correct method here.
Essentially, I have one cpp file which operates as a console application & a separate cpp file which runs as a windowed application. I want to be able to launch the windowed application when a certain point is reached within the console application. Is this possible? If so, how would I go about doing this?
Some more detail - The console application acts as a 'server' using winsock to communicate with another console application (the client). When the console server application reaches a certain point (a client connects with it) I wish to then launch the other windowed application I have created which will render certain graphics onscreen using Directx. Currently I have both these cpp files as separate projects in a single C++ 2010 Express solution. Currently, there are no links between the two cpp files and they both operate correctly when run separately.
If any more specifics are required, I can provide them but I really want to find out if this approach in general will work.
Thanks.
If you are not running a managed C++ application, then CreateProcess is the canonical WIN32 system call to use.
Do you just want to run the exe from another exe?
System::Diagnostics::Process::Start("C:\\Folder\\file.exe");
Related
I've been making a simple application which is able to launch a variety of other applications through QT5 (using QProcess class) but I've been running into a few key issues with the design. Specifically, it seems that Qprocess cannot set focus to windows that have been created via QProcess' start() function. This means that once a user opens more than one window, it can never return to the previous window that has been opened. After looking further into this dilemma, it has become clear that my program will need to be able to handle basic window management in order to fulfill my specifications.
I've decided that the best example to study for my program is Docky, which is capable of opening, closing and switching windows. Looking at the source code for that project was helpful, but there were many C# system calls that were used for fetching the list of client-windows which aren't available for my C++ program.
How can I get a list of all the X11 Windows that the client is running and provide basic window management (Switch To/ Open / Close Window) using C++? Is there a cross platform way of doing this through QT? Can I get this information directly using XServer?
I have developed communication program with c++ console programming, it is complete and works fine. Now I need to change my code for some real-time purpose, where I need to use the previous and add further and generate the .avi movie (most probably with BMP images).
The thing is the that as I have understood that the movie can only be generated with win32 c++ and not console programming?
hence
1. Can I use the same code (with necessary changes ofcourse) and the APIs that I was using in console programming with the win32 programming?
Can I go the other way around, i.e. make the movie generation code in win32 c++ and later include somehow in the console program. If yes, any idea?
any other idea is also appreciable
There's no difference to Win32 programming and "console" programming - you can use both at the same time. The only difference is the main entry function you're using (most often main vs. WinMain). So, don't bother setting up a new project if the console app could be adjusted more easily.
In fact, console apps can even make windows, and a window-based app can create it's own consoles as well. And there's no difference to Win32 C++ and console C++ (apart from the main entry function you're using I've mentioned and the idiomatic way to communicate input and output).
Currently I'm working on this example
http://msdn.microsoft.com/en-us/library/windows/desktop/aa363432(v=vs.85).aspx
that helped me capture any changes in my hardware. (Like connecting and disconnecting a USB flash drive)
The sample explains that in order to enable my console project to compile this code I had to set Project->Properties->Linker->System->Subsystem to Windows
My main problem is that I require the project to stay like a console application.
Is there any way to run this code by a console application or shall I be using a whole new strategy?
Thanks
I have a simple C++ console application and wondered if there would be any way to add a GUI without having to remake the application.
I am using a MinGW compiler, the Eclipse CDT IDE and standard and boost libraries.
(without knowing much of the console application)
You will have to remake the application.
If the console application is "well made", user interaction disconnected from actual functional code, then it should be a straightforward conversion.
Just create the appropriate UI and call the necessary functions.
For example if your console application contained a textual menu and asked answers, then you will have buttons and/or menu and/or edit box in the GUI that you will need to patch up to the code.
Max.
If you don't want to rewrite the application you could trying using a separated engine and interface pattern where the GUI and console apps are separate executables where the GUI spawn an instance of the console app and communicates with it to drive the application through some mechanism, e.g. Stdin
If your console application cannot be driven this way you nay need to change / rewrite the app
You should detail your question in order to get more precise answers.
What is the level of interactivity your console application provide ?
- It's just like a simple command with input parameters that produce output at end of the program
in this case, you can just code a gui front end that will get the parameters from a form or whatever you need and then your gui application will launch the console command, parse the result and display it in the gui.
- the console application is very interactive (takes input from the user during all the execution)
the console application code very big and very coupled to console interaction :
Maybe you can write a gui wrapper that takes std::in and std::out and render the two streams in gui widgets but that can be tricky. This is not a very pleasant solution, it should be used only if you really don't want to get inside the console application code.
the console application code is not that big or its easy to split the console input/ouput part from the rest of the program :
In this case, you should make a library from your app and then write a gui for it.
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 ?
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.
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:
Never ever just "copy-past" code without to know what MFC is doing in the background (Win32api).
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!