Reputation: 1125
I have an existing C++ win32 console app. This application contains a main program that continuously process some data from hardware in real time and has a server component (threaded) to stream the data out to clients.
I am thinking if it is possible to create a GUI for users to enter some program parameters before running this console program. The GUI i intend to only show the status of the console program, eg. running, no user interaction would be needed after the user clicks a Start button.
Any advise if this is possible? Thanks!
Upvotes: 0
Views: 4645
Reputation: 665
The way I implemented a process to GUI (when I had unfortunately not thought about the design to include the GUI), was to use a posix threaded process, one to run the code for the application, and one for the GUI, with global variables (hacky) shared by the parent (parent ran the two children processes) in a one-way manner (to avoid a race condition cropping up), so one variable would be write for process, read for GUI, and another would be read for process, write for GUI.
I had to re-write the processing coe to use busy waiting (bad) to wait for the information and state changing to hop between each busy waiting loop. The busy waiting state change didn't take too much to implement.
This isn't really the optimal way (this was very hacky), and a GUI should be designed into the code from the start rather than 'tacked on' later on. But this did work for me and the GUI did surprisingly well for a last minute additional.
Upvotes: 0
Reputation: 8733
Fast and dirty way - create GUI in any toolkit you wish (for example Qt, Gtk, Windows API...) and use standard system(const char *) function.
Nmap is a greatful topic, because many front ends exist, so you may be interested in digging into sources to see how they made front end to console application.
Upvotes: 1
Reputation: 11
It's typical for console applications to be configured using a text file, so that they can be run from a batch script without user interaction. The config file can be specified with a parameter.
Once you have this, it's straightforward to write a GUI config editor and launcher. A monitor program is probably best made into a Notification Area icon that will report when the process terminates or something appears in the console output.
Upvotes: 1
Reputation: 21319
Absolutely, just create a thread with a window message loop and you're done. This will likely require a separate thread for what you describe, although one could conceive other ways, depending on the exact details of your existing code.
The same is true for the converse: a GUI app can also create a console and output to it.
Upvotes: 4