public static void StartD2(Form mainForm, DiabloHostPanel panel, string title, string gameExePath) { Process diabloProcess = new Process(); ProcessStartInfo info = new ProcessStartInfo(); info.FileName = gameExePath; info.Arguments = "-w -ns"; diabloProcess = Process.Start(info); diabloProcess.EnableRaisingEvents = true; //diabloProcess.Exited += new EventHandler(diabloProcess_Exited); // Wait for the app to load diabloProcess.WaitForInputIdle(); var diabloHandle = diabloProcess.MainWindowHandle; DiabloWindow dw = new DiabloWindow(mainForm, panel, diabloHandle, title); // Application.OpenForms[0] panel.BindDiabloWindow(dw); dw.Activate(); }
public void SetHostPanel(DiabloHostPanel hostPanel) { this.targetControl = hostPanel; }
public DiabloWindow(Form mainWindow, DiabloHostPanel overlayControl, IntPtr diablo2Handle, string text) { this.Text = text; 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(); DiabloWindows.Add(this); underlayForm = new Form(); underlayForm.FormBorderStyle = FormBorderStyle.None; underlayForm.Text = "GreenVex 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 OverlayWindow(); 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("GreenVex.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(); }