Well, post it so we all can learn! 
Anyway, I fooled around a little, and came to the following modification, which appears to work better:
Code: Select all
If window_h < 0
    UseWindow(windownr)
    window_h = WindowID(windownr)
  EndIf
  ;
  t1 = GetWindowThreadProcessId_(GetTopWindow_(0),0)
  t2 = GetWindowThreadProcessId_(window_h,0)
  If t1 <> t2
    AttachThreadInput_(t1,t2,#True)
  EndIf
  Delay(128)
  SetFocus_(window_h)
  SetWindowPos_(window_h,#HWND_TOP,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE)
  If t1 <> t2
    AttachThreadInput_(t1,t2,#False)
  EndIf
  SetWindowPos_(window_h,#HWND_TOP,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE)
It looks like XP is trying to do smart things, such as grabbing back the top window after I disconnected the threads. Also SetForegroundWindow_() appears to be less efficient than SetWindowPos_()... beats me.
Added: oh darn, doesn't work 100%, who can help me further?