Dan
Dan

Reputation: 73

Prevent a Windows app from stealing the focus

I have created a windows application in C++ and I want to make so whenever I run it, it doesn't steal focus from whichever window is currently focused(or maybe steal the focus and give it back right away). I'm not creating any window so i'm not sure how to change the window style, my program runs in the background.

I couldn't find any answer that worked for C++, is there any way I can do this?

Upvotes: 0

Views: 2146

Answers (2)

Menace
Menace

Reputation: 1070

Make sure you use the extended style WS_EX_NOACTIVATE when using CreateWindowEx(). See the Microsoft Docs for CreateWindowEx.

Upvotes: 0

FrankieTheSkin
FrankieTheSkin

Reputation: 21

When you start your application by clicking on the EXE or shortcut, Windows Explorer takes focus, not your app. The only way to start your app and not let Windows Explorer take focus is to start your program when Windows starts, via registry key.

Upvotes: 2

Related Questions