Calendar back/forward buttons

Just starting out? Need help? Post your questions and find answers here.
Phoenix
Enthusiast
Enthusiast
Posts: 141
Joined: Sun Sep 04, 2005 2:25 am

Calendar back/forward buttons

Post 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?
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Post 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.

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

You can may be compare the date returned by GetGadgetState() and see if the month has changed ?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

That would catch it the user changes month using the light grey dates and he asked for button press.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post 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
Phoenix
Enthusiast
Enthusiast
Posts: 141
Joined: Sun Sep 04, 2005 2:25 am

Post 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.
Post Reply