PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Mark Strickland on August 24, 2007, 10:38:30 AM

Title: MonthCalendar Revisited
Post by: Mark Strickland on August 24, 2007, 10:38:30 AM
I am trying to get a MonthCalendar control working and I am a bit confused.  I found some PB DDT code and tried to use bits of it but obviously I don't understand.

That code looked for a WM_NOTIFY message in the callback.  The CUSTOM event for this control type does not generate any WM_NOTIFY messages. 

Based on the PB forum code this is what I did in the CUSTOM event to get the date that was selected but it never fires.


FUNCTION CALENDARPICK_MONTHCALENDAR1_CUSTOM ( _
                                            ControlIndex  AS LONG,  _  ' index in Control Array
                                            hWndForm      AS DWORD, _  ' handle of Form
                                            hWndControl   AS DWORD, _  ' handle of Control
                                            wMsg          AS LONG,  _  ' type of message
                                            wParam        AS DWORD, _  ' first message parameter
                                            lParam        AS LONG   _  ' second message parameter
                                            ) AS LONG

    LOCAL pNMSC   AS NMSELECT PTR
    LOCAL SelDate AS STRING
    LOCAL SelDay  AS STRING
       
    IF wMsg = %WM_NOTIFY THEN

        pNMSC = lParam
        SelDate = RSET$(TRIM$(STR$(@pNMSC.stSelStart.wMonth)), 2 USING "0") & "-" & _
                  RSET$(TRIM$(STR$(@pNMSC.stSelStart.wDay)), 2 USING "0") & "-" & _
                  TRIM$(STR$(@pNMSC.stSelStart.wYear))
   
        SelDay  = TRIM$(STR$(@pNMSC.stSelStart.wDayofWeek))

    END IF
END FUNCTION


Here is the code from the PB post:
http://www.powerbasic.com/support/forums/Forum7/HTML/001785.html (http://www.powerbasic.com/support/forums/Forum7/HTML/001785.html)

CALLBACK FUNCTION fMAIN_CB()

  DIM hMC   AS STATIC DWORD
  DIM  Msel AS STATIC LONG
  '---------------------------------------
  DIM tMhdr AS LOCAL NMSELECT PTR
  DIM  D    AS LOCAL LONG
  DIM  M    AS LOCAL LONG
  DIM  Y    AS LOCAL LONG

  SELECT CASE CBMSG
    CASE %WM_INITDIALOG    : hMC = GetDlgItem(CBHNDL, %IDC_SMC)    'get Calendar's handle
                             SendMessage hMC, %MCM_SETFIRSTDAYOFWEEK, 0, -1  ' local 1st day of week
                             Msel = SendMessage(hMC, %MCM_GETMAXSELCOUNT, 0, 0)
                             IF Msel = 1 THEN
                               CONTROL DISABLE CBHNDL, %BTN_BUTTON9
                               CONTROL DISABLE CBHNDL, %BTN_BUTTONA
                             END IF
    CASE %WM_NOTIFY        : tMhdr = CBLPARAM
                             SELECT CASE @tMhdr.hdr.code
                               CASE %MCN_SELECT    : Y = @tMhdr.stSelStart.wYear
                                                     M = @tMhdr.stSelStart.wMonth
                                                     D = @tMhdr.stSelStart.wDay
                                                     IF Msel < 2 THEN
                                                       MSGBOX "SELECTED:" & STR$(Y) & STR$(-M) & STR$(-D), %MB_SYSTEMMODAL
                                                     END IF
                             END SELECT
    CASE %WM_COMMAND       : SELECT CASE CBCTL
                               CASE %BTN_BUTTON1 : IF fBNclicked(CBCTLMSG) THEN MC_SetSize      CBHNDL, %IDC_SMC, 1, 1, 1
                               CASE %BTN_BUTTON2 : IF fBNclicked(CBCTLMSG) THEN MC_SetSize      CBHNDL, %IDC_SMC, 2, 2, 1
                               CASE %BTN_BUTTON3 : IF fBNclicked(CBCTLMSG) THEN MC_SetColors    CBHNDL, %IDC_SMC
                               CASE %BTN_BUTTON4 : IF fBNclicked(CBCTLMSG) THEN MC_SetDelta     CBHNDL, %IDC_SMC
                               CASE %BTN_BUTTON5 : IF fBNclicked(CBCTLMSG) THEN MC_SetRange     CBHNDL, %IDC_SMC
                               CASE %BTN_BUTTON6 : IF fBNclicked(CBCTLMSG) THEN MC_SetFirstDay  CBHNDL, %IDC_SMC
                               CASE %BTN_BUTTON7 : IF fBNclicked(CBCTLMSG) THEN MC_SetToday     CBHNDL, %IDC_SMC
                               CASE %BTN_BUTTON8 : IF fBNclicked(CBCTLMSG) THEN MC_MonthRange   CBHNDL, %IDC_SMC
                               CASE %BTN_BUTTON9 : IF fBNclicked(CBCTLMSG) THEN MC_SetMaxSelect CBHNDL, %IDC_SMC
                               CASE %BTN_BUTTONA : IF fBNclicked(CBCTLMSG) THEN MC_GetSelRange  CBHNDL, %IDC_SMC
                               CASE %BTN_Exit    : IF fBNclicked(CBCTLMSG) THEN DIALOG END CBHNDL, 0
                             END SELECT
  END SELECT

