private void OnCaptionMouseDown(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Left) { return; } WinAPIHelper.ReleaseCapture(); WinAPIHelper.SendMessage(Handle, WinAPIHelper.WM_NCLBUTTONDOWN, WinAPIHelper.HTCAPTION, IntPtr.Zero); }
public void WriteTextBox() { string txt = "Hello Hook!"; //获得窗体句柄 IntPtr winHwnd = WinAPIHelper.FindWindow("WindowsForms10.Window.8.app.0.378734a", "MyWindow"); //获得窗体上TextBox句柄 IntPtr txtHwnd = WinAPIHelper.FindWindowEx(winHwnd, IntPtr.Zero, "WindowsForms10.EDIT.app.0.378734a", ""); //向TextBox中写入内容 WinAPIHelper.BringWindowToTop(winHwnd); IntPtr result = WinAPIHelper.SendMessage(txtHwnd, 0x000C, (IntPtr)txt.Length, txt); IntPtr result1 = WinAPIHelper.SendMessage(txtHwnd, 0x000C, (IntPtr)0, txt); }
private void OnMemoEditEditValueChanging(object sender, ChangingEventArgs e) { textBox.Text = e.NewValue?.ToString() ?? string.Empty; if (!_allowToSave) { return; } var linesCount = WinAPIHelper.SendMessage(textBox.Handle, 0x00BA, IntPtr.Zero, IntPtr.Zero); if (linesCount <= 2) { return; } textBox.Text = e.OldValue?.ToString() ?? string.Empty; e.Cancel = true; }
private void OnButtonMouseMove(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Left) { return; } if (_dragStartRectangle.IsEmpty) { return; } if (!_dragStartRectangle.Contains(e.Location)) { WinAPIHelper.ReleaseCapture(); WinAPIHelper.SendMessage(Handle, WinAPIHelper.WM_NCLBUTTONDOWN, WinAPIHelper.HTCAPTION, IntPtr.Zero); } }
private void OnTabControlMouseDown(object sender, MouseEventArgs e) { if (AppManager.Instance.Settings.UserSettings.UseDockedStyle) { return; } if (e.Button != MouseButtons.Left) { return; } if (e.Clicks > 1) { return; } WinAPIHelper.ReleaseCapture(); WinAPIHelper.SendMessage(Handle, WinAPIHelper.WM_NCLBUTTONDOWN, WinAPIHelper.HTCAPTION, IntPtr.Zero); }
private void changePCMModules(string moduleName) { var moduleList = XMLHelper.LoadPCMFlashModules(); foreach (var module in moduleList) { if (" " + module.Key == moduleName) { WinAPIHelper.SendMessage(pcmComboBoxModules, 0x014F /*CB_SHOWDROPDOWN*/, 1, ""); WinAPIHelper.SendMessage(pcmComboBoxModules, 0x014E /*CB_SETCURSEL*/, module.Value, ""); WinAPIHelper.SendMessage(pcmComboBoxModules, 0x0201 /*WM_LBUTTONDOWN*/, 0, "-1"); WinAPIHelper.SendMessage(pcmComboBoxModules, 0x0202 /*WM_LBUTTONUP*/, 0, "-1"); WinAPIHelper.SendMessage(pcmComboBoxModules, 0x014F /*CB_SHOWDROPDOWN*/, 0, "0"); WinAPIHelper.SendMessage(pcmComboBoxModules, WinAPIHelper.CB_SETCURSEL, module.Value, ""); return; } } WinAPIHelper.SendMessage(pcmComboBoxModules, 0x014F /*CB_SHOWDROPDOWN*/, 1, ""); WinAPIHelper.SendMessage(pcmComboBoxModules, 0x014E /*CB_SETCURSEL*/, 1, ""); WinAPIHelper.SendMessage(pcmComboBoxModules, 0x0201 /*WM_LBUTTONDOWN*/, 0, "-1"); WinAPIHelper.SendMessage(pcmComboBoxModules, 0x0202 /*WM_LBUTTONUP*/, 0, "-1"); WinAPIHelper.SendMessage(pcmComboBoxModules, 0x014F /*CB_SHOWDROPDOWN*/, 0, "0"); WinAPIHelper.SendMessage(pcmComboBoxModules, WinAPIHelper.CB_SETCURSEL, 1, ""); }
private void VTFlasher_Load(object sender, EventArgs e) { if (File.Exists(Path.Combine(Application.StartupPath, FilePathProvider.PasswordFilePath))) { savedPassword = FileHelper.ReadText(Path.Combine(Application.StartupPath, FilePathProvider.PasswordFilePath)); if (!string.IsNullOrEmpty(savedPassword)) { txtPassword.Text = (string)serializationHelper.DeserializeObject(savedPassword); checkBoxSavePassword.Checked = true; } } var info = new ProcessStartInfo { FileName = AppDomain.CurrentDomain.BaseDirectory + "\\PcmFlasher\\pcmflash.exe", UseShellExecute = true, //CreateNoWindow = true, RedirectStandardInput = false, RedirectStandardOutput = false, RedirectStandardError = false, // WindowStyle = ProcessWindowStyle.Hidden }; pcmProcess = Process.Start(info); pcmProcess.WaitForInputIdle(); pcmMainWindow = WinAPIHelper.FindWindowByCaption(IntPtr.Zero, "PCMflash"); WinAPIHelper.SetParent(pcmProcess.MainWindowHandle, this.Handle); pcmChildren = GetChildWindows(pcmMainWindow); pcmComboBoxModules = WinAPIHelper.FindWindowEx(pcmMainWindow, pcmChildren[6], null, null); pcmComboBoxAdapters = WinAPIHelper.FindWindowEx(pcmMainWindow, pcmChildren[0], null, null); pcmTextBoxFilePath = WinAPIHelper.FindWindowEx(pcmMainWindow, pcmChildren[14], null, null); pcmButtonExit = WinAPIHelper.FindWindowEx(pcmMainWindow, pcmChildren[22], null, null); pcmButtonSettings = WinAPIHelper.FindWindowEx(pcmMainWindow, pcmChildren[4], null, null); pcmKeyNumber = WinAPIHelper.FindWindowEx(pcmMainWindow, pcmChildren[3], null, null); pcmTextBoxStatus = WinAPIHelper.FindWindowEx(pcmMainWindow, pcmChildren[20], null, null); pcmButtonInitialize = WinAPIHelper.FindWindowEx(pcmMainWindow, pcmChildren[10], null, null); pcmButtonIdentify = WinAPIHelper.FindWindowEx(pcmMainWindow, pcmChildren[7], null, null); pcmButtonReadErrors = WinAPIHelper.FindWindowEx(pcmMainWindow, pcmChildren[8], null, null); pcmButtonRestart = WinAPIHelper.FindWindowEx(pcmMainWindow, pcmChildren[9], null, null); pcmButtonEraseErrors = WinAPIHelper.FindWindowEx(pcmMainWindow, pcmChildren[11], null, null); pcmButtonRestartAdaptation = WinAPIHelper.FindWindowEx(pcmMainWindow, pcmChildren[12], null, null); pcmButtonRead = WinAPIHelper.FindWindowEx(pcmMainWindow, pcmChildren[17], null, null); pcmButtonWrite = WinAPIHelper.FindWindowEx(pcmMainWindow, pcmChildren[18], null, null); pcmButtonCheckCorrectCS = WinAPIHelper.FindWindowEx(pcmMainWindow, pcmChildren[16], null, null); InitializeComboBoxControl(pcmComboBoxAdapters, cbAdapter); //InitializeComboBoxControl(pcmComboBoxModules, cbModules); SetButtonStatus(); WinAPIHelper.SendMessage(pcmTextBoxStatus, WinAPIHelper.WM_GETTEXT, 10000, sb); if (sb.ToString().Contains("Электронный ключ недоступен")) { pcmProcess.Kill(); pcmMainWindow = IntPtr.Zero; panelKeyUnavailible.BringToFront(); panelKeyUnavailible.Visible = true; return; } else { panelKeyUnavailible.Visible = false; } txtStatusThread = new Thread(() => { string pcmTextData = ""; while (true) { WinAPIHelper.SendMessage(pcmTextBoxStatus, WinAPIHelper.WM_GETTEXT, 10000, sb); pcmTextData = sb.ToString(); var stringPcmText = pcmTextData.Replace("\n", "").Split('\r'); var denyStringsList = new List <string>(); denyStringsList.Add("Версия программы"); foreach (string denyStrings in denyStringsList) { stringPcmText = stringPcmText.Where(t => !t.StartsWith(denyStrings)).ToArray <string>(); } //this.Invoke(()=>txtStatus.Text = sb.ToString()); this.Invoke(() => tbReflashText.Text = String.Join("\r\n", stringPcmText)); Thread.Sleep(100); } }); txtStatusThread.Start(); }