첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.00MB

▶ Program.cs

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;

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 IntPtr 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

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

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

        /// <summary>
        /// 프로그램 시작하기
        /// </summary>
        private static void Main()
        {
            IntPtr  windowHandle = IntPtr.Zero;

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

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

                IntPtr processID;

                GetWindowThreadProcessId(windowHandle, out processID);

                Process process = Process.GetProcessById((int)processID);

                try
                {
                    if(!IsImmersiveProcess(process.Handle))
                    {
                        continue;
                    }
                }
                catch
                {
                    continue;
                }

                StringBuilder windowTextStringBuilder = new StringBuilder(1024);

                GetWindowText(windowHandle, windowTextStringBuilder, 1024);

                string windowText = windowTextStringBuilder.ToString();

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

                bool windowVisible = IsWindowVisible(windowHandle);

                bool isIconic = IsIconic(windowHandle);

                Console.WriteLine($"{process.ProcessName}:{process.Id}:{windowHandle}:{windowTextStringBuilder.ToString()}:{windowVisible}:{isIconic}");
            }
            while(true);
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요