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

TestProject.zip
0.01MB

▶ ApplicationBarMessage.cs

namespace TestProject
{
    /// <summary>
    /// 애플리케이션 바 메시지
    /// </summary>
    public enum ApplicationBarMessage
    {
        /// <summary>
        /// New
        /// </summary>
        New = 0x00,

        /// <summary>
        /// Remove
        /// </summary>
        Remove = 0x01,

        /// <summary>
        /// QueryPosition
        /// </summary>
        QueryPosition = 0x02,

        /// <summary>
        /// SetPosition
        /// </summary>
        SetPosition = 0x03,

        /// <summary>
        /// GetState
        /// </summary>
        GetState = 0x04,

        /// <summary>
        /// GetTaskBarPosition
        /// </summary>
        GetTaskBarPosition = 0x05,

        /// <summary>
        /// Activate
        /// </summary>
        Activate = 0x06,

        /// <summary>
        /// GetAutoHideBar
        /// </summary>
        GetAutoHideBar = 0x07,

        /// <summary>
        /// SetAutoHideBar
        /// </summary>
        SetAutoHideBar = 0x08,

        /// <summary>
        /// WindowPositionChanged
        /// </summary>
        WindowPositionChanged = 0x09,

        /// <summary>
        /// SetState
        /// </summary>
        SetState = 0x0a
    }
}

 

728x90

 

▶ ApplicationBarData.cs

using System;
using System.Runtime.InteropServices;

namespace TestProject
{
    /// <summary>
    /// 애플리케이션 바 데이터
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct ApplicationBarData
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region Field

        /// <summary>
        /// 크기
        /// </summary>
        public uint Size;

        /// <summary>
        /// 윈도우 핸들
        /// </summary>
        public IntPtr WindowHandle;

        /// <summary>
        /// 콜백 메시지
        /// </summary>
        public uint CallbackMessage;

        /// <summary>
        /// 에지
        /// </summary>
        public uint Edge;

        /// <summary>
        /// 사각형
        /// </summary>
        public System.Drawing.Rectangle Rectangle;

        /// <summary>
        /// 매개 변수
        /// </summary>
        public int Parameter;

        #endregion
    }
}

 

300x250

 

▶ ApplicationBarState.cs

namespace TestProject
{
    /// <summary>
    /// 애플리케이션 바 상태
    /// </summary>
    public enum ApplicationBarState
    {
        /// <summary>
        /// 자동 숨기기
        /// </summary>
        AutoHide = 0x01,

        /// <summary>
        /// 항상 상위
        /// </summary>
        AlwaysOnTop = 0x02
    }
}

 

▶ WIN32Helper.cs

using System;
using System.Runtime.InteropServices;

namespace TestProject
{
    /// <summary>
    /// WIN32 헬퍼
    /// </summary>
    public static class WIN32Helper
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Import
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Private

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

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

        #endregion
        #region 애플리케이션 바 메시지 처리하기 - SHAppBarMessage(message, ApplicationBarData)

        /// <summary>
        /// 애플리케이션 바 메시지 처리하기
        /// </summary>
        /// <param name="message">메시지</param>
        /// <param name="data">데이터</param>
        /// <returns>처리 결과</returns>
        [DllImport("shell32.dll")]
        private static extern uint SHAppBarMessage(uint message, ref ApplicationBarData data);

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Public

        #region 태스크바 상태 설정하기 - SetTaskbarState(state)

        /// <summary>
        /// 태스크바 상태 설정하기
        /// </summary>
        /// <param name="state">애플리케이션 바 상태</param>
        public static void SetTaskbarState(ApplicationBarState state)
        {
            ApplicationBarData data = new ApplicationBarData();

            data.Size         = (uint)Marshal.SizeOf(data);
            data.WindowHandle = FindWindow("System_TrayWnd", null);
            data.Parameter    = (int)(state);

            SHAppBarMessage((uint)ApplicationBarMessage.SetState, ref data);
        }

        #endregion
        #region 태스크바 상태 구하기 - GetTaskbarState()

        /// <summary>
        /// 태스크바 상태 구하기
        /// </summary>
        /// <returns>태스크바 상태</returns>
        public static ApplicationBarState GetTaskbarState()
        {
            ApplicationBarData data = new ApplicationBarData();

            data.Size         = (uint)Marshal.SizeOf(data);
            data.WindowHandle = FindWindow("System_TrayWnd", null);

            return (ApplicationBarState)SHAppBarMessage((uint)ApplicationBarMessage.GetState, ref data);
        }

        #endregion
    }
}

 

▶ MainWindow.xaml

<Window x:Class="TestProject.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="800"
    Height="600"
    Title="태스크바 숨기기/표시하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid>
        <Button Name="hideTaskbarButton"
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            Width="150"
            Height="30"
            Content="태스크바 숨기기" />
    </Grid>
</Window>

 

▶ MainWindow.xaml.cs

using System.Windows;

namespace TestProject
{
    /// <summary>
    /// 메인 윈도우
    /// </summary>
    public partial class MainWindow : Window
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 태스크바 숨기기 여부
        /// </summary>
        private bool hideTaskbar = false;

        #endregion

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

        #region 생성자 - MainWindow()

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

            this.hideTaskbarButton.Click += hideTaskbarButton_Click;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 태스크바 숨기기 버튼 클릭시 처리하기 - hideTaskbarButton_Click(sender, e)

        /// <summary>
        /// 태스크바 숨기기 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void hideTaskbarButton_Click(object sender, RoutedEventArgs e)
        {
            if(this.hideTaskbar)
            {
                this.hideTaskbar = false;

                this.hideTaskbarButton.Content = "태스크바 숨기기";

                WIN32Helper.SetTaskbarState(ApplicationBarState.AlwaysOnTop);
            }
            else
            {
                this.hideTaskbar = true;

                this.hideTaskbarButton.Content = "태스크바 표시하기";

                WIN32Helper.SetTaskbarState(ApplicationBarState.AutoHide);
            }
        }

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

댓글을 달아 주세요