Page 1 of 1

Calendar back/forward buttons

Posted: Mon Feb 20, 2006 2:03 pm
by Phoenix
Is there a way to know if the user clicks the back/forward buttons in the CalendarGadget to go back/forward a month?

Posted: Mon Feb 20, 2006 4:48 pm
by localmotion34
http://msdn.microsoft.com/library/defau ... ittest.asp
http://msdn.microsoft.com/library/defau ... stinfo.asp
http://msdn.microsoft.com/library/defau ... ittest.asp
Members

cbSize
Size of this structure, in bytes.
pt
POINT structure that contains information about the point to be hit-tested.
uHit
Output member that receives a bit flag representing the result of the hit-test operation. This value will be one of the following:

MCHT_CALENDARBK
The given point was in the calendar's background.
MCHT_CALENDARDATE
The given point was on a particular date within the calendar. The SYSTEMTIME structure at lpMCHitTest>st is set to the date at the given point.
MCHT_CALENDARDATENEXT
The given point was over a date from the next month (partially displayed at the end of the currently displayed month). If the user clicks here, the month calendar will scroll its display to the next month or set of months.
MCHT_CALENDARDATEPREV
The given point was over a date from the previous month (partially displayed at the end of the currently displayed month). If the user clicks here, the month calendar will scroll its display to the previous month or set of months.
MCHT_CALENDARDAY
The given point was over a day abbreviation ("Fri", for example). The SYSTEMTIME structure at lpMCHitTest>st is set to the corresponding date in the top row.
MCHT_CALENDARWEEKNUM
The given point was over a week number (MCS_WEEKNUMBERS style only). The SYSTEMTIME structure at lpMCHitTest>st is set to the corresponding date in the leftmost column.
MCHT_NOWHERE
The given point was not on the month calendar control, or it was in an inactive portion of the control.
MCHT_TITLEBK
The given point was over the background of a month's title.
MCHT_TITLEBTNNEXT
The given point was over the button at the top right corner of the control. If the user clicks here, the month calendar will scroll its display to the next month or set of months.

MCHT_TITLEBTNPREV
The given point was over the button at the top left corner of the control. If the user clicks here, the month calendar will scroll its display to the previous month or set of months.

MCHT_TITLEMONTH
The given point was in a month's title bar, over a month name.
MCHT_TITLEYEAR
The given point was in a month's title bar, over the year value.

st
SYSTEMTIME structure that receives date and time information specific to the location that was hit-tested.

what you have to do is look for a left click, send the hit test message with the point you get from where the mouse is.

Posted: Mon Feb 20, 2006 11:26 pm
by Fred
You can may be compare the date returned by GetGadgetState() and see if the month has changed ?

Posted: Tue Feb 21, 2006 3:06 pm
by Trond
That would catch it the user changes month using the light grey dates and he asked for button press.

Posted: Tue Feb 21, 2006 4:17 pm
by Sparkie
Here is some PB4 Beta3 code...

Code: Select all

#MCHT_TITLE = $10000
#MCHT_NEXT = $1000000
#MCHT_PREV = $2000000
#MCHT_TITLEBTNPREV = #MCHT_TITLE | #MCHT_PREV | 3
#MCHT_TITLEBTNNEXT = #MCHT_TITLE | #MCHT_NEXT | 3
#MCM_HITTEST = #MCM_FIRST + 14

Structure _MCHITTESTINFO
  cbSize.l
  pt.POINT
  uHIt.l
  st.SYSTEMTIME
EndStructure

mcht._MCHITTESTINFO\cbSize = SizeOf(_MCHITTESTINFO)

If OpenWindow(0, 0, 0, 300, 300, #PB_Window_SystemMenu | #PB_Window_ScreenCentered,"CalendarGadget Hit Test") And CreateGadgetList(WindowID(0))
  CalendarGadget(1, 50, 20, 200, 180)
  TextGadget(2, 10, 230, 200, 25, "")
  Repeat
    event = WaitWindowEvent()
    If event = #PB_Event_Gadget And EventGadget() = 1
      SetGadgetText(2, "")
      ; --> Get mouse location
      mcht\pt\x = DesktopMouseX()
      mcht\pt\y = DesktopMouseY()
      ; --> Convert mouse location to CalendarGadget coordinates
      ScreenToClient_(GadgetID(1), @mcht\pt)
      SendMessage_(GadgetID(1), #MCM_HITTEST, 0, @mcht)
      Select mcht\uHit
        Case #MCHT_TITLEBTNNEXT
          SetGadgetText(2, "Calendar last changed by button Next")
        Case #MCHT_TITLEBTNPREV
          SetGadgetText(2, "Calendar last changed by button Previous")
      EndSelect
    EndIf
  Until event = #PB_Event_CloseWindow
EndIf
End

Posted: Tue Feb 21, 2006 7:34 pm
by josku_x
I have nothing to do today, so here is the above code in PB3.94

Code: Select all

#MCHT_TITLE = $10000 
#MCHT_NEXT = $1000000 
#MCHT_PREV = $2000000 
#MCHT_TITLEBTNPREV = #MCHT_TITLE | #MCHT_PREV | 3 
#MCHT_TITLEBTNNEXT = #MCHT_TITLE | #MCHT_NEXT | 3
#MCM_HITTEST = $1000 + 14 

Structure _MCHITTESTINFO 
  cbSize.l 
  pt.POINT 
  uHIt.l 
  st.SYSTEMTIME 
EndStructure 

mcht._MCHITTESTINFO\cbSize = SizeOf(_MCHITTESTINFO) 

If OpenWindow(0, 0, 0, 300, 300, #PB_Window_SystemMenu | #PB_Window_ScreenCentered,"CalendarGadget Hit Test") And CreateGadgetList(WindowID(0)) 
  CalendarGadget(1, 50, 20, 200, 180) 
  TextGadget(2, 10, 230, 200, 25, "") 
  Repeat 
    event = WaitWindowEvent() 
    If event = #PB_Event_Gadget And EventGadgetID() = 1 
      SetGadgetText(2, "") 
      ; --> Get mouse location 
      mcht\pt\x = DesktopMouseX() 
      mcht\pt\y = DesktopMouseY() 
      ; --> Convert mouse location to CalendarGadget coordinates 
      ScreenToClient_(GadgetID(1), @mcht\pt) 
      SendMessage_(GadgetID(1), #MCM_HITTEST, 0, @mcht) 
      Select mcht\uHit 
        Case #MCHT_TITLEBTNNEXT 
          SetGadgetText(2, "Calendar last changed by button Next") 
        Case #MCHT_TITLEBTNPREV 
          SetGadgetText(2, "Calendar last changed by button Previous") 
      EndSelect 
    EndIf 
  Until event = #PB_Event_CloseWindow 
EndIf 
End

Posted: Wed Feb 22, 2006 12:05 am
by Phoenix
Fred wrote:You can may be compare the date returned by GetGadgetState() and see if the month has changed ?
I use a two-month display though so that won't help because I can click either of two months. I will try what Sparkie gave as it looks like what I need.