private void window_loaded(object sender, RoutedEventArgs e)
        {
            this.LocationChanged += delegate
            {
                XPorter.Bus.Global_Offset_Tabs    = MainTab.TranslatePoint(new System.Windows.Point(), this);
                XPorter.Bus.Global_Offset_Tabs.Y += 28;
            };

            this.SizeChanged += delegate
            {
                XPorter.Bus.Global_Size_Tabs = new System.Windows.Point(MainTab.ActualWidth,
                                                                        MainTab.ActualHeight - 28);
            };

            XPorter.Bus.Global_Offset_Tabs = MainTab.TranslatePoint(new System.Windows.Point(), this);

            XPorter.Bus.Global_Size_Tabs = new
                                           System.Windows.Point(MainTab.ActualWidth, MainTab.ActualHeight - 28);

            var element = ((Panel)MainTab.Template.FindName("HeaderPanel", MainTab));

            element.MouseLeftButtonDown      += main_tab_mouse_dbl_click;
            XPorter.Bus.Global_Offset_Tabs.Y += 28;
            //XPorter.Bus.Main_Handle = new MainWindow();                                                             //initialize descriptor of mainwindow
            XPorter.Bus.Main_Handle = this;
            RCConnectLibrary.set_default_settings();                                                                  //read all setting for connection and control
        }
