Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7516901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:16:50+00:00 2026-05-30T01:16:50+00:00

Hi I am trying to fix that when I open a speific program aero

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T01:16:52+00:00Added an answer on May 30, 2026 at 1:16 am

    Your for loop 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 call EnableComposition(false) and on the next iteration through the for loop you will call EnableComposition(true).

    Something like this should work instead:

        bool processFound = false;
        foreach (Process proc in procs)
        {
            if (proc.ProcessName.Contains("chrome"))
            {
                processFound = true;
            }
        }
    
        if (processFound)
        {
            EnableComposition(false);
        }
        else
        {
            EnableComposition(true);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to fix a project that someone else coded, it is a
I am trying to fix an ASP.NET site that a friend had botched converting
I've been trying to fix this for two hours straight and I can't figure
I'm trying to open an URI with Swing that I get above error. What
I'm trying to fix a .hta that someone at my company created 3 or
I have been trying to update a text field in a form that will
Newb here trying to fix my php code. Getting an error at line 89.
I have been trying to fix the following problem for weeks :(. In my
I am trying to write a program in Python that will loop to keep
I am trying to compile some C++ code that uses threads: #include <iostream> #include

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.