private static string GetOperaUrl(IntPtr hWnd) { string url = null; try { var dde = new NDde.Client.DdeClient("opera", "WWW_GetWindowInfo"); dde.Connect(); url = dde.Request("URL", 3000); dde.Disconnect(); if (!string.IsNullOrEmpty(url)) { url = url.Split(',')[0].Trim('\"'); } } catch (Exception ex) { TraceLogger.Instance.WriteException(ex); // if not support dde, try window text. try { IntPtr hAddressWnd = User32.FindWindowEx(hWnd, IntPtr.Zero, "ViewsTextfieldEdit", ""); if (hAddressWnd != IntPtr.Zero) { StringBuilder sb = new StringBuilder(2083); User32.SendMessage(hAddressWnd, User32.WM_GETTEXT, 2083, sb); url = sb.ToString(); } } catch (Exception ex2) { TraceLogger.Instance.WriteException(ex2); } } return(url); }
private static string GetFirfoxUrl(IntPtr hWnd) { string url = null; try { var dde = new NDde.Client.DdeClient("firefox", "WWW_GetWindowInfo"); dde.Connect(); url = dde.Request("URL", 3000); dde.Disconnect(); if (!string.IsNullOrEmpty(url)) { url = url.Split(',')[0].Trim('\"'); } } catch (Exception ex) { TraceLogger.Instance.WriteException(ex); } return(url); }
// This requires NDde // http://ndde.codeplex.com/ public static URLDetails[] Firefox() { NDde.Client.DdeClient dde = new NDde.Client.DdeClient("Firefox", "WWW_GetWindowInfo"); try { dde.Connect(); String url = dde.Request("URL", Int32.MaxValue); dde.Disconnect(); Int32 stop = url.IndexOf('"', 1); return(new URLDetails[] { new URLDetails() { URL = url.Substring(1, stop - 1), Title = url.Substring(stop + 3, url.Length - stop - 8) } }); } catch (Exception) { return(null); } }
public void ThreadProc(Object stateInfo) { // No state object was passed to QueueUserWorkItem, so stateInfo is null. Console.WriteLine("Hello from the thread pool."); NDde.Client.DdeClient client = new NDde.Client.DdeClient("SatPC32", "SatPcDdeConv"); try { client.Connect(); client.StartAdvise("SatPcDdeItem", 1, true, 60000); panel_status.Invoke((MethodInvoker) delegate { panel_status.Visible = true; }); while (true) { if (AppStatus == "stopped") { client.Disconnect(); client.Dispose(); break; } string satdata = client.Request("SatPcDdeItem", 60000); string[] words = satdata.Split(' '); //Console.WriteLine(word); string satname = ""; string downlink_freq = ""; string uplink_freq = ""; string downlink_mode = ""; string uplink_mode = ""; foreach (string word in words) { // Get Satellite Name if (word.StartsWith("SN")) { satname = word.Remove(0, 2); } else if (word.StartsWith("AZ")) { string azimuth = word.Remove(0, 2); } else if (word.StartsWith("EL")) { string elevation = word.Remove(0, 2); } else if (word.StartsWith("UP")) { uplink_freq = word.Remove(0, 2); } else if (word.StartsWith("UM")) { uplink_mode = word.Remove(0, 2); } else if (word.StartsWith("DN")) { downlink_freq = word.Remove(0, 2); } else if (word.StartsWith("DM")) { downlink_mode = word.Remove(0, 2); } label_satname.Invoke((MethodInvoker) delegate { label_satname.Text = satname; }); label_uplink_freq.Invoke((MethodInvoker) delegate { label_uplink_freq.Text = uplink_freq; }); label_downlink_freq.Invoke((MethodInvoker) delegate { label_downlink_freq.Text = downlink_freq; }); label_satmode_up.Invoke((MethodInvoker) delegate { label_satmode_up.Text = uplink_mode; }); label_satmode_down.Invoke((MethodInvoker) delegate { label_satmode_down.Text = downlink_mode; }); label_cloudlog_status.Invoke((MethodInvoker) delegate { label_cloudlog_status.Text = "Connected"; }); button1.Invoke((MethodInvoker) delegate { button1.Text = "Stop SatPC32 <> Cloudlog Link"; }); } using (WebClient cli = new WebClient()) { try { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3; cli.Headers[HttpRequestHeader.ContentType] = "application/json"; string response = cli.UploadString(textBox1.Text + "/index.php/api/radio", "{\"radio\":\"SatPC32\",\"frequency\":0,\"mode\":\"non\",\"sat_name\":\"" + satname + "\",\"downlink_freq\":\"" + downlink_freq + "\",\"uplink_freq\":\"" + uplink_freq + "\",\"downlink_mode\":\"" + downlink_mode + "\",\"uplink_mode\":\"" + uplink_mode + "\",\"key\":\"" + textBox2.Text + "\"}"); Console.WriteLine(response); label_cloudlog_status.Invoke((MethodInvoker) delegate { label_cloudlog_status.Text = "Connected"; }); } catch (WebException e) { // ERROR: Application forced to stop the thread although buttons etc not activated. label_cloudlog_status.Invoke((MethodInvoker) delegate { label_cloudlog_status.Text = "Disconnected"; }); panel_status.Invoke((MethodInvoker) delegate { panel_status.Visible = false; }); button1.Invoke((MethodInvoker) delegate { button1.Text = "SatPC32 <> Cloudlog Connect"; }); textBox1.Invoke((MethodInvoker) delegate { textBox1.ReadOnly = false; }); string text = "Lost connection to Cloudlog"; MessageBox.Show(text); AppStatus = "stopped"; break; } } System.Threading.Thread.Sleep(1000); } } catch { panel_status.Invoke((MethodInvoker) delegate { panel_status.Visible = false; }); button1.Invoke((MethodInvoker) delegate { button1.Text = "SatPC32 <> Cloudlog Connect"; }); textBox1.Invoke((MethodInvoker) delegate { textBox1.ReadOnly = false; }); string text = "DDE Connection to SatPC32 Failed"; MessageBox.Show(text); AppStatus = "stopped"; } }