Create an Application without a Window
When you write a WinMain program, you automatically get the /SUBSYSTEM option to be windows in the compiler. (Assuming you use Visual Studio). For any other compiler a similar option might be present but the flag name might be different.
This causes the compiler to create an entry in the executable file format (PE format) that marks the executable as a windows executable.
Once this information is present in the executable, the system loader that starts the program will treat your binary as a windows executable and not a console program and therefore it does not cause console windows to automatically open when it runs.
But a windows program need not create any windows if it need not want to, much like all those programs and services that you see running in the taskbar, but do not see any corresponding windows for them. This can also happen if you create a window but opt not to show it.
All you need to do, to achieve all this is,
#include <Windows.h>
int WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int cmdShow)
{
/* do your stuff here. If you return from this function the program ends */
}
The reason you require a WinMain itself is that once you mark the subsystem as Windows, the linker assumes that your entry point function (which is called after the program loads and the C Run TIme library initializes) will be WinMain and not main. If you do not provide a WinMain in such a program you will get an un-resolved symbol error during the linking process.
how to create an application without window frame
- Can be done with window styling as described by @Deanna
- Can be achieved with a timer via SetTimer firing WM_TIMER messages. On your handler, you get the time, generate the string and use SetWindowText on some static control in your window.
- This can be done by handling WM_NCHITTEST as described here.
- For this, you need to handle WM_CONTEXTMENU, generating a right-click menu via TrackPopupMenu/TrackPopupMenuEx
For more specific questions, you should probably pose a new question since right now your question is very general and broad.
Windows Application without a Window
Set the following values on the Window
:
<Window ...
WindowStyle="None"
AllowsTransparency="True"
ResizeMode="NoResize"
Background="Transparent">
<Grid>
</Grid>
</Window>
The window will have no borders, only the content will be visible.
How to run a console application without showing the console window
"or alternatively how to code a main menu that will launch one of the other three forms (but making them the startup form)."
Start with a standard WinForms Project and use the Application.Startup() event. From there you can check your startup parameters and then dynamically change the Startup form by assigning your desired instance to "My.Application.MainForm". This will cause that form to load as if it was the one originally assigned to the "Startup Form" entry.
Click on Project --> Properties --> Application Tab --> "View Application Events" Button (bottom right; scroll down).
Change the Left dropdown from "(General)" to "(MyApplication Events)".
Change the Right dropdown from "Declarations" to "Startup".
Simplified code:
Namespace My
' The following events are available for MyApplication:
'
' Startup: Raised when the application starts, before the startup form is created.
' Shutdown: Raised after all application forms are closed. This event is not raised if the application terminates abnormally.
' UnhandledException: Raised if the application encounters an unhandled exception.
' StartupNextInstance: Raised when launching a single-instance application and the application is already active.
' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
Partial Friend Class MyApplication
Private Sub MyApplication_Startup(sender As Object, e As ApplicationServices.StartupEventArgs) Handles Me.Startup
If True Then
My.Application.MainForm = New Form1 ' <-- pass your desired instance to MainForm
End If
End Sub
End Class
End Namespace
How to create a background application using UWP without UI?
Firstly I think that it is good to clarify that even if you want to create UWP app that works in background you have to create normal Universal Windows Application from template in Visual Studio:
Each UWP application can register Background Task to perform some background operations.
You can find the whole implementation guide under below link:
https://msdn.microsoft.com/en-us/windows/uwp/launch-resume/create-and-register-a-background-task
Background task has to be registered by the app so there is no way to create only Background task without the app.
Please also remember that application without UI will not pass Windows Store certification.
How do I create a C# program without a GUI?
Create a windows application, remove the Form1.cs file, edit the Program.cs file to remove the lines
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Put your own code instead, and you're done.
c# run application without a dos/form window
then you need to create a Windows Service.
Visual Studio => New Project => Windows => Windows Service
Here is some more information:
- Introduction to Windows Service Applications
- How to: Create Windows Services
Related Topics
How to Use Covariant Return Types with Smart Pointers
Compilation Error: "Stddef.H: No Such File or Directory"
Isn't the Const Modifier Here Unnecessary
How to Initialize Std::Vector Over Already Allocated Memory
Acquire/Release Semantics with Non-Temporal Stores on X64
C++ Template Friend Operator Overloading
What Is the Scope of a 'While' and 'For' Loop
How to Use Something Like Std::Vector<Std::Mutex>
Do Class Functions/Variables Have to Be Declared Before Being Used
Virtual Tables and Memory Layout in Multiple Virtual Inheritance
The Behaviour of Floating Point Division by Zero
Simple Glob in C++ on Unix System
Override a Member Function with Different Return Type
Template Specialization and Enable_If Problems
Overloaded Functions Are Hidden in Derived Class
Initializer-List-Constructing a Vector of Noncopyable (But Movable) Objects