첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
본 블로그는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 블로그 콘텐츠 향상을 위해 쓰여집니다.

728x90
반응형
728x170

TestProject.zip
0.01MB

▶ DWMWINDOWATTRIBUTE.cs

namespace TestProject
{
    /// <summary>
    /// DWM 윈도우 어트리뷰트
    /// </summary>
    public enum DWMWINDOWATTRIBUTE : uint
    {
        /// <summary>
        /// NCRenderingEnabled
        /// </summary>
        NCRenderingEnabled = 1,

        /// <summary>
        /// NCRenderingPolicy
        /// </summary>
        NCRenderingPolicy,

        /// <summary>
        /// TransitionsForceDisabled
        /// </summary>
        TransitionsForceDisabled,

        /// <summary>
        /// AllowNCPaint
        /// </summary>
        AllowNCPaint,

        /// <summary>
        /// CaptionButtonBounds
        /// </summary>
        CaptionButtonBounds,

        /// <summary>
        /// NonClientRtlLayout
        /// </summary>
        NonClientRtlLayout,

        /// <summary>
        /// ForceIconicRepresentation
        /// </summary>
        ForceIconicRepresentation,

        /// <summary>
        /// Flip3DPolicy
        /// </summary>
        Flip3DPolicy,

        /// <summary>
        /// ExtendedFrameBounds
        /// </summary>
        ExtendedFrameBounds,

        /// <summary>
        /// HasIconicBitmap
        /// </summary>
        HasIconicBitmap,

        /// <summary>
        /// DisallowPeek
        /// </summary>
        DisallowPeek,

        /// <summary>
        /// ExcludedFromPeek
        /// </summary>
        ExcludedFromPeek,

        /// <summary>
        /// Cloak
        /// </summary>
        Cloak,

        /// <summary>
        /// Cloaked
        /// </summary>
        Cloaked,

        /// <summary>
        /// FreezeRepresentation
        /// </summary>
        FreezeRepresentation
    }
}

 

▶ WindowInformation.cs

using System;

namespace TestProject
{
    /// <summary>
    /// 윈도우 정보
    /// </summary>
    public class WindowInformation
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 윈도우 핸들 - WindowHandle

        /// <summary>
        /// 윈도우 핸들
        /// </summary>
        public IntPtr WindowHandle { get; set; }

        #endregion
        #region 윈도우 텍스트 - WindowText

        /// <summary>
        /// 윈도우 텍스트
        /// </summary>
        public string WindowText { get; set; }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 문자열 구하기 - ToString()

        /// <summary>
        /// 문자열 구하기
        /// </summary>
        /// <returns>문자열</returns>
        public override string ToString()
        {
            return $"WINDOW HANDLE={WindowHandle}, WINDOW TEXT={WindowText}";
        }

        #endregion
    }
}

 

▶ Program.cs

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;

namespace TestProject
{
    /// <summary>
    /// 프로그램
    /// </summary>
    class Program
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Import
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Private

        #region 윈도우 찾기 (확장) - FindWindowEx(parentWindowHandle, childAfterWindowHandle, className, windowText)

        /// <summary>
        /// 윈도우 찾기 (확장)
        /// </summary>
        /// <param name="parentWindowHandle">부모 윈도우 핸들</param>
        /// <param name="childAfterWindowHandle">찾기 이후 자식 윈도우 핸들</param>
        /// <param name="className">클래스명</param>
        /// <param name="windowText">윈도우 텍스트</param>
        /// <returns>윈도우 핸들</returns>
        [DllImport("user32.dll")]
        private static extern IntPtr FindWindowEx(IntPtr parentWindowHandle, IntPtr childAfterWindowHandle, string className, string windowText);

        #endregion
        #region 윈도우 스레드 프로세스 ID 구하기 - GetWindowThreadProcessId(windowHandle, processID)

        /// <summary>
        /// 윈도우 스레드 프로세스 ID 구하기
        /// </summary>
        /// <param name="windowHandle">윈도우 핸들</param>
        /// <param name="processID">프로세스 ID</param>
        /// <returns>스레드 ID</returns>
        [DllImport("user32")]
        private static extern uint GetWindowThreadProcessId(IntPtr windowHandle, out int processID);

        #endregion
        #region UWP 프로세스 여부 구하기 - IsImmersiveProcess(processHandle)

        /// <summary>
        /// UWP 프로세스 여부 구하기
        /// </summary>
        /// <param name="processHandle">프로세스 핸들</param>
        /// <returns>UWP 프로세스 여부</returns>
        [DllImport("user32")]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool IsImmersiveProcess(IntPtr processHandle);

        #endregion
        #region 윈도우 텍스트 구하기 - GetWindowText(windowHandle, stringBuilder, maximumCount)

