Set CalendarGadget width to X number of months

Share your advanced PureBasic knowledge/code with the community.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Set CalendarGadget width to X number of months

Post by PB »

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):

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 
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.