Is it possible to interrupt the focus change of a window?

I’m currently trying to implement my own dialog windows and some windows need to keep the focus while the windows are open. My current solution is to just set the focus to true again if it loses it, but this causes the window decoration to flicker as there is a frame where the window is not in focus before it gains focus again. Is there a way to directly interrupt the focus loss?