END FUNCTION


The CBLPARAM value in the DDT code, by my understanding, the LPARAM value in a FF event that is passed in.

There is another FF event that does have something to do with selecting a date but I cannot figure out how to get the proper reference to the date structure to get the mm/dd/yyyy parts.

FUNCTION CALENDARPICK_MONTHCALENDAR1_MCN_SELECT ( _
                                                ControlIndex  AS LONG,           _  ' index in Control Array
                                                hWndForm      AS DWORD,          _  ' handle of Form
                                                hWndControl   AS DWORD,          _  ' handle of Control
                                                BYVAL pNMHDR  AS NMHDR PTR       _  ' pointer to NMHDR structure
                                                ) AS LONG



Can anybody help?  If you have some "better way" to do a popup calendar selection let me know.

Thanks.
Title: Re: MonthCalendar Revisited
Post by: TechSupport on August 24, 2007, 11:52:52 AM
Your problem is that you are using the CUSTOM handler of the control rather than the form. WM_NOTIFY is passed to the parent form and not the control itself. If the control had any child windows embedded it in then the control would be the parent and would receive notification messages from the child windows.

You need to either move your WM_NOTIFY code to the parent form or use the MCN_SELECT handler as follows:

Function FORM1_MONTHCALENDAR1_MCN_SELECT ( _
                                         ControlIndex  As Long,           _  ' index in Control Array
                                         hWndForm      As Dword,          _  ' handle of Form
                                         hWndControl   As Dword,          _  ' handle of Control
                                         ByVal pNMHDR  As NMHDR Ptr       _  ' pointer to NMHDR structure
                                         ) As Long

    Local pNMSC   As NMSELECT Ptr
    Local SelDate As String
    Local SelDay  As String
   
    pNMSC = pNMHDR
   
   
    SelDate = RSet$(Trim$(Str$(@pNMSC.stSelStart.wMonth)), 2 Using "0") & "-" & _
              RSet$(Trim$(Str$(@pNMSC.stSelStart.wDay)), 2 Using "0") & "-" & _
              Trim$(Str$(@pNMSC.stSelStart.wYear))

    SelDay  = Trim$(Str$(@pNMSC.stSelStart.wDayofWeek))
    MsgBox SelDay 

End Function


Hope this helps.

Title: Re: MonthCalendar Revisited
Post by: Mark Strickland on August 24, 2007, 12:27:40 PM
Thanks!

I was 99% sure I tried the code you posted in the reply (in the MCN_SELECT event) and the
pNMSC = pNMHDR
GPF'ed.

Oh well it works now.

BTW -- The day function seems to not return the day of the week but I remember a reference that the format of the structure is not quite right and you have to do a little different conversion to get the day.

Thanks again for the help.

ALSO BTW -- I have FireFly and PB installed on a USB drive.  I was able to start FireFly, load the project, make the change, compile, and get results ALL WITHOUT HAVING ANYTHING INSTALLED ON THIS LAPTOP!  Try that with one of the "Studio" products.

Not to mention that the EXE is only 500k from 85k lines of code for a program that can generate over a dozen different reports for this application.

I just LOVE FF and PB!  ;D

The thing I find curious is how can anybody think something else would be better?