Esempio n. 2
0
 public void change_mode_menu(object sender, RoutedEventArgs e)
 {
     if (!Flagok)
     {
         Tmp.HostInfo.ControlPort = RCConnectLibrary.port_dealer(Tmp.HostInfo.Addr,
                                                                 new GlobalTypes.SysMessageStruct("PRT", 1), GlobalTypes.Settings.TCPPort + 1);
         RCConnectLibrary.send_to(
             RCConnectLibrary.get_tcp(Tmp.HostInfo.Addr, GlobalTypes.Settings.TCPPort).GetStream(),
             new GlobalTypes.SysMessageStruct("CTR", 0));
         Ctrl_Client        = RCConnectLibrary.get_tcp(Tmp.HostInfo.Addr, Tmp.HostInfo.ControlPort);
         Counter            = System.Environment.TickCount;
         thr_Cursor_Control = new Thread(cur_buf_sender);
         thr_Cursor_Control.Start();
         RCHOOKLIB.HookMng.Mouse += mouse_hook_proc;
         thr_Key_Control          = new Thread(key_buf_sender);
         thr_Key_Control.Start();
         RCHOOKLIB.HookMng.Keyboard += keyboard_hook_proc;
         XPorter.Bus.Main_Handle.Menu_Mode.Header = "Normal Mode";
         Flagok = true;
     }
     else
     {
         RCHOOKLIB.HookMng.Mouse    -= mouse_hook_proc;
         RCHOOKLIB.HookMng.Keyboard -= keyboard_hook_proc;
         RCConnectLibrary.send_to(RCConnectLibrary.get_tcp(Tmp.HostInfo.Addr, GlobalTypes.Settings.TCPPort).GetStream(),
                                  new GlobalTypes.SysMessageStruct("CTR", 1));
         XPorter.Bus.Main_Handle.Menu_Mode.Header = "Control Mode";
         MainWindow.thr_killer(thr_Cursor_Control);
         Flagok = false;
         Ctrl_Client.Client.Shutdown(SocketShutdown.Both);
         Ctrl_Client.Close();
     }
 }
        //function which performs in thread
        //public static void one_to_one(Object Arg)
        //{
        //    UdpClient client = new UdpClient(5012);                                                                 //port for exchange picture in onetoone mode
        //    client.Client.ReceiveTimeout = 10000;

        //    while (true)
        //    {
        //        GlobalTypes.ScreenPart recent_struct = receive_from<GlobalTypes.ScreenPart>(client);
        //        if (recent_struct.Buffer != null)
        //        {
        //            Bitmap bmp = buf_to_bitmap(recent_struct.Buffer);
        //            XPorter.Bus.Main_Handle.Dispatcher.Invoke(new MethodInvoker(delegate()                          //paint received picture
        //                {
        //                    XPorter.Bus.Main_Handle.show_pic(
        //                        bmp,
        //                        recent_struct.Point.X,
        //                        recent_struct.Point.Y
        //                        );
        //                }));
        //        }
        //    }
        //}

        public static void start_one_to_one(object Args)
        {
            GlobalTypes.ClientInfo tmp = Args as GlobalTypes.ClientInfo;
            if ((!RCConnectLibrary.Threads_Already_Started) && (tmp != null))
            {
                RCConnectLibrary.send_to_all_sys_msg(new GlobalTypes.SysMessageStruct("SCR", 11));

                tmp.HostInfo.ScreenPort = RCConnectLibrary.port_dealer(tmp.HostInfo.Addr, new GlobalTypes.SysMessageStruct
                                                                           ("PRT", 0), 8268); //TCP port + 1
                RCConnectLibrary.Opened_Ports.Add(tmp.HostInfo.ScreenPort);
                //Выполнить проверку если порты принялись нулевые....если так то сервер выеживается
                if (tmp.HostInfo.ScreenPort != 0)
                {
                    XPorter.Bus.Main_Handle.Dispatcher.Invoke(new MethodInvoker(delegate()
                    {
                        var tab       = XPorter.Bus.Main_Handle.uni_tab_creator(null, true);
                        tab.Unloaded += delegate
                        {
                            TcpClient client = RCConnectLibrary.get_tcp(tmp.HostInfo.Addr, GlobalTypes.Settings.TCPPort);
                            if (client != null)
                            {
                                RCConnectLibrary.sys_msg_analyzer(
                                    client,
                                    null,
                                    new GlobalTypes.SysMessageStruct("SCR", 11)
                                    );
                                client.Close();
                            }
                            //MainWindow.thr_killer(RCScreenClient.thr_One_To_One);
                        };

                        tab.Loaded += delegate
                        {
                            Grid target_grid = new Grid();
                            tab.Content      = target_grid;
                            tab.Header       = (GlobalTypes.Settings.TabHeader == "IP") ?
                                               tmp.HostInfo.Addr.ToString() : tmp.HostInfo.HostName;
                            scrfrm _win = new scrfrm(target_grid, tab, tmp);
                            ((FrameworkElement)tab.Template.FindName("Cross", tab)).MouseLeftButtonDown += delegate(
                                object ss,
                                MouseButtonEventArgs ee
                                )
                            {
                                _win.Close();
                                XPorter.Bus.Main_Handle.MainTab.Items.Remove(tab);
                            };


                            Bitmap bmp = new Bitmap(800, 600);
                            using (var gr = Graphics.FromImage(bmp)) {
                                gr.Clear(System.Drawing.Color.Black);
                            }
                            _win.Screen_Box.Image = bmp;
                        };
                        //_Win.GotFocus += delegate
                        //{
                        //    XPorter.Bus.MDI.curentAddress = tmp.HostInfo.Addr;
                        //    IPEndPoint point = new IPEndPoint(XPorter.Bus.MDI.curentAddress, 5002);
                        //    keyboardClient = new TcpClient();
                        //    keyboardClient.Connect(point);
                        //    RCHLib.RCHookManager.Keyboard += KeyboardControl;
                        //};
                        //_Win.LostFocus += delegate
                        //{
                        //   // keyboardClient.Close();
                        //    XPorter.Bus.MDI.curentAddress = null;
                        //    RCHLib.RCHookManager.Keyboard -= KeyboardControl;
                        //};


                        //IntPtr refBitmap = bmp.GetHbitmap();
                        //BitmapSource bmpsrc;
                        //bmpsrc = Imaging.CreateBitmapSourceFromHBitmap(
                        //refBitmap,
                        //IntPtr.Zero,
                        //Int32Rect.Empty,
                        //BitmapSizeOptions.FromEmptyOptions()
                        //);
                        //MainWindow.ScreenBox.Source = bmpsrc;
                        //TAB_item.Content=MainWindow.ScreenBox;
                        //Grid.SetRowSpan(MainWindow.ScreenBox, 2);
                        //MainWindow.DeleteObject(refBitmap);
                    }));
                    MainWindow.thr_killer(RCScreenClient.thr_Get_Img_From_UDP);
                    TcpClient _client = RCConnectLibrary.get_tcp(tmp.HostInfo.Addr, GlobalTypes.Settings.TCPPort);
                    RCConnectLibrary.sys_msg_analyzer(_client, tmp, new GlobalTypes.SysMessageStruct("SCR", 10));
                    //Object[] args = new Object[2];
                    //args[0] = tmp;
                    //args[1] = new GlobalTypes.ServiceMessageStruct("GET", 3);
                    //RCScreenClient.get_query(args);
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("Lost Connection!");
                }
            }
        }
        private void show_settings(object sender, RoutedEventArgs e)
        {
            if (Settings == null)
            {
                Settings = new ContentControl();
                var tab  = uni_tab_creator("Settings", true);
                var grid = new Grid();
                grid.Background = System.Windows.Media.Brushes.AliceBlue;
                Uri _uri = new Uri(RCResourceLibs.vsresources.settings_style, UriKind.Relative);
                ResourceDictionary local_dict = new ResourceDictionary();
                using (MemoryStream tmp_stream = new MemoryStream(Encoding.UTF8.GetBytes(_uri.ToString())))
                {
                    System.Windows.Markup.XamlReader reader = new System.Windows.Markup.XamlReader();
                    try
                    {
                        local_dict.MergedDictionaries.Add((ResourceDictionary)reader.LoadAsync(tmp_stream));
                        Settings.Resources = local_dict;
                    }
                    catch (Exception ex) { }
                }
                Uri uri = new Uri(RCResourceLibs.vsresources.win_settings, UriKind.Relative);
                //ResourceDictionary dict_res = new ResourceDictionary();
                using (MemoryStream tmp_stream = new MemoryStream(Encoding.UTF8.GetBytes(uri.ToString())))
                {
                    System.Windows.Markup.XamlReader xaml_reader = new System.Windows.Markup.XamlReader();
                    try
                    {
                        local_dict.MergedDictionaries.Add((ResourceDictionary)xaml_reader.LoadAsync(tmp_stream));
                    }
                    catch (Exception ex) { }
                    Settings.Resources = local_dict;
                    Settings.SetValue(Panel.ZIndexProperty, 110);
                    grid.Children.Add(Settings);
                    tab.Content = grid;
                }
                tab.Loaded += delegate
                {
                    ((TabItem)Settings.Template.FindName("General", Settings)).PreviewMouseLeftButtonDown       += label_click;
                    ((TabItem)Settings.Template.FindName("Sounds", Settings)).PreviewMouseLeftButtonDown        += label_click;
                    ((TabItem)Settings.Template.FindName("Video", Settings)).PreviewMouseLeftButtonDown         += label_click;
                    ((TabItem)Settings.Template.FindName("Privacy", Settings)).PreviewMouseLeftButtonDown       += label_click;
                    ((TabItem)Settings.Template.FindName("Notifications", Settings)).PreviewMouseLeftButtonDown += label_click;
                    ((TabItem)Settings.Template.FindName("Advanced", Settings)).PreviewMouseLeftButtonDown      += label_click;
                    TabSettings = (TabControl)Settings.Template.FindName("Settings", Settings);

                    ((Button)Settings.Template.FindName("Default_General1", Settings)).Click += delegate
                    {
                        RCConnectLibrary.set_default_settings();
                        //refresh all settings values
                    };
                    ((Button)Settings.Template.FindName("Default_General2", Settings)).Click += delegate
                    {
                        RCConnectLibrary.set_default_settings();
                        //refresh all settings values
                    };

                    ((Button)Settings.Template.FindName("Apply_General1", Settings)).Click += delegate
                    {
                        GlobalTypes.Settings.IPCatalog.Clear();
                        GlobalTypes.Settings.IPCatalog.Add(new GlobalTypes.IPInterval(
                                                               ((TextBox)Settings.Template.FindName("Left_Range_Ip", Settings)).Text, ((TextBox)Settings.Template.FindName("Left_Range_Ip", Settings)).Text
                                                               ));
                        if (((PasswordBox)Settings.Template.FindName("Password", Settings)).Password == ((PasswordBox)Settings.Template.FindName("Confirm_Password", Settings)).Password)
                        {
                            StatusBarText.Text            = "Password Accepted";
                            GlobalTypes.Settings.Password = ((PasswordBox)Settings.Template.FindName("Password", Settings)).Password;
                        }
                        else
                        {
                            StatusBarText.Text = "Passwords doesn't equals";
                        }
                        GlobalTypes.Settings.TabHeader = ((ComboBoxItem)((ComboBox)Settings.Template.FindName("Host_Name_Format", Settings)).SelectedItem).Content.ToString();
                    };
                    ((Button)Settings.Template.FindName("Apply_General2", Settings)).Click += delegate
                    {
                        GlobalTypes.Settings.TCPPort       = Convert.ToInt32(((TextBox)Settings.Template.FindName("TCP_Port", Settings)).Text);
                        GlobalTypes.Settings.Interval      = Convert.ToInt32(((Slider)Settings.Template.FindName("Refresh_Period", Settings)).Value);
                        GlobalTypes.Settings.TimeToConnect = Convert.ToInt32(((TextBox)Settings.Template.FindName("Connection_Timeout", Settings)).Text);
                        GlobalTypes.Settings.ThreadCount   = Convert.ToInt32(((Slider)Settings.Template.FindName("Thread_Count", Settings)).Value);
                    };
                };
                tab.Unloaded += delegate
                {
                    Settings = null;
                };
            }
            else
            {
                foreach (TabItem it in MainTab.Items)
                {
                    if (it.Header == "Settings")
                    {
                        MainTab.SelectedItem = it;
                    }
                }
            }
        }