Suliman
Suliman

Reputation: 1499

Is it's possible make GUI and console app in one exe?

I want to develop App with GUI, that can be run without showing GUI. How I can do it?

If it's possible would this App work on servers that do not have nothing related with GUI (ex: can I work with such App with ssh or so).

Any example please if it's possible.

Upvotes: 0

Views: 149

Answers (1)

Adam D. Ruppe
Adam D. Ruppe

Reputation: 25595

Yes, it isn't always easy though and might not be worth it. The general idea is to write a console program that attempts to dynamically load the gui libraries and create a window. If that succeeds, it detaches from the console/controlling terminal and becomes a gui program. On Windows, this may pop up a console window briefly when the user double clicks the exe as it would be created first, then quickly destroyed.

You would want to dynamically load the gui with dlopen/LoadLibrary because the libs might not even be present on the computer you're running on, and if you rely on the system to load them at startup, your program won't run at all when they are missing. This is the most painful part - checking the return value of XOpenDisplay or CreateWindow or whatever is easy, and detaching from a console is easy (FreeConsole or fork). But first you need to get your program to actually start in the worst case scenario of no client side gui libraries at all.

If you're ok with ignoring that case - if the libs are present but the display isn't, you just handle it as a regular runtime error - then it isn't too hard at all.

Upvotes: 2

Related Questions