//Gets called when this form has laoaded private void WallpaperForm_Load(object sender, System.EventArgs e) { //Start the refresh timer ImageRenderer.StartTimer(); //Start the update active state timer Overlay.StartTimer(); //Calling the starting method startingMethod(); //Setup for the ticker ticker.Tick += new EventHandler(TickEvent); ticker.Interval = tickRate; ticker.Start(); }
private static int counter = 0; //TODO: Put this variable at the top of class //Makes the appriopriate window the foreground private async static void UpdateForegroundWindow(Object myObject, EventArgs myEventArgs) { if (Control.MouseButtons == MouseButtons.Left || counter >= 10) { if (counter >= 10) { counter = 0; } foregroundWindow = GetForegroundWindow(); //Console.WriteLine(foregroundWindow); if (foregroundWindow.ToInt32() == 65792) { Console.WriteLine("Desktop"); } updateTask = Task.Run(() => UpdateShouldBeForeground()); await Task.WhenAll(updateTask); if (shouldBeForeground && !shouldBeForegroundPrior) { Program.overlayForm.TopMost = true; //TODO: Figure out why this line causes poor graphics performance SetForegroundWindow(Program.overlayForm.Handle); //Note sure whether this line is needed SetForegroundWindow(foregroundWindow); ImageRenderer.StopRendering(); } else if (!shouldBeForeground && shouldBeForegroundPrior) { Program.overlayForm.TopMost = false; SetForegroundWindow(foregroundWindow); ImageRenderer.StartRendering(); } shouldBeForegroundPrior = shouldBeForeground; } counter++; }