        /// <summary>
        /// 윈도우 텍스트 구하기
        /// </summary>
        /// <param name="windowHandle">윈도우 핸들</param>
        /// <param name="stringBuilder">문자열 빌더</param>
        /// <param name="maximumCount">최대 카운트</param>
        /// <returns>윈도우 텍스트</returns>
        [DllImport("user32.dll")]
        private static extern int GetWindowText(IntPtr windowHandle, StringBuilder stringBuilder, int maximumCount);

        #endregion
        #region 윈도우 표시 여부 구하기 - IsWindowVisible(windowHandle)

        /// <summary>
        /// 윈도우 표시 여부 구하기
        /// </summary>
        /// <param name="windowHandle">윈도우 핸들</param>
        /// <returns>윈도우 표시 여부</returns>
        [DllImport("user32.dll")]
        private static extern bool IsWindowVisible(IntPtr windowHandle);

        #endregion
        #region 윈도우 최소화 여부 구하기 - IsIconic(windowHandle)

        /// <summary>
        /// 윈도우 최소화 여부 구하기
        /// </summary>
        /// <param name="windowHandle">윈도우 핸들</param>
        /// <returns>윈도우 최소화 여부</returns>
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool IsIconic(IntPtr windowHandle);

        #endregion
        #region DWM 윈도우 어트리뷰트 구하기 - DwmGetWindowAttribute(windowHandle, attribute, value, valueSize)

        /// <summary>
        /// DWM 윈도우 어트리뷰트 구하기
        /// </summary>
        /// <param name="windowHandle">윈도우 핸들</param>
        /// <param name="attribute">어트리뷰트</param>
        /// <param name="value">값</param>
        /// <param name="valueSize">값 크기</param>
        /// <returns>처리 결과</returns>
        [DllImport("dwmapi.dll")]
        private static extern int DwmGetWindowAttribute(IntPtr windowHandle, DWMWINDOWATTRIBUTE attribute, out bool value, int valueSize);

        #endregion
        #region 윈도우 표시하기 - ShowWindow(windowHandle, command)

        /// <summary>
        /// 윈도우 표시하기
        /// </summary>
        /// <param name="windowHandle">윈도우 핸들</param>
        /// <param name="command">명령</param>
        /// <returns>처리 결과</returns>
        [DllImport("user32.dll")]
        private static extern bool ShowWindow(IntPtr windowHandle, int command);

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Private

        #region 프로그램 시작하기 - Main()

        /// <summary>
        /// 프로그램 시작하기
        /// </summary>
        private static void Main()
        {
            while(true)
            {
                List<WindowInformation> infoList = GetUWPWindowInformationList();

                foreach(WindowInformation windowInformation in infoList)
                {
                    Console.WriteLine(windowInformation);

                    ShowWindow(windowInformation.WindowHandle, 6); // SW_MINIMIZE
                }

                Console.WriteLine("UWP APP WINDOWS MINIMIZED.");

                Thread.Sleep(3000);

                foreach(WindowInformation info in infoList)
                {
                    Console.WriteLine(info);

                    ShowWindow(info.WindowHandle, 9); // SW_RESTORE
                }

                Console.WriteLine("UWP APP WINDOWS RESOTRED.");

                Thread.Sleep(3000);
            }
        }

        #endregion

        #region UWP 윈도우 정보 리스트 구하기 - GetUWPWindowInformationList()

        /// <summary>
        /// UWP 윈도우 정보 리스트 구하기
        /// </summary>
        /// <returns>UWP 윈도우 정보 리스트</returns>
        private static List<WindowInformation> GetUWPWindowInformationList()
        {
            List<WindowInformation> list = new List<WindowInformation>();

            IntPtr        windowHandle            = IntPtr.Zero;
            StringBuilder windowTextStringBuilder = new StringBuilder(1024);
            string        windowText;
            bool          windowVisible;
            bool          isIconic;

            do
            {
                windowHandle = FindWindowEx(IntPtr.Zero, windowHandle, "ApplicationFrameWindow", null);

                if(windowHandle == IntPtr.Zero)
                {
                    break;
                }

                GetWindowText(windowHandle, windowTextStringBuilder, 1024);

                windowText = windowTextStringBuilder.ToString();

                if(string.IsNullOrEmpty(windowText))
                {
                    continue;
                }

                windowVisible = IsWindowVisible(windowHandle);

                if(!windowVisible)
                {
                    continue;
                }

                isIconic = IsIconic(windowHandle);

                if(isIconic)
                {
                    continue;
                }

                DwmGetWindowAttribute(windowHandle, DWMWINDOWATTRIBUTE.Cloaked, out bool isCloacked, Marshal.SizeOf(typeof(bool)));

                if(isCloacked)
                {
                    Console.WriteLine($"CLOAKED : {windowHandle}, {windowText}");

                    continue;
                }

                WindowInformation info = new WindowInformation()
                {
                    WindowHandle = windowHandle,
                    WindowText   = windowText
                };

                list.Add(info);
            }
            while(true);

            return list;
        }

        #endregion
    }
}
728x90
반응형
그리드형
Posted by 사용자 icodebroker
TAG , ,

댓글을 달아 주세요