can we have commands and functions of console and win32 c++ interchanged? - c++

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).

Related

program NSTouchBar with c++

The problem
I would like to use c++ to create an application that uses the new macbook pro touch bar. However I am not able to find any really good resources. And apple does not have any docs on using c++ to program the touch bar.
What I have done
I found this article on c++ and the touch bar, However I cannot find either of the header files for the script GLFW/glfw3.h and GLFW/glfw3native.h. These both seem critical to the script working.
More on the issue
Even if the above article's script works, there are no official docs for programing the touch bar with c++ (That I know of). I think that this is an important thing to have given the fact that many, if not most applications are written in c/c++.
Thank you in advance for the help!
So the article that you link to basically does not need the GLFW/glfw3.h and GLFW/glfw3native.h files if you are not using GLFW.
What UI framework are you using for your C++ app?
Unless it is still using Carbon, at the lowest level, the framework will be creating NSWindows to actually have windows in the UI. You need to get access to the NSWindow that your framework is using to host it the UI. If it is still using Carbon, I think you are probably not going to be able to accomplish this.
If the framework provides some mechanism to get the native platform window (which will be an NSWindow), you would replace the author's call to glfwGetCocoaWindow(window); with the correct call from your framework.
If the framework does not provide access to the NSWindow, then you will need to use the code that is commented out at the bottom of the article to attach your touchbar to the windows in your app.
Please note that all that code is Obj-C code; you'll need to have at least one .m or .mm file in your project to provide that Obj-C glue code to get access to the touchbar. Basically that code is a C-calleable wrapper around the Cocoa API.
Also note that you'll need to expand the list of buttons and actions for all the different things you want to put in the touchbar. You could add your own wrapping API so that the construction of the toolbar is done from C++ and registers actions that call-back into your C++ app to handle the events.
Fundamentally though, the touchbar is not available on any other platform, so there is no great benefit to trying to avoid writing Obj-C to implement your touchbar as that code will only run on macOS anyway. If you use .mm files to implement Obj-C++ for this code, you can still call into your C++ objects from your touchbar code.

How can I add a GUI to a pre-existing C++ console application?

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.

Launching a windowed application from a console application?

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");

Dev-C++ Run Program in Background without GUI

I recently began learning C++ in order to reach people w/o .net. I need to run my program in the background(without any visual indication to the user so no window or cmd). I know there a various methods to do this In C#, but I don't know how to do this in C++ (specifically Dev-C++). Any help is greatly appreciated.
First of all, you shouldn't be using Dev-C++. If you really don't want to use Visual Studio (why not? it's free!) then Code::Blocks or Eclipse or something is a better choice. Dev-C++ hasn't been updated in like 5 years...
The ways of creating background processes in C++ is basically the same as in C#, you just don't get the enormous class library that C# has which handles most of the work for you.
Your main choices are windows services, or creating a regular windows application and simply not displaying any windows... which one you choose depends on your specific requirements (do you want it run even when no one is logged in, or do you want it associated with a logged-in user, etc)
You need to be creating a Windows GUI application and not a console application (or else the console window will show). Then, just don't create any windows.

Convert GUI C++ app to a console one

I have a GUI C++ application (Visual Studio 2008) that needs to be converted to a console one.
I don't have any 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.