Looks like d3d8 is unique; unlike d3d9ex, it checks if the foreground window belongs to the thread, where d3d9ex explicitly checks for focus_window instead.
ddraw is like d3d9ex where it checks its window explicitly, but it differs from both d3d8 and d3d9ex in that it treats an invisible window as "not active" and doesn't do changes—both d3d8 and d3d9ex do changes if the window is invisible.