Re: Using IWin32Window to SetParent

From: Jay B. Harlow [MVP - Outlook] (Jay_Harlow_MVP_at_msn.com)
Date: 03/16/04


Date: Tue, 16 Mar 2004 09:44:08 -0600

Dan,
It sounds like your handle was too large or too small an integer.

Try using:

> Private Declare Auto Function SetParent Lib "user32.dll" (ByVal Child As
> IntPtr, ByVal Parent As IntPtr) As IntPtr
> ...
> Private mlOldParent as IntPtr
> ...
> Friend Overloads Sub Show(ByVal oOwner As IWin32Window)
> Try
> mlOldParent = SetParent(Handle, oOwner.Handle)

Both an Int32 & an IntPtr are 32 bit values, however IntPtr is normally used
for Windows Handles, so if you define the parameters & variable as IntPtr
instead of Int32 you do not need to convert, also you will be ready for the
64bit version of the framework where IntPtr will be 64bit.

Hope this helps
Jay

"Dan" <qqqqq> wrote in message news:105ceon9q102baa@corp.supernews.com...
> Ed -
> Thanks for the response. The same code, today, is working. It's the oddest
> thing.
>
> Incidentally, the error was an overflow that was happening on
Handle.ToInt32
> when I called SetParent to restore the "original" parent. It was in the
Hide
> method below:
>
> Private Declare Auto Function SetParent Lib "user32.dll" (ByVal Child As
> Int32, ByVal Parent As Int32) As Int32
> ...
> Private mlOldParent as Int32
> ...
> Friend Overloads Sub Show(ByVal oOwner As IWin32Window)
> Try
> mlOldParent = SetParent(Handle.ToInt32, oOwner.Handle.ToInt32)
> Catch ex As Exception
> mlOldParent = -1
> End Try
>
> MyBase.Show()
> End Sub
> Friend Shadows Sub Hide()
> Try
> If mlOldParent > 0 Then
> Call SetParent(Handle.ToInt32, mlOldParent)
> End If
> Catch
> End Try
> End Sub
>
> Dan
>
> ""Ed Dore [MSFT]"" <eddo@online.microsoft.com> wrote in message
> news:jchiJyrCEHA.1672@cpmsftngxa06.phx.gbl...
> > Hi Dan,
> >
> > Something obviously changed if it was previously working. Probably the
> best
> > thing to do would be to debug the overflow exception. Can you track down
> > and post the section of code that's throwing the exception?
> >
> > For what it's worth, a better solution might be to create a toolwindow
in
> a
> > VS .Net addin. There are some ToolWindow samples available with the VS
> > Automation samples out on:
> >
> >
> >
>
http://www.microsoft.com/downloads/details.aspx?familyid=3ff9c915-30e5-430e-
> > 95b3-621dccd25150&displaylang=en
> >
> > Sincerely,
> > Ed Dore [MSFT]
> >
> > This post is 'AS IS' with no warranties, and confers no rights.
> >
>
>



Relevant Pages