啟動「CBOX 央視影音」播放器後,需在不重啟進程前提下切換頻道(體育/財經/新聞)。
[DllImport("user32.dll")] static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
// 例:向 ListView 發送 LVM_SETITEMSTATE 選中指定項
// 或向 Button 發送 BM_CLICKusing System.Windows.Automation;
var proc = Process.GetProcessesByName("CBox").FirstOrDefault();
var ae = AutomationElement.FromHandle(proc.MainWindowHandle);
var list = ae.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElementIdentifiers.ControlTypeProperty, ControlType.List));
// 選中項、觸發 InvokePatternProcess.Start 帶參數,**但題目要求不關閉進程**,故僅能走 UI 自動化。SendKeys 或 keybd_event 更簡單。