/// <summary> /// this method starts a thread which shows a laserpointer dot on _Process's window on the specified position /// </summary> /// <param name="lpinfo"></param> public void show(LaserPointerInfo lpinfo) { //if a overlaywindow is already shown, the thread that runs the current overlaywindow is stopped if (_active) { stop(); } _active = true; //start a parameterized thread which shows the laserpointerdot displaythread = new Thread(new ParameterizedThreadStart(run)); displaythread.Start(lpinfo); }
private bool _finished = false; //tells if the thread which shows the overlaywindow is finished /// <summary> /// this method activates the overlay window for 5 seconds /// </summary> /// <param name="lpinfoobj"> /// the object that contains the information where the laserpointerdot is supposed to be shown /// </param> void run(object lpinfoobj) { LaserPointerInfo lpinfo = (lpinfoobj as LaserPointerInfo); try { if (_Process == null) { throw new Exception("Process to display laserpointerdot on is null"); } //initialize overlaywindow _Overlay = new OverLayWindow(); _processSharp = new ProcessSharp(_Process, MemoryType.Remote); _Overlay.active = true; _Overlay.Initialize(_processSharp.WindowFactory.MainWindow); _Overlay.Enable(lpinfo.xPercentage, lpinfo.yPercentage); //put window of _Process in the foreground SetForegroundWindow(_Process.MainWindowHandle); DateTime starttime = DateTime.Now; //register the time when this overlay is supposed to start Stopwatch sw = new Stopwatch(); sw.Start(); //show Window for 5 seconds and as long _active is true while (_active == true && sw.ElapsedMilliseconds < 5000) { _Overlay.Update(); } sw.Stop(); //disable overlay window _Overlay.active = false; _Overlay.Disable(); _Overlay.Dispose(); _finished = true; //this flag tells that the thread ended } catch (Exception ex) { if (_active) { throw new Exception(ex.Message); } } }
/// <summary> /// this method deserializes the given laserpointerinfo object and initializes a overlaywindow at the position /// given by the laserpointerinfoobject /// </summary> /// <param name="LpInfo"></param> public void LaserPointerCallBack(string LpInfojson) { if (_display_window == null) { _display_window = new DisplayWindow(_Process); } LaserPointerInfo lpinfo = JsonConvert.DeserializeObject <LaserPointerInfo>(LpInfojson); try { _display_window.show(lpinfo); } catch { MessageBox.Show("Error: Wasn't able to show the laserpointer, Make sure the Application\n" + "is running. It is important, that it was running, before the Laserpointer-Object was created!"); return; } }