Beispiel #1
0
        private void RunCustomD2(string path, D2HostPanel diabloPanel)
        {
            if (diabloWindow == null)
            {
                if (!string.IsNullOrEmpty(path) && System.IO.File.Exists(path))
                {
                    Process          diabloProcess = new Process();
                    ProcessStartInfo info          = new ProcessStartInfo();
                    info.FileName  = path;
                    info.Arguments = "-w";

                    diabloProcess = Process.Start(info);
                    diabloProcess.EnableRaisingEvents = true;
                    diabloProcess.Exited += new EventHandler(diabloProcess_Exited);

                    // Wait for the app to load
                    diabloProcess.WaitForInputIdle();

                    diabloHandle = diabloProcess.MainWindowHandle;

                    // If greater than Windows XP
                    if (System.Environment.OSVersion.Version.Major > 5)
                    {
                        diabloWindow = new D2Window(Application.OpenForms[0], diabloPanel, diabloHandle);
                        diabloPanel.BindDiabloWindow(diabloWindow);
                    }
                }
            }
            //diabloPanel.DiabloWindow.Activate();
        }
 public void SetHostPanel(D2HostPanel hostPanel)
 {
     this.targetControl = hostPanel;
 }
        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();
        }