Jump to content


Photo

[SAMPLE] Display bold days in a MonthCal (AHK_L)


  • Please log in to reply
1 reply to this topic

#1 just me

just me
  • Members
  • 1173 posts

Posted 03 September 2011 - 06:06 AM

This sample demonstrates the use of MCM_SETDAYSTATE message, MCN_GETDAYSTATE notification, and MCS_DAYSTATE style which force MonthCal controls to display certain days in bold. Because a MonthCal always shows (parts of) three months at least, you have to pass an array containing at least three MONTHDAYSTATE fields, in chronological order. For controls showing more than one month, add two to the number of months shown.

The sample needs Const_MonthCal.ahk and Class_On_WM_NOTIFY.ahk and here it comes:

#include Const_MonthCal.ahk
#include Class_On_WM_NOTIFY.ahk
; #include Class_DllStruct.ahk
; ----------------------------------------------------------------------------------------------------------------------
Dates := "2011-09-12;2011-10-05;2011-11-22"
DateObj := []
Loop, Parse, Dates, `; 
{
   StringSplit, D, A_LoopField, -
   If (D0 = 3) {
      YM := D1 . SubStr("0" . D2, -1)
      If !DateObj.Haskey(YM)
         DateObj[YM] := []
      DateObj[YM].Insert(D3, "")
   }
}
; ----------------------------------------------------------------------------------------------------------------------
Gui, Margin, 20, 20
; If you set the MCS_DAYSTATE style you must handle MCN_GETDAYSTATE notifications, otherwise the result will be odd
Gui, Add, MonthCal, hwndHMC vMC +%MCS_DAYSTATE%
On_WM_NOTIFY.Attach(HMC, MCN_GETDAYSTATE, "On_MCN_GETDAYSTATE")
Y := A_YYYY
M := A_MM
M -= 1
If (M < 1)
   Y -= 1, M := 12
; MCM_SETDAYSTATE -> http://msdn.microsoft.com/en-us/library/bb761004%28v=VS.85%29.aspx
SendMessage, MCM_SETDAYSTATE, 3, CreateMonthDayState(Y, M, 3), , ahk_id %HMC%
Gui, Show, , MonthCal
Return
; ======================================================================================================================
GuiClose:
ExitApp
; ======================================================================================================================
On_MCN_GETDAYSTATE(Hwnd, Message, wParam, lParam) {
   ; MCN_GETDAYSTATE -> http://msdn.microsoft.com/en-us/library/bb760935%28v=VS.85%29.aspx
   ; NMDAYSTATE -> http://msdn.microsoft.com/en-us/library/bb760929%28v=VS.85%29.aspx
   Static wYear := (A_PtrSize * 2) + 4
   Static wMonth := wYear + 2
   Static cDayState := wMonth + 14
   Static prgDayState := cDayState + 4
   Static DAYSTATE := 0
   Y := NumGet(lParam + 0, wYear, "Short")
   M := NumGet(lParam + 0, wMonth, "Short")
   I := NumGet(lParam + 0, cDayState, "Int")
   NumPut(CreateMonthDayState(Y, M, I), lParam + 0, prgDayState, "Ptr")
}
; ======================================================================================================================
CreateMonthDayState(Y, M, I) {
   ; MONTHDAYSTATE -> http://msdn.microsoft.com/en-us/library/bb760915%28v=VS.85%29.aspx
   Global DateObj
   Static MONTHDAYSTATE := 0
   VarSetCapacity(MONTHDAYSTATE, 4 * I, 0)
   Loop, % I {
      YM := Y . SubStr("0" . M, -1)
      DAYSTATE := 0
      If DateObj.HasKey(YM)
         For D In DateObj[YM] {
            If (D < 0) || (D > 31)
               Break
            DAYSTATE |= 0x1 << (D - 1)
         }
      NumPut(DAYSTATE, MONTHDAYSTATE, 4 * (A_Index - 1), "UInt")
      M += 1
      If (M > 12)
         Y += 1, M := 1
   }
   Return &MONTHDAYSTATE
}


#2 just me

just me
  • Members
  • 1173 posts

Posted 23 April 2012 - 08:50 AM

@Mods: Move this into the "Custom" section, please.