Set CalendarGadget width to X number of months
Posted: Sat Jan 21, 2006 6:16 am
Code updated for 5.20+
A search for "calendar width" and "calendargadget width" shows no results
for this tip, so here's what I do to neatly set the CalendarGadget width to X
number of months (takes system fonts into account, etc):
A search for "calendar width" and "calendargadget width" shows no results
for this tip, so here's what I do to neatly set the CalendarGadget width to X
number of months (takes system fonts into account, etc):
Code: Select all
; Set CalendarGadget width to X number of months.
; Note: Your code must include a Callback to check for a #WM_SETTINGCHANGE message,
; and if it occurs then you need to recalculate the width again to compensate.
#MCM_GETMINREQRECT=4105
If OpenWindow(0,200,200,0,0,"CalendarGadget",#PB_Window_SystemMenu)
calendar=CalendarGadget(0,0,0,0,0)
SendMessage_(calendar,#MCM_GETMINREQRECT,0,MyCalendar.RECT)
monthheight=(MyCalendar\Bottom-MyCalendar\Top)+GetSystemMetrics_(#SM_CYFRAME)
monthwidth=(MyCalendar\Right-MyCalendar\Left)+GetSystemMetrics_(#SM_CXEDGE)+GetSystemMetrics_(#SM_CXFRAME)
monthwidth*4-GetSystemMetrics_(#SM_CXEDGE) ; Convert calender width to desired number of months (4 in this example).
SetWindowPos_(calendar,0,0,0,monthwidth,monthheight,#SWP_NOMOVE) ; Set the new width for the number of months.
ResizeWindow(0, #PB_Ignore, #PB_Ignore, monthwidth,monthheight) ; And also do it for the window, just to make it look nice. :)
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf