void MonthCal_HitTest(
hmc,
pinfousing System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
internal class CurrentMonthCalendar : MonthCalendar
{
public CurrentMonthCalendar() {
var today = DateTime.Today;
MinDate = new DateTime(today.Year, today.Month, 1);
MaxDate = new DateTime(today.Year, today.Month,
DateTime.DaysInMonth(today.Year, today.Month));
}
protected override void WndProc(ref Message m) {
switch (m.Msg) {
case WM_LBUTTONDOWN:
if (!IsDisableMouse(ref m)) {
base.WndProc(ref m);
}
break;
default:
base.WndProc(ref m);
break;
}
}
private bool IsDisableMouse(ref Message m) {
var mci = new MCHITTESTINFO();
mci.pt_x = SignedLOWORD(m.LParam);
mci.pt_y = SignedHIWORD(m.LParam);
var result = (int)SendMessage(Handle, MCM_HITTEST, 0, mci);
switch (result) {
case MCHT_TITLE:
return true;
}
return false;
}
const int WM_LBUTTONDOWN = 0x0201;
const int MCM_FIRST = 0x1000;
const int MCM_HITTEST = MCM_FIRST + 14;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
class MCHITTESTINFO
{
public int cbSize = Marshal.SizeOf(typeof(MCHITTESTINFO));
public int pt_x = 0;
public int pt_y = 0;
public int uHit = 0;
public short st_wYear = 0;
public short st_wMonth = 0;
public short st_wDayOfWeek = 0;
public short st_wDay = 0;
public short st_wHour = 0;
public short st_wMinute = 0;
public short st_wSecond = 0;
public short st_wMilliseconds = 0;
}
private const int
MCHT_TITLE = 0x00010000,
MCHT_CALENDAR = 0x00020000,
MCHT_TODAYLINK = 0x00030000,
MCHT_TITLEBK = (0x00010000),
MCHT_TITLEMONTH = (0x00010000 | 0x0001),
MCHT_TITLEYEAR = (0x00010000 | 0x0002),
MCHT_TITLEBTNNEXT = (0x00010000 | 0x01000000 | 0x0003),
MCHT_TITLEBTNPREV = (0x00010000 | 0x02000000 | 0x0003),
MCHT_CALENDARBK = (0x00020000),
MCHT_CALENDARDATE = (0x00020000 | 0x0001),
MCHT_CALENDARDATENEXT = ((0x00020000 | 0x0001) | 0x01000000),
MCHT_CALENDARDATEPREV = ((0x00020000 | 0x0001) | 0x02000000),
MCHT_CALENDARDAY = (0x00020000 | 0x0002),
MCHT_CALENDARWEEKNUM = (0x00020000 | 0x0003);
[DllImport("User32", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(
IntPtr hWnd, int msg, int wParam, MCHITTESTINFO lParam);
private static int SignedHIWORD(IntPtr n) {
return SignedHIWORD(unchecked((int)(long)n));
}
private static int SignedLOWORD(IntPtr n) {
return SignedLOWORD(unchecked((int)(long)n));
}
private static int SignedHIWORD(int n) {
int i = (short)((n >> 16) & 0xffff);
return i;
}
private static int SignedLOWORD(int n) {
int i = (short)(n & 0xFFFF);
return i;
}
}
);