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

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
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Import
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Private

        #region 메시지 보내기 - SendMessage(windowHandle, message, longParameter, wordParameter)

        /// <summary>
        /// 메시지 보내기
        /// </summary>
        /// <param name="windowHandle">윈도우 핸들</param>
        /// <param name="message">메시지</param>
        /// <param name="longParameter">LONG 매개 변수</param>
        /// <param name="wordParameter">WORD 매개 변수</param>
        /// <returns>처리 결과</returns>
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        private extern static IntPtr SendMessage(IntPtr windowHandle, int message, IntPtr longParameter, IntPtr wordParameter);

        #endregion
        #region 메시지 보내기 - SendMessage(windowHandle, message, longParameter, wordParameter)

        /// <summary>
        /// 메시지 보내기
        /// </summary>
        /// <param name="windowHandle">윈도우 핸들</param>
        /// <param name="message">메시지</param>
        /// <param name="longParameter">LONG 매개 변수</param>
        /// <param name="wordParameter">WORD 매개 변수</param>
        /// <returns>처리 결과</returns>
        [DllImport("User32.dll", CharSet=CharSet.Auto)]
        private extern static IntPtr SendMessage(IntPtr windowHandle, int message, int longParameter, int wordParameter);

        #endregion

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

        #region Field

        /// <summary>
        /// WM_LBUTTONDOWN
        /// </summary>
        private const int WM_LBUTTONDOWN = 513;

        /// <summary>
        /// WM_LBUTTONUP
        /// </summary>
        private const int WM_LBUTTONUP = 514;

        /// <summary>
        /// MK_LBUTTON
        /// </summary>
        private const int MK_LBUTTON = 0x0001;

        /// <summary>
        /// MK_RBUTTON
        /// </summary>
        private const int MK_RBUTTON = 0x0002;

        /// <summary>
        /// MK_SHIFT
        /// </summary>
        private const int MK_SHIFT = 0x0004;

        /// <summary>
        /// MK_CONTROL
        /// </summary>
        private const int MK_CONTROL = 0x0008;

        /// <summary>
        /// MK_MBUTTON
        /// </summary>
        private const int MK_MBUTTON = 0x0010;

        #endregion

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

        #region 생성자 - MainForm()

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

            this.showMessageButton.Click += showMessageButton_Click;
            this.clickButtonButton.Click += clickButtonButton_Click;
        }

        #endregion

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

        #region 메시지 표시하기 버튼 클릭시 처리하기 - showMessageButton_Click(sender, e)

        /// <summary>
        /// 메시지 표시하기 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void showMessageButton_Click(object sender, EventArgs e)
        {
            MessageBox.Show("메시지를 표시합니다.");
        }

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

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

        #endregion

        //////////////////////////////////////////////////////////////////////////////// Function

        #region LONG 매개 변수 구하기 - GetLongParameter(low, high)

        /// <summary>
        /// LONG 매개 변수 구하기
        /// </summary>
        /// <param name="low">하위 워드</param>
        /// <param name="high">상위 워드</param>
        /// <returns>LONG 매개 변수</returns>
        private int GetLongParameter(int low, int high)
        {
            return ((high << 16) | (low & 0xffff));
        }

        #endregion
        #region 컨트롤 클릭하기 - ClickControl(control)

        /// <summary>
        /// 컨트롤 클릭하기
        /// </summary>
        /// <param name="control">컨트롤</param>
        private void ClickControl(Control control)
        {
            int x             = 0;
            int y             = 0;
            int longParameter = GetLongParameter(x, y);

            SendMessage(control.Handle, WM_LBUTTONDOWN, longParameter, MK_LBUTTON);
            SendMessage(control.Handle, WM_LBUTTONUP  , longParameter, MK_LBUTTON);
        }

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

댓글을 달아 주세요