Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / June 2007

Tip: Looking for answers? Try searching our database.

Owned forms in Excel add-in

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tom - 15 Jun 2007 08:41 GMT
Hi,

I want to use forms in my Excel application-level add-in that have the
main Excel window set as their owner. Could someone who knows these
thins tell me, am I disposing the handle correctly?

   public partial class ExcelForm : Form
   {
       NativeWindow nativeWindow;

       public void Show(IntPtr handle)
       {
           nativeWindow = new NativeWindow();
           nativeWindow.AssignHandle(handle);
           base.Show(nativeWindow);
       }

       protected override void Dispose(bool disposing)
       {
           if (disposing && (components != null)) // Windows Form
Designer generated code
           {
               components.Dispose();
           }

           // Is this the correct way and place?
           if (nativeWindow != null)
           {
               nativeWindow.ReleaseHandle();
           }

           base.Dispose(disposing);
       }
}

Usage:
ExcelForm excelForm = new ExcelForm();
excelForm.Show(new IntPtr(Application.Hwnd));
Ben Voigt [C++ MVP] - 15 Jun 2007 18:50 GMT
> Hi,
>
[quoted text clipped - 25 lines]
>            {
>                nativeWindow.ReleaseHandle();

Are you trying to leave the window open after your .NET form is disposed?
That's what ReleaseHandle does, detaches the Windows object from the .NET
object.  If you want the window to close just do nothing, base.Dispose()
below will cleanup the window.

>            }
>
[quoted text clipped - 5 lines]
> ExcelForm excelForm = new ExcelForm();
> excelForm.Show(new IntPtr(Application.Hwnd));
Tom - 21 Jun 2007 10:47 GMT
The native window I'm passing is the main window of Excel.
So I guess the answer is yes, I need the window to stay open after
my .NET child form closes.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.