C++ Application that doesn't steal focus and just runs

Jun 28, 2013 at 2:41pm
I'd like to make a simple, small application which, when started doesn't steal focus, shows in the process list and runs until I stop it.

Unfortunately I have no experience with this type of scripting so I'd like some help, Thanks!
Jun 28, 2013 at 5:02pm
closed account (Dy7SLyTq)
theres porbably something in the windows api
Jun 28, 2013 at 6:21pm
What platform are you on?
Last edited on Jun 28, 2013 at 6:21pm
Jun 29, 2013 at 9:35am
Hi. I am using Visual Studio 2013 Preview.
Jun 29, 2013 at 7:07pm
closed account (Dy7SLyTq)
so windows thumper
Jun 29, 2013 at 8:29pm
The only way I know to do what you're asking is platform dependent, so this will only work on Windows.
You can hide the console window with the Windows API function ShowWindow: http://msdn.microsoft.com/en-us/library/windows/desktop/ms633548(v=vs.85).aspx
You can create a function to hide your console window something like the following:
1
2
3
4
5
6
7
#include <windows.h>
void HideConsole()
{
    HWND hConsole;
    hConsole = FindWindowA("ConsoleWindowClass", NULL);
    ShowWindow(hConsole, SW_HIDE);
}

Jun 30, 2013 at 12:14pm
Hi!

While building the above solution I get the following error:

"Error 1 error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source? c:\users\urban\documents\visual studio 2013\projects\win32project3\win32project3\win32project3.cpp 8 1 Win32Project3"

Thanks for the help!
Jun 30, 2013 at 12:24pm
If you're talking Windows specific, you could just make it a Windows app (rather than a Windows console app) and not create a GUI.

Andy

PS @Thumper

If you want to get the HWND of your console app's (console) window, you can just use

GetConsoleWindow function
http://msdn.microsoft.com/en-us/library/windows/desktop/ms683175%28v=vs.85%29.aspx
(for Windows 2000 and after.)

Jun 30, 2013 at 3:42pm
Hi,

can you be so good to provide the actual code please, I'm having a lot of problems with this and can't get it working.

Thank you!

Edit: Managed it.
Last edited on Jun 30, 2013 at 4:33pm
Topic archived. No new replies allowed.