Hi I am trying to fix that when I open a speific program aero should been disable and when the speific program close I want the aero be enabled again.
My code:
{
const uint DWM_EC_DISABLECOMPOSITION = 0;
const uint DWM_EC_ENABLECOMPOSITION = 1;
[DllImport("dwmapi.dll", EntryPoint = "DwmEnableComposition")]
extern static uint DwmEnableComposition(uint compositionAction);
public Form1()
{
InitializeComponent();
}
int count = 1;
public static bool EnableComposition(bool enable)
{
try
{
if (enable)
{
DwmEnableComposition(DWM_EC_ENABLECOMPOSITION);
}
else
{
DwmEnableComposition(DWM_EC_DISABLECOMPOSITION);
}
return true;
}
catch
{
return false;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
Process[] procs = Process.GetProcesses();
foreach (Process proc in procs)
{
string chrome = "chrome";
string list;
list = proc.ProcessName;
if (list.Contains(chrome))
{
EnableComposition(false);
}
else if(!list.Contains(chrome))
{
EnableComposition(true);
}
}
}
}
Problem: If the program is open it runs both true and false in the if statement.
What have I do wrong?
Thanks In Advance.
Your
forloop is not correct. You are checking each process name one by one. So it depends on which process happens to come last. If “chrome” is in the middle of the process list, you will callEnableComposition(false)and on the next iteration through theforloop you will callEnableComposition(true).Something like this should work instead: