In this case, I want to display the current month with today highlighted. As I was trying to get my head round writing this in a program using the qHTM.dll (to include HTML in an autohotkey GUI), the calendar will be in a HTML-autohotkey mixed code. Obviously just omit the HTML rubbish if you want to create a calendar using just autohotkey syntax.
Actually, the following code is an excerpt from my program which checks an online server (for IT Events during this month) and if it can't download the calendar, it had to display an offline version in the GUI. To display the following code in this website though, I've had to omit a lot of the HTML part.
This is the code in full; apologies for the mess coding but it's a mix between HTML and autohotkey syntax (note we're making a table with 9 columns and 6 rows - there's a spacing column on either side):
htmlText:=""
htmlText:=htmlText "<table>"
htmlText:=htmlText "<tr>"
htmlText:=htmlText " <td><img src='" A_ScriptDir "\images\s.gif' width='15' height='1' /></td>"
htmlText:=htmlText " <td><font color='#cccccc'>M</font></td>"
htmlText:=htmlText " <td><font color='#cccccc'>T</font></td>"
htmlText:=htmlText " <td><font color='#cccccc'>W</font></td>"
htmlText:=htmlText " <td><font color='#cccccc'>T</font></td>"
htmlText:=htmlText " <td><font color='#cccccc'>F</font></td>"
htmlText:=htmlText " <td><font color='#cccccc'>S</font></td>"
htmlText:=htmlText " <td><font color='#cccccc'>S</font></td>"
htmlText:=htmlText " <td><img src='" A_ScriptDir "\images\s.gif' width='10' height='1' /></td>"
htmlText:=htmlText "</tr>"
; GET NUMBER OF DAYS THIS MONTH
; Haven't found anyone who calculates how many days there are in a month so this is a crude solution
; This checks if this year is a leap year
Check1:=Mod(A_YYYY,4)
Check2:=Mod(A_YYYY,100)
Check3:=Mod(A_YYYY,400)
if (Check1=0) AND (((Check2=0)and(Check3=0)) OR (Check2<>0))
DaysInMonth=31,29,31,30,31,30,31,31,30,31,30,31
else
DaysInMonth=31,28,31,30,31,30,31,31,30,31,30,31
ThisMonthNum:=A_MM * 1 ; because we want 01 to equal 1
ThisDateNum:=A_DD * 1 ; because we want 01 to equal 1
StringSplit, DaysPerMonth, DaysInMonth, `,
DaysInThisMonth:=DaysPerMonth%ThisMonthNum%
; get the first day-of-week of this month
FormatTime, firstDayBlankNum, %A_YYYY%%A_MM%1, WDay
; add blank spaces in front of this first day
dateToDisplay:=1
If (firstDayBlankNum<3)
{
If (firstDayBlankNum=2) ; a day reference cannot be 0, and we're about subtract 2 from this
firstDayBlankNum:=7
If (firstDayBlankNum=1) ; a day reference cannot be less than 1, and we're about subtract 2 from this
firstDayBlankNum:=6
} else
firstDayBlankNum-=2 ; because my week starts with Monday
daysLeftOnFirstRow:=7-firstDayBlankNum
; write the first row
ThisMonth:=ThisMonth " <tr>"
ThisMonth:=ThisMonth " <td><img src='" A_ScriptDir "\images\s.gif' width='15' height='1' /></td>"
Loop, %firstDayBlankNum%
ThisMonth:=ThisMonth " <td><img src='" A_ScriptDir "\images\s.gif' width='15' height='1' /></td>"
Loop, %daysLeftOnFirstRow%
{
If (dateToDisplay=ThisDateNum)
ThisMonth:=ThisMonth " <td background='" A_ScriptDir "/images/program/bgs/calendar_today.png'><font color='#ffffff'><b>" dateToDisplay "</b></font></td></td>"
Else
ThisMonth:=ThisMonth " <td>" dateToDisplay "</td>"
dateToDisplay++
}
ThisMonth:=ThisMonth " <td><img src='" A_ScriptDir "\images\s.gif' width='15' height='1' /></td>"
ThisMonth:=ThisMonth " </tr>"
; write the remaining rows
Loop, 5
{
ThisMonth:=ThisMonth " <tr>"
ThisMonth:=ThisMonth " <td><img src='" A_ScriptDir "\images\s.gif' width='15' height='1' /></td>"
Loop, 7
{
If (dateToDisplay<=DaysInThisMonth)
{
If (dateToDisplay=ThisDateNum)
ThisMonth:=ThisMonth " <td background='" A_ScriptDir "/images/program/bgs/calendar_today.png'><font color='#ffffff'><b>" dateToDisplay "</b></font></td></td>"
Else
ThisMonth:=ThisMonth " <td>" dateToDisplay "</td>"
} Else
ThisMonth:=ThisMonth " <td><img src='" A_ScriptDir "\images\s.gif' width='15' height='1' /></td>"
dateToDisplay++
}
ThisMonth:=ThisMonth " <td><img src='" A_ScriptDir "\images\s.gif' width='15' height='1' /></td>"
ThisMonth:=ThisMonth " </tr>"
}
htmlText:=htmlText "</table>"
Easy-peasy hey???



Add comment