With this simple code:
I can set without problems a form of mine owned from an EXTERNAL application (I don't use SetParent API because my owned form can be a bit external from the Owner window)
The problem is that, in the rare cases that my program crashes, also the External window becomes UNUSABLE, if few words it crashes too.
Now the question: How to avoid the problem?? In ApplicationEvents.VB I can't manage the problem with a Private Sub MyApplication_UnhandledException, because when the program crashes the Sub don't works...
Code:
'note: in NativeMethods Class
<DllImport("user32.dll")> _
Friend Shared Function SetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As IntPtr) As Integer
End Function
'Classe level variable
Dim OldParent As IntPtr
'in Form_Load
OldParent = CType(NativeMethods.SetWindowLong(Me.Handle, -8, ExternalWindowHwnd), IntPtr)
'in Form_Closing
NativeMethods.SetWindowLong(Me.Handle, -8, OldParent)
The problem is that, in the rare cases that my program crashes, also the External window becomes UNUSABLE, if few words it crashes too.
Now the question: How to avoid the problem?? In ApplicationEvents.VB I can't manage the problem with a Private Sub MyApplication_UnhandledException, because when the program crashes the Sub don't works...