Example #1
0
        public static void MonitorThreadFunction()
        {
            App.Current.Dispatcher.Invoke((Action)(() =>
            {
                fnw = new FileNameWindow();
            }));
            while (true)
            {
                if (((GetActiveWindowTitle() == "压缩文件名和参数") || (GetActiveWindowTitle() == "添加到压缩包")) &&
                    (GetForegroundWindow() != HandledHwnd))
                {
                    int RarOr7z = 0;
                    if (GetActiveWindowTitle() == "压缩文件名和参数")
                    {
                        RarOr7z = 1;
                        string RarExe = GetRarExe();
                        ConfigTxt.Write("rarexe", RarExe, "");
                    }
                    if (GetActiveWindowTitle() == "添加到压缩包")
                    {
                        RarOr7z = 2;
                        string SevenZipExe = Get7zExe();
                        ConfigTxt.Write("7zexe", SevenZipExe, "");
                    }

                    Thread.Sleep(1100);
                    HandledHwnd = GetForegroundWindow();
                    Rect r = new Rect();
                    GetWindowRect(GetForegroundWindow(), ref r);
                    App.Current.Dispatcher.Invoke((Action)(() =>
                    {
                        fnw.Topmost = true;
                        fnw.Top = -10000;
                        fnw.Left = -10000;
                        fnw.UserNameTextBox.Text = ConfigTxt.Read("username", "用户名");
                        fnw.InitShow();
                        IntPtr fnwHwnd = (new WindowInteropHelper(fnw)).Handle;

                        if (RarOr7z == 1)
                        {
                            MoveWindow(fnwHwnd,
                                       r.Left + (r.Right - r.Left) / 2 - (r.Right - r.Left) * 150 / (100 * 2),
                                       r.Top + (r.Bottom - r.Top) / 2 - (r.Bottom - r.Top) * 46 / (100 * 2),
                                       (r.Right - r.Left) * 150 / 100,
                                       (r.Bottom - r.Top) * 46 / 100,
                                       true);
                        }
                        else if (RarOr7z == 2)
                        {
                            MoveWindow(fnwHwnd,
                                       r.Left,
                                       r.Top + (r.Bottom - r.Top) / 2 - (r.Bottom - r.Top) * 33 / (100 * 2),
                                       (r.Right - r.Left),
                                       (r.Bottom - r.Top) * 33 / 100,
                                       true);
                        }
                    }));
                }
                if (!IsWindow(HandledHwnd))
                {
                    App.Current.Dispatcher.Invoke((Action)(() =>
                    {
                        fnw.Close();
                    }));
                }
                Thread.Sleep(100);
            }
        }
 private void UserNameTextBox_TextChanged(object sender, TextChangedEventArgs e)
 {
     ConfigTxt.Write("username", ((TextBox)sender).Text, "用户名");
 }