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

728x90
반응형
728x170

TestProject.zip
다운로드

▶ MainForm.cs

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

namespace TestProject
{
    /// <summary>
    /// 메인 폼
    /// </summary>
    public partial class MainForm : Form
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Enumeration
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 윈도우 위치 설정 플래그 - SetWindowPosFlag

        /// <summary>
        /// 윈도우 위치 설정 플래그
        /// </summary>
        [Flags]
        private enum SetWindowPosFlag : uint
        {
            /// <summary>
            /// SWP_ASYNCWINDOWPOS
            /// </summary>
            SWP_ASYNCWINDOWPOS = 0x4000,

            /// <summary>
            /// SWP_DEFERERASE
            /// </summary>
            SWP_DEFERERASE = 0x2000,

            /// <summary>
            /// SWP_DRAWFRAME
            /// </summary>
            SWP_DRAWFRAME = 0x0020,

            /// <summary>
            /// SWP_FRAMECHANGED
            /// </summary>
            SWP_FRAMECHANGED = 0x0020,

            /// <summary>
            /// SWP_HIDEWINDOW
            /// </summary>
            SWP_HIDEWINDOW = 0x0080,

            /// <summary>
            /// SWP_NOACTIVATE
            /// </summary>
            SWP_NOACTIVATE = 0x0010,

            /// <summary>
            /// SWP_NOCOPYBITS
            /// </summary>
            SWP_NOCOPYBITS = 0x0100,

            /// <summary>
            /// SWP_NOMOVE
            /// </summary>
            SWP_NOMOVE = 0x0002,

            /// <summary>
            /// SWP_NOOWNERZORDER
            /// </summary>
            SWP_NOOWNERZORDER = 0x0200,

            /// <summary>
            /// SWP_NOREDRAW
            /// </summary>
            SWP_NOREDRAW = 0x0008,

            /// <summary>
            /// SWP_NOREPOSITION
            /// </summary>
            SWP_NOREPOSITION = 0x0200,

            /// <summary>
            /// SWP_NOSENDCHANGING
            /// </summary>
            SWP_NOSENDCHANGING = 0x0400,

            /// <summary>
            /// SWP_NOSIZE
            /// </summary>
            SWP_NOSIZE = 0x0001,

            /// <summary>
            /// SWP_NOZORDER
            /// </summary>
            SWP_NOZORDER = 0x0004,

            /// <summary>
            /// SWP_SHOWWINDOW
            /// </summary>
            SWP_SHOWWINDOW = 0x0040,
        }

        #endregion
        #region 윈도우 구하기 명령 - GetWindowCmd

        /// <summary>
        /// 윈도우 구하기 명령
        /// </summary>
        private enum GetWindowCmd : uint
        {
            /// <summary>
            /// GW_HWNDFIRST
            /// </summary>
            GW_HWNDFIRST = 0,

            /// <summary>
            /// GW_HWNDLAST
            /// </summary>
            GW_HWNDLAST = 1,

            /// <summary>
            /// GW_HWNDNEXT
            /// </summary>
            GW_HWNDNEXT = 2,

            /// <summary>
            /// GW_HWNDPREV
            /// </summary>
            GW_HWNDPREV = 3,

            /// <summary>
            /// GW_OWNER
            /// </summary>
            GW_OWNER = 4,

            /// <summary>
            /// GW_CHILD
            /// </summary>
            GW_CHILD = 5,

            /// <summary>
            /// GW_ENABLEDPOPUP
            /// </summary>
            GW_ENABLEDPOPUP = 6
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Import
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Private

        #region 윈도우 위치 설정하기 - SetWindowPos(windowHandle, windowHandleInsertAfter, x, y, width, height, flag)

        /// <summary>
        /// 윈도우 위치 설정하기
        /// </summary>
        /// <param name="windowHandle">윈도우 핸들</param>
        /// <param name="windowHandleInsertAfter">삽입 이후 윈도우 핸들</param>
        /// <param name="x">X 좌표</param>
        /// <param name="y">Y 좌표</param>
        /// <param name="width">너비</param>
        /// <param name="height">높이</param>
        /// <param name="flag">플래그</param>
        /// <returns>처리 결과</returns>
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool SetWindowPos(IntPtr windowHandle, IntPtr windowHandleInsertAfter, int x, int y, int width, int height, SetWindowPosFlag flag);

        #endregion
        #region 윈도우 찾기 - FindWindow(className, windowName)

        /// <summary>
        /// 윈도우 찾기
        /// </summary>
        /// <param name="className">클래스명</param>
        /// <param name="windowName">윈도우명</param>
        /// <returns>윈도우 핸들</returns>
        [DllImport("user32", EntryPoint = "FindWindowA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
        private static extern IntPtr FindWindow(string className, string windowName);

        #endregion
        #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, IntPtr className, string windowText);

        #endregion
        #region 윈도우 구하기 - GetWindow(windowHandle, cmd)

        /// <summary>
        /// 윈도우 구하기
        /// </summary>
        /// <param name="windowHandle">윈도우 핸들</param>
        /// <param name="cmd">명령</param>
        /// <returns>윈도우 핸들</returns>
        [DllImport("user32.dll", SetLastError = true)]
        private static extern IntPtr GetWindow(IntPtr windowHandle, GetWindowCmd cmd);

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 태스크바 윈도우 핸들
        /// </summary>
        private IntPtr taskbarWindowHandle;
        
        /// <summary>
        /// 시작 버튼 윈도우 핸들
        /// </summary>
        private IntPtr startButtonWindowHandle;

        #endregion

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

        #region 생성자 - MainForm()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            #region 이벤트를 설정한다.

            Load                   += Form_Load;
            FormClosing            += Form_FormClosing;
            this.closeButton.Click += closeButton_Click;

            #endregion
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private
        //////////////////////////////////////////////////////////////////////////////// Event

        #region 폼 로드시 처리하기 - Form_Load(sender, e)

        /// <summary>
        /// 폼 로드시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Form_Load(object sender, EventArgs e)
        {
            this.taskbarWindowHandle    = FindWindow("Shell_traywnd", "");
            this.startButtonWindowHandle = FindWindowEx(IntPtr.Zero, IntPtr.Zero, (IntPtr)0xC017, null);

            SetWindowPos(this.taskbarWindowHandle    , IntPtr.Zero, 0, 0, 0, 0, SetWindowPosFlag.SWP_HIDEWINDOW);
            SetWindowPos(this.startButtonWindowHandle, IntPtr.Zero, 0, 0, 0, 0, SetWindowPosFlag.SWP_HIDEWINDOW);

            Bounds = Screen.PrimaryScreen.Bounds;
        }

        #endregion
        #region 폼을 닫을 경우 처리하기 - Form_FormClosing(sender, e)

        /// <summary>
        /// 폼을 닫을 경우 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이베늩 인자</param>
        private void Form_FormClosing(object sender, FormClosingEventArgs e)
        {
            SetWindowPos(this.taskbarWindowHandle    , IntPtr.Zero, 0, 0, 0, 0, SetWindowPosFlag.SWP_SHOWWINDOW);
            SetWindowPos(this.startButtonWindowHandle, IntPtr.Zero, 0, 0, 0, 0, SetWindowPosFlag.SWP_SHOWWINDOW);
        }

        #endregion
        #region 종료 버튼 클릭시 처리하기 - closeButton_Click(sender, e)

        /// <summary>
        /// 종료 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void closeButton_Click(object sender, EventArgs e)
        {
            Close();
        }

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

댓글을 달아 주세요