오늘 하루종일 삽질해서 어케든 끼워맞춘거..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Drawing;
namespace Ueco2010
{
enum WMMessage
{
RBtnWParam = 0x0002,
LButtonDown = 0x0201,
LButtonUp = 0x0202,
RButtonDown = 0x0204,
RButtonUp = 0x0205,
}
class MessageHooker : IMessageFilter
{
#region importExternDll Fuction
[DllImport("User32.dll")]
public static extern int PostMessage(uint hWnd, uint Msg, uint wParam, uint lParam);
[DllImport("User32.dll")]
public static extern bool GetCursorPos(ref Point lpPoint);
#endregion
#region Properties
private bool _bMessageHook = true; //메시지 후킹할 건가..
public bool bMessageHook
{
get
{
return _bMessageHook;
}
set
{
_bMessageHook = value;
}
}
private ocx컨트롤가진 클래스이름 _curApp = null;
public ocx컨트롤가진 클래스이름 curApp
{
set { _curApp = value; }
}
#endregion
#region Methods
public bool PreFilterMessage(ref Message m)
{
uint hWnd = 0;
if ((bMessageHook == true) && (m.Msg == (uint)WMMessage.LButtonDown) && (IsObjectHandle((uint)m.HWnd) == true))
{
//좌우를 바꾸어서 보내기
PostMessage((uint)m.HWnd, (uint)WMMessage.RButtonDown, (uint)WMMessage.RBtnWParam, (uint)m.LParam);
return true;
}
else if ((bMessageHook == true) && (m.Msg == (uint)WMMessage.LButtonUp) && (IsObjectHandle((uint)m.HWnd) == true))
{
//여기도 좌우 변경
PostMessage((uint)m.HWnd, (uint)WMMessage.RButtonUp, (uint)WMMessage.RBtnWParam, (uint)m.LParam);
return true;
}
return false;
}
private bool IsObjectHandle(uint hWnd)
{
//그리고 HItTest를 해주자. 과연 마우스 포인터가 정상적으로 안에 있는것인지.
Point curPos = new Point();
GetCursorPos(ref curPos); //screen좌표
Rectangle curMapView = ocx컨트롤.RectangleToScreen(ocx컨트롤.DisplayRectangle);
Point ltPt = curMapView.Location; //좌상단 구하기
//요기가 HitTest임..
if ((curPos.X > ltPt.X) && (curPos.X < (ltPt.X + curMapView.Width)) &&
(curPos.Y > ltPt.Y) && (curPos.Y < (ltPt.Y + curMapView.Height)))
{
return true; //안에 있다!
}
else
{
return false;
}
}
#endregion
}
}
댓글