Skip to content

Commit

Permalink
Fix the color effect randomly being activated by other running programs
Browse files Browse the repository at this point in the history
  • Loading branch information
mlaily committed Dec 5, 2018
1 parent fc405b0 commit 744ae4f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions NegativeScreen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@

using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.IO;
using System.Linq;
using System.Windows.Forms;

namespace NegativeScreen
{
class Program
internal class Program
{
[STAThread]
static void Main(string[] args)
private static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

Expand Down Expand Up @@ -72,7 +73,7 @@ There is a Vista version though. You can download it on
foreach (ProcessThread thread in aleadyRunningInstance.Threads)
{
// The goal is to enable the already running instance color effect:
NativeMethods.PostThreadMessage((uint)thread.Id, UserMessageFilter.WM_ENABLE_COLOR_EFFECT, IntPtr.Zero, IntPtr.Zero);
NativeMethods.PostThreadMessage((uint)thread.Id, UserMessageFilter.WM_ENABLE_COLOR_EFFECT, UserMessageFilter.ExpectedParams, UserMessageFilter.ExpectedParams);
}
return;
}
Expand Down Expand Up @@ -126,11 +127,12 @@ private static bool IsAnotherInstanceAlreadyRunning(out Process alreadyRunningIn
/// </summary>
public class UserMessageFilter : IMessageFilter
{
public const int WM_ENABLE_COLOR_EFFECT = (int)WindowMessage.WM_USER + 0;
public const int WM_ENABLE_COLOR_EFFECT = (int)WindowMessage.WM_APP + 42;
public static readonly IntPtr ExpectedParams = new IntPtr(1337);

public bool PreFilterMessage(ref Message m)
{
if (m.Msg == WM_ENABLE_COLOR_EFFECT)
if (m.Msg == WM_ENABLE_COLOR_EFFECT && m.LParam == ExpectedParams && m.WParam == ExpectedParams && Configuration.Current.ActiveOnStartup)
{
// Handle a custom WM_ENABLE_COLOR_EFFECT message
// so that NegativeScreen can be enabled from another process/instance.
Expand Down

0 comments on commit 744ae4f

Please sign in to comment.