C++ System Command window shows up when launching a WinForm Application - c#

I have a C++ - based application. This application triggers in turn a C# based WinForm executable. I use system() to launch this. When I do this, I get system (command prompt) window alongwith my form. My question is how to suppress this window. I want only to launch the application without prompt window...
// Trigger the form application
system("C:\\tmp\\MyApp\\SBCForm.exe");

Related

How can I trigger a WinForms app when I open another Desktop application?

I want to trigger a WinForms app when I open notepad.exe. How can I do that?
So far I've tried the Process Class. Here when you run the C# Program, then the external application is executed. MDI keeps the external application in the form.
I want to create an overlay for notepad.exe. The overlay being the child window and notepad.exe being the parent window.
However, I want execution of notepad.exe to trigger the WinForms app.

How to create a console application that runs in background?

I created app that open every time that I start pc. So its so annoying to close it every time so I'm wondering if its some code that will hide my console app. I saw videos and tutorials on forms but idk how to do it with console app.
The easiest way to do this is change your console app to a windows app.
Console apps get a console made for them by Windows. But if you change it to a windows forms app, then windows expect the application to make a window, so if you never make a window, then it will never show
The other way is to turn your application into a service. This has some additional requirements in terms of programming
Option 1
You can use this run command:
start /min "SomeTitle" MyConsoleApp.exe myarg1 myarg2
Thus it will be on the taskbar minimized.
Option 2
If you use a file link in the start menu, select the start minimized option for the exe.
Option 3
Using a WinForm app you will be able to use a tray icon by setting the main form as not visible, to say it simply because it can be complex according to the expected behavior, and it will not be in the taskbar too.
Option 4
If you don't want a main form, create a win form app, delete the form file and the code in the main method, and you're done, without GUI nor console, no main input and no main output but you can show MessageBox and some forms when necessary, just a background process only visible in the Task Manager.
With that you can add a tray icon to to offer exit and some status information for example.
Option 5
Also you can create a windows service:
.NET console application as Windows service
Note
In all cases, if you don't use an internal message events dispatcher like the WinForms Application pattern or WPF and so on, be carefull to not saturate the CPU with the processings like with loops and use Thread.Sleep() between iterations or any thread idleing pattern or some timer if necessary.

How to diagnose a program run by the user from a program run by Windows(run on windows startup)in C#?

i have a wpf program that can run in windows startup. i want to run
program in WindowState.Normal mode when user run the program and
in WindowState.Minimized when windows run the program at startup. but problem
is that i do not know how to distinguish between them.
One way to do it would be to use a launcher app, an app's who's sole purpose is to launch your main application with a command line argument that says that the user launched it. If that command line argument is there, it was launched by the launcher and you can show it in normal mode. If the argument isn't there it was launched by the OS and run it minimized.

C# Console Application Keypress capturing

Is it possible to check pressed keys in a Console Application in any other way than Console.ReadKey()?
I've changed the project settings to Windows Application so that the console window won't show. But if the console window isn't shown the application crashes since Console.ReadKey() requires a console window. Is there any workaround?
NOTE:
I don't want any window open, just track a key-press, through a thread.
You cannot receive key pressed event if you do not have a window. You hae to have a console or "desktop" window.
In case of console 'Console.ReadKey()' does the job, in case of WPF or Windows Forms 'KeyPressed' event does the job.

Starting application from background process

I'm working a small WPF based program for launching applications through system wide hotkeys implemented using hooking. I'm implementing it in C# and Visual Studio 2010.
When I detect the specific keypress I use Process.Start(...) to run the application. This works fine while Visual Studio is active, placing the new application in the foreground with input focus, as I would expect. If my launcher is in the background (behind another active program), it still detects the key and starts the application correctly, in front of everything else.
The problem is, that when I run the launcher without Visual Studio active, and my launcher application isn't front, neither will applications it starts. They appear in front of the launcher but behind the active application.
I can see that other software, like AutoHotkey, is able to do hotkey launching with this behavior, but I fail to see what I'm doing wrong.
Update: Just figured out a solution to this issue that works in my development environment. I first register a global hotkey through the Windows API RegisterHotKey using the launcher main window handle. The key could be any, but should be one that normally doesn't exist physically, F24 in my case. Then, whenever I detect a keypress through the hooks that should launch an app, I first call keybd_event to 'fake' a keypress for the hotkey.
For WPF use:
keybd_event((byte)KeyInterop.VirtualKeyFromKey(Key.F24),0,KEYEVENTF_KEYUP,0);
For WinForms use:
keybd_event((byte)Keys.F24,0,KEYEVENTF_KEYUP,0);
This will bring enough focus to the launcher, so that Process.Start(...) makes the executed program get in front. It does not bring the launcher window to front, nor does it make the launcher accept inputs.
If Activate() is called on the main window after the keybd_event(), this will bring the main window to front and allow for keyboard input, just as if the user had task switched.

Categories

Resources