It a is a c# winform app. I've set ShowInTaskbar prop to false because I don't want the program to appear in taskbar, but like this SetForegroundWindow or ShowWindowAsync don't work.
views:
936answers:
1Raymond Chen explains the things the govern the rules in Windows around foreground activation in his classic article Foreground activation permission is like love: You can't steal it, it has to be given to you. Roughly speaking, you cannot steal foreground activation using a call like SetForegroundWindow
, you need to be given it from a process which already has the foreground activation.
In your case, when you have show in taskbar set, the taskbar is able to give your application the foreground activation, because when you click on the taskbar icon for your window, this will (briefly) give the activation to the taskbar. If you don't have the activation shown in the taskbar, you need to find a way to have an application that does give it to you. One way that is explicitly allowed is to use a notification window (tray) icon.