I have a GUI C++ application (Visual Studio 2008) that needs to be converted to a console one. I don't have a开发者_运维问答ny experience in C programming. Mostly I use .NET. Where do I start?
Down-converting a GUI app is major surgery. The programming model is entirely different, a GUI app is event driven. Relying on a message loop to deliver events, processed in message handlers. And typically a bunch of controls that take care of the grunge work of taking input.
Given that you have to completely redesign the app to make it work as a console mode app and that you don't have experience with the language, writing this in a .NET language you have experience with is the best way to get it completed quickly.
Start with refactoring. Make sure that GUI is separated from business logic. Then add another interface to access this business logic: one that uses console, rather than GUI widgets.
Check out ncurses and readline to help you build a rich console application. You can't use them both at once, as I found out, so try ncurses if your application is more oriented toward output/display or will implement single-key interactions (hotkeys), and readline if it's more of a line-at-a-time user input situation.
- Create a new project with a main
- add your files
- here you got a console application doing nothing. It may still create windows, or if you like, hidden windows.
- Now it's up to your creativity to tie interface to existing code.
- Don't forget to download and use boost::program_options to access command line parameters properly.
精彩评论