티스토리 뷰

IT/C#

[CS][dwmapi.dll] DWM 활성화 상태 확인하기 - DwmIsCompositionEnabled

주인장 진빼이

함수 설명

DwmIsCompositionEnabled 함수는 DWM이 활성화 되어 있는지 체크하는 함수이다. (MSDN)
Windows 8이후로 DWM(Desktop Window Manager)은 항상 활성화 된다.

DWM이 활성화된 경우 true를 반환하고 비활성화된 경우 false를 반환한다.
윈도우즈 설정에서 고대비 모드가 켜져 있는 경우 언제나 false를 반환한다.

반환값은 함수의 반환값이 아닌 매개변수를 out으로 넘겨주어 받는다.

테스트케이스

0.1초마다 DWM이 활성화되어 있는지 체크 후

  • 활성화: 변수값에 1씩 더한 뒤, Enable 텍스트 출력
  • 비활성화: 변수값을 0으로 초기화 한뒤, Disable 텍스트 출력

결과

작업 관리자로 DWM.exe를 강제로 종료하는 경우 운영체제에 의해 빠르게 복구되지만
0.1초마다 체크하는 경우 DWM 종료를 확인하여 변수 값을 0으로 초기화 한뒤,
DWM.exe 프로세스가 다시 복구 된 이후부터 1씩 더하고 있다.

코드

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DwmIsCompositionEnabledTest
{
    public partial class Form1 : Form
    {
        [DllImport("dwmapi.dll")]
        private static extern int DwmIsCompositionEnabled(out bool enabled);

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.ShowIcon = false;
            timer1.Start();
        }
        private int i = 0;
        private void timer1_Tick(object sender, EventArgs e)
        {
            bool result = false;
            DwmIsCompositionEnabled(out result);
            label2.Text = (result == true) ? "Enable " + i++ : "Disable " + (i=0);
        }
    }
}

댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함