public Form1() { InitializeComponent(); // Create a simple tray menu with only one item. var trayMenu = new ContextMenu(); trayMenu.MenuItems.Add("Exit", OnExit); TrayIcon = new NotifyIcon { Text = @"Hyperion Screen Capture (Not Connected)" }; TrayIcon.DoubleClick += TrayIcon_DoubleClick; TrayIcon.Icon = Resources.Hyperion_disabled; // Add menu to tray icon and show it. TrayIcon.ContextMenu = trayMenu; TrayIcon.Visible = true; _d = new DxScreenCapture(MonitorIndex); _protoClient = new ProtoClient(); _protoClient.Init(HyperionServerIp, HyperionServerPort, HyperionMessagePriority); if (_protoClient.IsConnected()) { if (NotificationLevel == NotifcationLevels.Info) { Notifications.Info(string.Format("Connected to Hyperion server on {0}!", HyperionServerIp)); } CaptureEnabled = true; Thread t = new Thread(StartCapture) { IsBackground = true }; t.Start(); } TrayIcon.Icon = Resources.Hyperion_enabled; TrayIcon.Text = @"Hyperion Screen Capture (Enabled)"; }
private static void StartCapture() { try { _d = new DxScreenCapture(Settings.MonitorIndex); while (_captureEnabled) { if (!ProtoClient.IsConnected()) { // Reconnect every 5s (default) ProtoClient.Init(Settings.HyperionServerIp, Settings.HyperionServerPort, Settings.HyperionMessagePriority); Thread.Sleep(Settings.ReconnectInterval); continue; } var s = _d.CaptureScreen(Settings.HyperionWidth, Settings.HyperionHeight, _d.MonitorIndex); var dr = s.LockRectangle(LockFlags.None); var ds = dr.Data; var x = RemoveAlpha(ds); s.UnlockRectangle(); s.Dispose(); ds.Dispose(); ProtoClient.SendImageToServer(x); // Add small delay to reduce cpu usage (200FPS max) Thread.Sleep(Settings.CaptureInterval); } _d = null; } catch (Exception ex) { _captureEnabled = false; Notifications.Error("Error occured during capture: " + ex.Message); } }