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

■ IWin32Window 인터페이스를 사용해 메시지 박스를 최상위로 표시하는 방법을 보여준다.

TestProject.zip
0.00MB

▶ WIN32Window.cs

using System;
using System.Windows.Forms;

namespace TestProject
{
    /// <summary>
    /// WIN32 윈도우
    /// </summary>
    public class WIN32Window : IWin32Window
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 윈도우 핸들
        /// </summary>
        private IntPtr windowHandle;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 윈도우 핸들 - Handle

        /// <summary>
        /// 윈도우 핸들
        /// </summary>
        public IntPtr Handle
        {
            get
            {
                return this.windowHandle;
            }
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - WIN32Window(windowHandle)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="windowHandle">윈도우 핸들</param>
        public WIN32Window(IntPtr windowHandle)
        {
            this.windowHandle = windowHandle;
        }

        #endregion
    }
}

 

▶ Program.cs

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

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

        #region 전경 윈도우 구하기 - GetForegroundWindow()

        /// <summary>
        /// 전경 윈도우 구하기
        /// </summary>
        /// <returns>윈도우 핸들</returns>
        [DllImport("user32")]
        private static extern IntPtr GetForegroundWindow();

        #endregion

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

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

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

            WIN32Window window = new WIN32Window(windowHandle);

            MessageBox.Show(window, "작업을 진행하시겠습니까?", "확인", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
        }

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