Announcement

Collapse
No announcement yet.

system date responses twice?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • system date responses twice?

    After plugging in some code from the last topic I posted on two system dates in one dialog, have problem.

    This code is a little different, and the problem is that when a date is selected it responses twice to one click.

    Do not see the problem, how to fix?

    code below

    Code:
    #DIM ALL
    #COMPILE EXE
    #INCLUDE "WIN32API.INC"
    
    %IDC_SYSDATETIMEPICK32_1B = 101
    %LBL8                     = 102
    
    %IDC_SYSDATETIMEPICK32_1C = 103
    %LBL9                     = 104
    
    '------------------/
    CALLBACK FUNCTION DlgProc() AS LONG
       LOCAL MO, DA, YR AS STRING
      SELECT CASE CBMSG
    
             CASE %WM_NOTIFY                               ' Control Event Notification sent to Parent
            IF CB.NMCODE = %DTN_DATETIMECHANGE THEN        ' DTP Change notification
              LOCAL nDTC AS NMDATETIMECHANGE               ' Use appropriate UDT
               TYPE SET nDTC = CB.NMHDR$( SIZEOF(nDTC) )   ' **
    
                  MO=STR$( nDTC.st.wMonth )
                  DA=STR$( nDTC.st.wDay )
                  YR=STR$( nDTC.st.wYear )
    
                SELECT CASE CB.NMID
                    CASE %IDC_SYSDATETIMEPICK32_1B
                          ? "START "+MO+DA+YR
    
                    CASE %IDC_SYSDATETIMEPICK32_1C
                        ? "END "+MO+DA+YR
                END SELECT
            END IF
    
        CASE %WM_COMMAND
          SELECT CASE CBCTL
            CASE %IDOK
              IF CBCTLMSG = %BN_CLICKED THEN
                DIALOG END CBHNDL, 0
              END IF
          END SELECT
    
        CASE %WM_DESTROY
    
      END SELECT
    END FUNCTION
    '------------------/DlgProc
    
    FUNCTION PBMAIN() AS LONG
     LOCAL hDlg3 AS DWORD
     LOCAL wszFormat AS WSTRINGZ * 14
    
      DIALOG NEW 0, "Test", , , 240, 150, %WS_CAPTION OR %WS_SYSMENU, 0 TO hDlg3
    
        CONTROL ADD "SysDateTimePick32", hDlg3, %IDC_SYSDATETIMEPICK32_1B, "",50, 30, 120, 15 , %WS_CHILD OR _
                %WS_TABSTOP OR %WS_VISIBLE OR %DTS_LONGDATEFORMAT, %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                %WS_EX_RIGHTSCROLLBAR OR %WS_EX_CLIENTEDGE
    
         CONTROL ADD "SysDateTimePick32", hDlg3, %IDC_SYSDATETIMEPICK32_1C, "",50, 105, 120, 15 , %WS_CHILD OR _
                %WS_TABSTOP OR %WS_VISIBLE OR %DTS_LONGDATEFORMAT, %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                %WS_EX_RIGHTSCROLLBAR OR %WS_EX_CLIENTEDGE
    
    
     wszFormat = "MM-dd-yyyy"
      CONTROL SEND hDlg3, %IDC_SYSDATETIMEPICK32_1B, %DTM_SETFORMATW, 0, VARPTR(wszFormat)
      CONTROL SEND hDlg3, %IDC_SYSDATETIMEPICK32_1C, %DTM_SETFORMATW, 0, VARPTR(wszFormat)
    
    
        CONTROL ADD LABEL, hDlg3, %LBL8, "", 50, 10, 120, 15
        CONTROL ADD LABEL, hDlg3, %LBL9, "", 50, 85, 120, 15
    
        CONTROL ADD BUTTON, hDlg3, %IDOK, "Ok", 185, 132, 50, 14
    
      DIALOG SHOW MODAL hDlg3, CALL DlgProc
    
    END FUNCTION
    '------------------/PBMain
    Robert

  • #2
    Same sample just added a counter to see that it does process twice when clicked on a date. Strange . I can still use this since it will just repeat the date twice.

    Code:
    #DIM ALL
    #COMPILE EXE
    #INCLUDE "WIN32API.INC"
    
    %IDC_SYSDATETIMEPICK32_1B = 101
    %LBL8                     = 102
    
    %IDC_SYSDATETIMEPICK32_1C = 103
    %LBL9                     = 104
    
    GLOBAL X AS LONG
    
    '------------------/
    CALLBACK FUNCTION DlgProc() AS LONG
       LOCAL MO, DA, YR AS STRING
    
      SELECT CASE CBMSG
    
        CASE %WM_NOTIFY                               ' Control Event Notification sent to Parent
            IF CB.NMCODE = %DTN_DATETIMECHANGE THEN        ' DTP Change notification
              LOCAL nDTC AS NMDATETIMECHANGE               ' Use appropriate UDT
    
               TYPE SET nDTC = CB.NMHDR$( SIZEOF(nDTC) )   ' **
    
                  MO=STR$( nDTC.st.wMonth )
                  DA=STR$( nDTC.st.wDay )
                  YR=STR$( nDTC.st.wYear )
    
                SELECT CASE CB.NMID
                    CASE %IDC_SYSDATETIMEPICK32_1B
                         CONTROL SET TEXT CB.HNDL, %LBL8, MO+DA+YR +" X  "+STR$(X): ? "START "+MO+DA+YR +" X  "+STR$(X) : INCR X
    
                    CASE %IDC_SYSDATETIMEPICK32_1C
                        CONTROL SET TEXT CB.HNDL, %LBL9, MO+DA+YR +" X  "+STR$(X): ? "END "+MO+DA+YR +" X  "+STR$(X) : INCR X
                END SELECT
            END IF
    
        CASE %WM_COMMAND
          SELECT CASE CBCTL
            CASE %IDOK
              IF CBCTLMSG = %BN_CLICKED THEN
                DIALOG END CBHNDL, 0
              END IF
          END SELECT
    
        CASE %WM_DESTROY
    
      END SELECT
    END FUNCTION
    '------------------/DlgProc
    
    FUNCTION PBMAIN() AS LONG
     LOCAL hDlg3 AS DWORD
     LOCAL wszFormat AS WSTRINGZ * 14    : X=1
    
      DIALOG NEW 0, "Test", , , 240, 150, %WS_CAPTION OR %WS_SYSMENU, 0 TO hDlg3
    
        CONTROL ADD "SysDateTimePick32", hDlg3, %IDC_SYSDATETIMEPICK32_1B, "",50, 30, 120, 15 , %WS_CHILD OR _
                %WS_TABSTOP OR %WS_VISIBLE OR %DTS_LONGDATEFORMAT, %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                %WS_EX_RIGHTSCROLLBAR OR %WS_EX_CLIENTEDGE
    
         CONTROL ADD "SysDateTimePick32", hDlg3, %IDC_SYSDATETIMEPICK32_1C, "",50, 105, 120, 15 , %WS_CHILD OR _
                %WS_TABSTOP OR %WS_VISIBLE OR %DTS_LONGDATEFORMAT, %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                %WS_EX_RIGHTSCROLLBAR OR %WS_EX_CLIENTEDGE
    
    
     wszFormat = "MM-dd-yyyy"
      CONTROL SEND hDlg3, %IDC_SYSDATETIMEPICK32_1B, %DTM_SETFORMATW, 0, VARPTR(wszFormat)
      CONTROL SEND hDlg3, %IDC_SYSDATETIMEPICK32_1C, %DTM_SETFORMATW, 0, VARPTR(wszFormat)
    
    
        CONTROL ADD LABEL, hDlg3, %LBL8, "", 50, 10, 120, 15
        CONTROL ADD LABEL, hDlg3, %LBL9, "", 50, 85, 120, 15
    
        CONTROL ADD BUTTON, hDlg3, %IDOK, "Ok", 185, 132, 50, 14
    
      DIALOG SHOW MODAL hDlg3, CALL DlgProc
    
    END FUNCTION
    '------------------/PBMain
    Robert

    Comment


    • #3
      Just to let you know you are not going crazy. I too have run into this double notification. Hopefully someone more experienced that us can clear it up. By the way you should check for a valid condition. I tried it but made no difference.

      Frank

      Code:
                      CASE %IDC_SYSDATETIMEPICK32_1B
      
      
                        LOCAL NMDTC AS NMDATETIMECHANGE PTR
                        NMDTC = CB.LPARAM
                        IF @NMDTC.dwFlags = %GDT_VALID THEN
                           CONTROL SET TEXT CB.HNDL, %LBL8, MO+DA+YR +" X  "+STR$(X): ? "START "+MO+DA+YR +" X  "+STR$(X): INCR X
                        END IF
      
      
                      CASE %IDC_SYSDATETIMEPICK32_1C
      you should also check for valid before trusting .ST

      Comment


      • #4
        Hi Robert,

        It's a little odd isn't it!
        The double notification only occurs if a change is made in the Drop-down Calendar.
        Once, when the Drop-down change is made and another when the drop-down closes.
        If you use the keyboard to adjust the date in the editbox of the control there is only one 'change' notification per valid entry.
        Rgds, Dave

        Comment


        • #5
          Thanks Frank and Dave for the info on this mystery . Dave in my computer using mouse to click date control and then use keyboard down or any arrow key moves cursor on date one at a time only. Have to click anywhere on dialog to close date calendar. When use mouse to click date get two notifications and date calendar closes.
          Robert

          Comment


          • #6
            Hi Robert,

            You should avoid using Message Boxes inside a CallBack Proc. They can cause unwanted problems as they interfere with 'normal' program flow.
            For example see what happens if you click on the month change button inside the drop-down calendar !! (use Taskmanger / end process to break the loop)

            A better option could be to use the Dialog Caption to display info..
            Code:
                            CASE %IDC_SYSDATETIMEPICK32_1B
                               Incr x : Dialog Set Text Cb.Hndl, Str$(x) + " START "+MO+DA+YR
            Rgds, Dave

            Comment


            • #7
              While working on this piece of code found another anomaly with dates.
              Had two variables DATE1 and DATE2 to get the dates. DATE1 did not work, a big blank. Spend a while trying to figure it out. So changed variables to STAMO and ENDMO.
              That worked . The closest PB key word is DATE$ , wonder it that caused the problem.
              Robert

              Comment


              • #8
                Robert, I think it's normal behavior to get two notifications because of the SysDateTimePick32 / SysMonthCal32 tandem.
                SysMonthCal32 beeing called internally by SysDateTimePick32.

                If multiple notifications is a problem then you may try the following...

                Code:
                CASE %WM_NOTIFY
                  LOCAL  pDateChange        AS NMDATETIMECHANGE POINTER
                  STATIC DateBak            AS NMDATETIMECHANGE
                  STATIC wParamCtrlId       AS DWORD
                  STATIC BypassNotification AS LONG
                
                  SELECT CASE CBNMCODE
                
                    CASE %DTN_DROPDOWN
                      BypassNotification = %TRUE
                
                    CASE %DTN_CLOSEUP
                      BypassNotification = %FALSE
                      SendNotifyMessage(CBHNDL, %WM_NOTIFY, wParamCtrlId, VARPTR(DateBak))
                
                    CASE %DTN_DATETIMECHANGE
                      wParamCtrlId = CBWPARAM
                      pDateChange  = CBLPARAM
                      IF BypassNotification THEN
                        DateBak = @pDateChange
                      ELSE
                        OutputDebugString("Single notification date change from control" & STR$(wParamCtrlId) & _
                                          ", date:" & STR$(@pDateChange.st.wYear) & _
                                          STR$(@pDateChange.st.wMonth) & STR$(@pDateChange.st.wDay))
                      END IF
                
                  END SELECT
                Last edited by Pierre Bellisle; 9 Mar 2019, 05:53 PM.

                Comment


                • #9
                  Thanks for the info Pierre. This double notification may not be a problem since I am just getting the date to a variables. Your code would be helpful if I did want to post a message after a date had been selected. Will try it out and save in my sample code library for future use.
                  Robert

                  Comment

                  Working...
                  X