Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42454

[vb2010] Problems setting a Form of mine owned from external window

$
0
0
With this simple code:

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)

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...

Viewing all articles
Browse latest Browse all 42454

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>