private void CreateNativeProcess()
        {
            this.Process                = ProcessCreator.CreateProcess(ApplicationString);
            Application.Current.Exit   += (x, y) => Process.Kill();
            Process.EnableRaisingEvents = true;
            Process.Exited             += Process_Exited;

            Thread.Sleep(100); //BAD, need a better way to wait for signal

            //Gets the current window style, removes the border from it (~0x00450000)
            ExternalFunctions.SetWindowLong(Process.MainWindowHandle, -16, (int)(ExternalFunctions.GetWindowLong(Process.MainWindowHandle, -16) & ~0x00450000));

            System.Windows.Forms.ContainerControl panel1 = new System.Windows.Forms.ContainerControl();

            IntPtr value = ExternalFunctions.SetParent(Process.MainWindowHandle, panel1.Handle);

            this.Window = Process.MainWindowHandle;

            //HookNativeKeyboardEvent();

            this.Content = new System.Windows.Forms.Integration.WindowsFormsHost()
            {
                Child = panel1
            };
        }
        static NativeFrameworkContentControl()
        {
            FrameworkElement.WidthProperty.OverrideMetadata(typeof(NativeFrameworkContentControl), new FrameworkPropertyMetadata(0.0, (x, y) =>
            {
                if (y.NewValue != y.OldValue)
                {
                    NativeFrameworkContentControl element = x as NativeFrameworkContentControl;

                    if (element != null && element.Window != IntPtr.Zero)
                    {
                        ExternalFunctions.MoveWindow(element.Window, 0, 0, Convert.ToInt32(element.Width), Convert.ToInt32(element.Height), false);
                    }
                }
            }));

            FrameworkElement.HeightProperty.OverrideMetadata(typeof(NativeFrameworkContentControl), new FrameworkPropertyMetadata(0.0, (x, y) =>
            {
                if (y.NewValue != y.OldValue)
                {
                    NativeFrameworkContentControl element = x as NativeFrameworkContentControl;
                    if (element != null && element.Window != IntPtr.Zero)
                    {
                        ExternalFunctions.MoveWindow(element.Window, 0, 0, Convert.ToInt32(element.Width), Convert.ToInt32(element.Height), false);
                    }
                }
            }));


            ProcessProperty = DependencyProperty.Register("Process", typeof(Process), typeof(NativeFrameworkContentControl), new FrameworkPropertyMetadata(null, (x, y) =>
            {
            })
            {
                DefaultUpdateSourceTrigger = System.Windows.Data.UpdateSourceTrigger.PropertyChanged
            });
        }
        private static void CalcScreenRes()
        {
            var   ptrToDesk = ExternalFunctions.GetDesktopWindow();
            _RECT r         = new _RECT();

            ExternalFunctions.GetWindowRect(ptrToDesk, out r);
            ScreenWidth  = r.right / 1.5;
            ScreenHeight = r.bottom / 2;

            Encoding.Unicode.GetBytes("hello");
        }
Exemple #4
0
        public void SendMessage(string message, IntPtr pro, Action <string> ActCallBack, bool includeReturn)
        {
            ActCallBack("Sending Message.........");

            ExternalFunctions.SetForegroundWindow(pro);
            InputSimulator.SimulateTextEntry(message);

            if (includeReturn)
            {
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
            }

            ActCallBack("Message Sent Successfully");                                                              //Maybe pass future report back
            ExternalFunctions.SetForegroundWindow(new WindowInteropHelper(Application.Current.MainWindow).Handle); //Return focus back to main app
        }
Exemple #5
0
        public async Task SendMessageAsync(string message, IntPtr pro, int interval)
        {
            await Task.Run(() =>
            {
                Timer timer    = new Timer(1000);
                timer.Elapsed += ((x, y) =>
                {
                    if (!token.IsCancellationRequested)
                    {
                        ExternalFunctions.SetForegroundWindow(pro);
                        InputSimulator.SimulateTextEntry(message);
                    }
                    else
                    {
                        timer.Stop();
                        timer.Dispose();
                    }
                });

                timer.Start();
            });

            await Task.Delay(-1, token);
        }
 private void HookNativeKeyboardEvent()
 {
     _lowLevelKeyBoardReference = LowLevelKeyboardProc; //Store a reference to this function pointer, as it gets invoked from unmanaged code
     ExternalFunctions.SetWindowsHookEx(13, _lowLevelKeyBoardReference, ExternalFunctions.GetWindowLong(Process.MainWindowHandle, -6), 0);
 }