OK, this is old, but as I often face issues concerning 'stuff' that needs a visible window/window handle, I use a System.Windows.Forms.Timer like this:
(This UserControl hosts a native NamespaceTreeControl that needs a visible handle to initialize)
Private Sub NamespaceTreeControlLite_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim tmr As New Timer() With {.Interval = 100, .Enabled = True}
AddHandler tmr.Tick, AddressOf WaitForUCTRLVisible
End Sub
Private Sub WaitForUCTRLVisible(sender As Object, e As EventArgs)
If Me.Visible Then
Try
Marshal.ThrowExceptionForHR(Me.NamespaceTreeBase1.Initialize(Me, Me.ClientRectangle))
Me.SetRootPath()
Catch ex As Exception
MsgBox(ex.ToString(), MsgBoxStyle.Critical)
End Try
Dim tmr = TryCast(sender, Timer)
If Not tmr Is Nothing Then
tmr.Dispose()
tmr = Nothing
End If
End If
End Sub
(It also releaves the PIA of having global variables that are used for this sole purpose...)