public void Close()
 {
     this.mainWindow.Move -= new EventHandler(OnParentMove);
     overlayForm.Close();
     underlayForm.Close();
     overlayForm  = null;
     underlayForm = null;
     disposed     = true;
 }
        public D2Window(Form mainWindow, D2HostPanel overlayControl, IntPtr diablo2Handle)
        {
            this.mainWindow    = mainWindow;
            this.handle        = diablo2Handle;
            this.targetControl = overlayControl;

            this.mainWindow.Move       += new EventHandler(OnParentMove);
            this.targetControl.KeyDown += new System.Windows.Forms.KeyEventHandler(targetControl_KeyDown);
            this.targetControl.KeyUp   += new System.Windows.Forms.KeyEventHandler(targetControl_KeyUp);

            this.targetControl.RegisterEvents();

            underlayForm = new Form();
            underlayForm.FormBorderStyle = FormBorderStyle.None;
            underlayForm.Text            = "D2 Container Window";
            underlayForm.Controls.Add(new Panel()
            {
                Width = Screen.PrimaryScreen.WorkingArea.Width, Height = Screen.PrimaryScreen.WorkingArea.Height
            });
            underlayForm.ShowInTaskbar = false;
            underlayForm.Show();

            Mouse.OverrideCursor = System.Windows.Input.Cursors.None;

            overlayForm            = new D2OverlayWindow();
            overlayForm.MouseMove += new System.Windows.Input.MouseEventHandler(overlayForm_MouseMove);
            overlayForm.Width      = 1600;
            overlayForm.Height     = 1200;
            overlayForm.Show();

            HwndSource hwndSource = PresentationSource.FromVisual(overlayForm) as HwndSource;

            System.Windows.Point formSize = hwndSource.CompositionTarget.TransformFromDevice.Transform(new System.Windows.Point(targetControl.Width, targetControl.Height));

            scaleX = formSize.X / 800;
            scaleY = formSize.Y / 600;

            this.overlayForm.Canvas.RenderTransform = new ScaleTransform(scaleX, scaleY);

            System.IO.Stream fileStream = this.GetType().Assembly.GetManifestResourceStream("D2PartyTime.Resources.D2Cursor.png");
            if (fileStream != null)
            {
                PngBitmapDecoder bitmapDecoder = new PngBitmapDecoder(fileStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                ImageSource      imageSource   = bitmapDecoder.Frames[0];

                d2Cursor = new System.Windows.Controls.Image();
                d2Cursor.IsHitTestVisible = false;
                //d2Cursor.MouseMove += new System.Windows.Input.MouseEventHandler(d2Cursor_MouseMove);
                d2Cursor.Source  = imageSource;
                d2Cursor.Stretch = Stretch.Uniform;

                d2Cursor.Visibility = Visibility.Hidden;

                overlayForm.Canvas.Children.Add(d2Cursor);
            }

            RegisterThumbnail();
            Hide();

            OnParentMove(null, null);

            this.mainWindow.Activate();
        }