private void ReceiveDataFromClient() { while (true) { try { PipeSecurity pse = new PipeSecurity(); pse.SetAccessRule(new PipeAccessRule("Everyone", PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow));//设置访问规则 NamedPipeServerStream _pipeServer = new NamedPipeServerStream("StartupAddPipe", PipeDirection.InOut, 10, PipeTransmissionMode.Message, PipeOptions.Asynchronous, 1024, 1024, pse, HandleInheritability.None); _pipeServer.WaitForConnection(); //Waiting using (StreamReader sr = new StreamReader(_pipeServer)) { string path = sr.ReadLine().Trim(); string defaultName = System.IO.Path.GetFileNameWithoutExtension(path).ToLower(); // InstructionTextBox 被主线程占用,利用 Dispatcher 进行操作 InstructionTextBox.Dispatcher.BeginInvoke((Action)(() => { InstructionTextBox.Text = "@add" + " " + defaultName + " " + path; InstructionTextBox.SelectionStart = ("@add" + " ").Length; InstructionTextBox.SelectionLength = defaultName.Length; Visibility = Visibility.Visible; InstructionTextBox.Focus(); })); } Thread.Sleep(1000); } catch (Exception) { /* I don't care */ } } }
private void page5_Click(object sender, EventArgs e) { InstructionTextBox.Clear(); InstructionTextBox.Text = page5Text; InstructionTextBox.Refresh(); page5.Enabled = false; introPage.Enabled = true; page3.Enabled = true; page1.Enabled = true; page2.Enabled = true; page4.Enabled = true; }
private void InitializeGUI(AThemeConfig tc, bool hideWhenStart = false, bool mustShowDetails = false) { Resize(); themeConfig = tc; InstructionTextBox.Background = themeConfig.BackgroundInput; InstructionTextBox.Foreground = themeConfig.ForegroundInput; TestRichTextbox.Background = themeConfig.BackgroundOutput; TestRichTextbox.Foreground = themeConfig.ForegroundOutput; InstructionTextBox.Focus(); // Hide when start up if (hideWhenStart) { Visibility = Visibility.Hidden; showOutput = false; Resize(); } }
private void CheckCommandLine() { List <string> commandLineArgList = new List <string>(Environment.GetCommandLineArgs()); if (commandLineArgList.Count == 0) { return; } string path = commandLineArgList[commandLineArgList.Count - 1].Trim(); if (path != "" && path != AHelper.BASE_PATH + @"\Alterful.exe" && (File.Exists(path) || Directory.Exists(path))) { string defaultName = System.IO.Path.GetFileNameWithoutExtension(path).ToLower(); InstructionTextBox.Text = "@add" + " " + defaultName + " " + path; InstructionTextBox.SelectionStart = ("@add" + " ").Length; InstructionTextBox.SelectionLength = defaultName.Length; InstructionTextBox.Focus(); } }
/// <summary> /// 指令框按键按下事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void InstructionTextBox_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter && "" != InstructionTextBox.Text) { e.Handled = true; if (!constInstructionInputMode) { new Thread(() => { InstructionTextBox.Dispatcher.BeginInvoke((Action)(() => ExecuteTextBoxInstrution())); }).Start(); } else { e.Handled = false; Resize(true, 12, 500); InstructionTextBox.Height = 500; InstructionTextBox.MaxLines = 500; } return; } if (e.Key == Key.Enter && "" == InstructionTextBox.Text) { Visibility = Visibility.Hidden; showOutput = false; Resize(); } if (e.Key == Key.Escape) { Visibility = Visibility.Hidden; showOutput = false; Resize(); } if (e.KeyboardDevice.Modifiers == ModifierKeys.Alt) { e.Handled = true; showOutput = !showOutput; Resize(); return; } if (e.Key == Key.Tab) { e.Handled = true; if (InstructionTextBox.Text[InstructionTextBox.Text.Length - 1] != ' ') { completing = true; InstructionTextBox.AppendText(" "); completing = false; } InstructionTextBox.CaretIndex = InstructionTextBox.Text.Length; } }
/// <summary> /// 窗体回调函数,接收所有窗体消息的事件处理函数 /// </summary> /// <param name="hWnd">窗口句柄</param> /// <param name="msg">消息</param> /// <param name="wideParam">附加参数1</param> /// <param name="longParam">附加参数2</param> /// <param name="handled">是否处理</param> /// <returns>返回句柄</returns> private IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wideParam, IntPtr longParam, ref bool handled) { var hotkeySetting = new AHotKeySetting(); // Console.WriteLine(wideParam.ToInt32()); switch (msg) { case HotKeyManager.WM_HOTKEY: int sid = wideParam.ToInt32(); if (sid == m_HotKeySettings[AHotKeySetting.AWAKEN]) { hotkeySetting = AHotKeySetting.AWAKEN; //TODO AWAKEN Visibility = IsVisible ? Visibility.Hidden : Visibility.Visible; showOutput = constInstructionInputMode; Resize(); if (Visibility == Visibility.Visible) { InstructionTextBox.Focus(); } } else if (constInstructionInputMode && sid == m_HotKeySettings[AHotKeySetting.CANCEL_CONST_INSTRUCTION_INPUT]) { constInstructionInputMode = false; TestRichTextbox.IsReadOnly = true; InstructionTextBox.IsEnabled = true; // Get const instruction lines and update max width. foreach (string ciLine in GetConstInstructionInputLines()) { UpdateMaxWidth(ciLine); } string outputMsg = "\nOperation [" + InstructionTextBox.Text + "] cancelled."; UpdateMaxWidth(outputMsg); AppendRTBLine(TestRichTextbox, outputMsg, themeConfig.ForegroundOutputError, themeConfig.BackgroundOutputError); TestRichTextbox.BorderThickness = new Thickness(1, 1, 1, 0); InstructionTextBox.Focus(); showOutput = true; Resize(); } else if (constInstructionInputMode && sid == m_HotKeySettings[AHotKeySetting.CONFIRM_CONST_INSTRUCTION_INPUT]) { ConstInstructionItem ciItem = AInstruction_Macro.GetConstInstructionItem(InstructionTextBox.Text); constInstructionInputMode = false; TestRichTextbox.IsReadOnly = true; InstructionTextBox.IsEnabled = true; string outputHead = ciItem.ConstInstruction + "("; foreach (string paramName in ciItem.ParameterList) { outputHead += paramName + ","; } outputHead = (outputHead[outputHead.Length - 1] == ',' ? outputHead.Substring(0, outputHead.Length - 1) : outputHead) + ")"; string output = ""; // Get const instruction lines and update max width. foreach (string ciLine in GetConstInstructionInputLines()) { output += ciLine + "\n"; UpdateMaxWidth(ciLine); } string outputMsg = ""; SolidColorBrush colorBackground = themeConfig.BackgroundOutputOk; try { try { File.Delete(AHelper.CONST_INSTRUCTION_PATH + @"\" + OldConstInstructionFileName); } catch { } using (StreamWriter writer = new StreamWriter(AHelper.CONST_INSTRUCTION_PATH + @"\" + outputHead, false)) { writer.WriteLine(output); } outputMsg = "\nAdd const instruction [" + InstructionTextBox.Text + "] successfully."; } catch (Exception exception) { outputMsg = "\n" + exception.Message; colorBackground = themeConfig.BackgroundOutputError; } finally { UpdateMaxWidth(outputMsg); AppendRTBLine(TestRichTextbox, outputMsg, themeConfig.BackgroundOutput, colorBackground); TestRichTextbox.BorderThickness = new Thickness(1, 1, 1, 0); InstructionTextBox.Focus(); showOutput = true; InstructionTextBox.Text = ""; Resize(); } } handled = true; break; } hotkeySetting = hotkeySetting + 0; // Meaningless, just for clearing up warnning return(IntPtr.Zero); }