Announcement

Collapse
No announcement yet.

Focus with SysDateTimePick32

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

  • Focus with SysDateTimePick32

    Hello,

    I've got a problem with SysDateTimePick32. Everytime the calender is opened, and a selection is picked, the Focus shifts (unwanted) to the first control on the Dialog.
    This can be very annoying. I have several of these date entry fields in a form, together with edit and comboboxes, that need to be filled in in sequence. How can you keep focus on the SysDateTimePick32 control?
    An example:

    Code:
    #Compile Exe
    #Dim All
    #Include "WIN32API.INC"
    #Include "COMMCTRL.INC"
    #Include "PBForms.INC"
    
    %IDD_DIALOG1                = 101
    %IDC_SYSDATETIMEPICK32_1    = 1001
    %IDC_TEXTBOX1               = 1002
    %IDC_TEXTBOX2               = 1003
    %IDC_TEXTBOX3               = 1004
    %IDC_TEXTBOX4               = 1005
    
    Declare CallBack Function ShowDIALOG1Proc()
    Declare Function ShowDIALOG1(ByVal hParent As Dword) As Long
    
    Function PBMain()
        PBFormsInitComCtls (%ICC_WIN95_CLASSES Or %ICC_DATE_CLASSES Or %ICC_INTERNET_CLASSES)
        ShowDIALOG1 %HWND_DESKTOP
    End Function
    '--------------------------------------------------------------------------------
    Function ShowDIALOG1(ByVal hParent As Dword) As Long
        Local lRslt As Long, hDlg As Dword, X As Long
    
        Dialog New hParent, "Dialog1", 69, 80, 195, 102, %WS_SYSMENU To hDlg
        Control Add TextBox, hDlg, %IDC_TEXTBOX1, "TextBox1", 5, 5, 100, 13
        Control Add TextBox, hDlg, %IDC_TEXTBOX2, "TextBox2", 5, 20, 100, 13
        Control Add "SysDateTimePick32", hDlg, %IDC_SYSDATETIMEPICK32_1, _
            "SysDateTimePick321", 5, 35, 100, 13, %WS_CHILD Or %WS_VISIBLE Or _
            %WS_TABSTOP Or %DTS_SHORTDATEFORMAT
        Control Add TextBox, hDlg, %IDC_TEXTBOX3, "TextBox3", 5, 50, 100, 13
        Control Add TextBox, hDlg, %IDC_TEXTBOX4, "TextBox4", 5, 65, 100, 13
    
        Dialog Show Modal hDlg To lRslt
    
        Function = lRslt
    End Function
    '--------------------------------------------------------------------------------
    Regards,
    Peter

  • #2
    Far be it for me to be advising you Peter but I do have a thought:

    Don't you need a CallBack to trap the %IDC_SYSDATETIMEPICK32_1 Control click and then restore the Focus to whichever Control had it before the %IDC_SYSDATETIMEPICK32_1 click?

    ===================================================
    "Learning is what most adults will do for a living
    in the 21st century."
    Lewis Perelman
    ===================================================
    It's a pretty day. I hope you enjoy it.

    Gösta

    JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
    LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

    Comment


    • #3
      DTN_CLOSEUP Notification
      --------------------------------------------------------------------------------
      Sent by a date and time picker (DTP) control when the user closes the drop-down month calendar. The month calendar is closed when the user chooses a date from the month calendar or clicks the drop-down arrow while the calendar is open
      REQUIRED NON-QUOTED TEXT TO ALLOW POSTING.
      Michael Mattias
      Tal Systems Inc. (retired)
      Racine WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        I knew better than to advise Peter L on anything regarding PB ("Don't you need a CallBack to trap ...") then went ahead and did it anyway. {arrrghh}

        So, I thought wisely, maybe I ought to try what I preached. And, to no one's suprise I'm sure, it didn't work. {sigh}


        '
        Code:
        #Compile Exe
        #Dim All
        #Include "WIN32API.INC"
        #Include "COMMCTRL.INC"
        #Include "PBForms.INC"
         
        %IDD_DIALOG1                = 101
        %IDC_SYSDATETIMEPICK32_1    = 1001
        %IDC_TEXTBOX1               = 1002
        %IDC_TEXTBOX2               = 1003
        %IDC_TEXTBOX3               = 1004
        %IDC_TEXTBOX4               = 1005
         
        Declare CallBack Function ShowDIALOG1Proc()
        Declare Function ShowDIALOG1(ByVal hParent As Dword) As Long
        '
        CallBack Function ShowDIALOG1Proc()
           Static Last_Control_Focused&       
        'DTN_CLOSEUP   '<<== How to use?
         
           Select Case CbMsg
             Case %WM_COMMAND
                Select Case CbCtl   
                  Case %IDC_TEXTBOX1 To %IDC_TEXTBOX4
                    If CbCtlMsg = 0 Then
                       Last_Control_Focused = CbCtl
                       ? Using$("at # ", CbCtl) '<- never gets hit
                    End If 
                     
                  Case %IDC_SYSDATETIMEPICK32_1
                     Control Set Focus  CbHndl, Last_Control_Focused
                       ? Using$("at # ", CbCtl) '<- never gets hit
                     
                End Select
           End Select
           
        End Function
        '
        Function PBMain()
            PBFormsInitComCtls (%ICC_WIN95_CLASSES Or %ICC_DATE_CLASSES Or %ICC_INTERNET_CLASSES)
            ShowDIALOG1 %HWND_DESKTOP
        End Function
        '--------------------------------------------------------------------------------
        Function ShowDIALOG1(ByVal hParent As Dword) As Long
            Local lRslt As Long, hDlg As Dword, X As Long
         
            Dialog New hParent, "Dialog1", 69, 80, 195, 102, %WS_SYSMENU To hDlg
            Control Add TextBox, hDlg, %IDC_TEXTBOX1, "TextBox1", 5, 5, 100, 13
            Control Add TextBox, hDlg, %IDC_TEXTBOX2, "TextBox2", 5, 20, 100, 13
            Control Add "SysDateTimePick32", hDlg, %IDC_SYSDATETIMEPICK32_1, _
                "SysDateTimePick321", 5, 35, 100, 13, %WS_CHILD Or _
                %WS_VISIBLE Or _
                %WS_TABSTOP Or _
                %DTS_SHORTDATEFORMAT
            Control Add TextBox, hDlg, %IDC_TEXTBOX3, "TextBox3", 5, 50, 100, 13
            Control Add TextBox, hDlg, %IDC_TEXTBOX4, "TextBox4", 5, 65, 100, 13
            
            'Dialog Show Modal hDlg To lRslt             '<<- remmed this
            Dialog Show Modal hDlg Call  ShowDIALOG1Proc '<<- added this
         
            Function = lRslt
        End Function
        '--------------------------------------------------------------------------------
        '
        It's a pretty day. I hope you enjoy it.

        Gösta

        JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
        LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

        Comment


        • #5
          > 'DTN_CLOSEUP '<<== How to use?

          I'd say except my 2002 version of the fm does not include what it should: "This notification message is sent in the form of a WM_NOTIFY message. "

          I wonder what the current doc at msdn says....let me look....hmm, that's interesting.

          MCM
          Michael Mattias
          Tal Systems Inc. (retired)
          Racine WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Halfway there

            Okay Peter, I got you halfway there. The cursor returns to the textbox it was in before the Date control is chosen. But there's just one minor problem as you'll see if you run the code. It works with En_change so a tb needs to have been tyoed in. Probably other msgs would work better.

            Mike, I played around with your suggestion but got nowhere. Without actual code for me to see/clip/paste/copy/agonize_over, cryptic clues are lost on this dummy, even if they are in the manual.

            '
            Code:
            'PBWIN 8.04 XP Pro SP3
            #Compile Exe
            #Dim All
            #Include "WIN32API.INC"
            #Include "COMMCTRL.INC"
            #Include "PBForms.INC"
            %IDD_DIALOG1                = 101
            %IDC_SYSDATETIMEPICK32_1    = 1001
            %IDC_TEXTBOX1               = 1002
            %IDC_TEXTBOX2               = 1003
            %IDC_TEXTBOX3               = 1004
            %IDC_TEXTBOX4               = 1005
            Declare CallBack Function ShowDIALOG1Proc()
            Declare Function ShowDIALOG1(ByVal hParent As Dword) As Long
            '
            Global OldListProc As Dword, hList As Dword 'for subclassing
            Global Last_Control_Focused&, hDlg As Dword       
            '
            CallBack Function ShowDIALOG1Proc()
             
               Select Case CbMsg
                 Case %WM_COMMAND
                    Select Case CbCtl   
                      If CbCtlMsg = %En_Change Then 'textbox changed
                        Last_Control_Focused = CbCtl 'remember where
                      End If
                    End Select
                 Case %Wm_Notify '%DTN_DATETIMECHANGE
                    If CbCtl =  %IDC_SYSDATETIMEPICK32_1 Then
                     ''This works but gets hit 5 times
                     'cbctlmsg always = 0
                      '? Using$("# cbctlmsg  at # Last focus #", CbCtlMsg, CbCtl, Last_Control_Focused) 
                      Control Set Focus hdlg, Last_Control_Focused '<<- keeps focus
                    End If  
               End Select
             
            End Function
            '
            Function PBMain()
                PBFormsInitComCtls (%ICC_WIN95_CLASSES Or %ICC_DATE_CLASSES Or %ICC_INTERNET_CLASSES)
                ShowDIALOG1 %HWND_DESKTOP
            End Function
            '--------------------------------------------------------------------------------
            Function ShowDIALOG1(ByVal hParent As Dword) As Long
                Local lRslt As Long,  X As Long
             
                Dialog New hParent, "Dialog1", 69, 80, 195, 102, %WS_SYSMENU To hDlg
                Control Add TextBox, hDlg, %IDC_TEXTBOX1, "TextBox1" & Str$(%IDC_TEXTBOX1), 5, 5, 100, 13
                Control Add TextBox, hDlg, %IDC_TEXTBOX2, "TextBox2" & Str$(%IDC_TEXTBOX2), 5, 20, 100, 13
                Control Add "SysDateTimePick32", hDlg, %IDC_SYSDATETIMEPICK32_1, _
                    "SysDateTimePick321", 5, 35, 100, 13, %WS_CHILD Or _
                    %WS_VISIBLE Or _
                    %WS_TABSTOP Or _
                    %DTS_SHORTDATEFORMAT
             
             'Sub-class the SysDateTimePick32               
                Control Handle hParent, %IDC_SYSDATETIMEPICK32_1 To hList
                  OldListProc = SetWindowLong(hList, %GWL_WNDPROC, CodePtr(SysDate_Processor))
             
                Control Add TextBox, hDlg, %IDC_TEXTBOX3, "TextBox3" & Str$(%IDC_TEXTBOX3), 5, 50, 100, 13
                Control Add TextBox, hDlg, %IDC_TEXTBOX4, "TextBox4" & Str$(%IDC_TEXTBOX4), 5, 65, 100, 13
             
             
                'Dialog Show Modal hDlg To lRslt             '<<- remmed this
                Dialog Show Modal hDlg Call  ShowDIALOG1Proc '<<- added this
                Function = lRslt
            End Function
            '
            Function SysDate_Processor(ByVal hWnd As Long, ByVal wMsg As Long, _
                              ByVal wParam As Long, ByVal lParam As Long) As Long
              Select Case wMsg                  
                 ? " Wmsg hit" '<<- doesn't get hit
                 Case %DTN_CLOSEUP
                   ?"%DTN_CLOSEUP Bingo" '<<- doesn't get hit
              End Select          
              ?"hit",, FuncName$ '<<- Never hits either
            End Function
            '
            '--------------------------------------------------------------------------------
            '
            ======================================================
            "Fill what's empty,
            empty what's full,
            and scratch where it itches."
            the Duchess of Windsor,
            when asked what is the secret of a long and happy life
            ======================================================
            It's a pretty day. I hope you enjoy it.

            Gösta

            JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
            LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

            Comment


            • #7
              Here are a couple of ways to keep the keyboard focus on the Date Time Picker once the SysMonthCal has been displayed..
              Code:
                  Case %WM_NCACTIVATE  ' Leaves focus on DTP control after SysMonthCal closes
                    Static hWndSaveFocus As Dword
                    If IsFalse CbWParam Then
                      hWndSaveFocus = GetFocus()
                    ElseIf hWndSaveFocus Then
                      SetFocus(hWndSaveFocus)
                      hWndSaveFocus = 0
                    End If
              I believe MCM was alluding to something like..
              Code:
               
                  Case %WM_NOTIFY
                   Local lpNmhdr As NMHDR Ptr
                    lpNmhdr = CbLParam
                    Select Case @lpNmhdr.idFrom
                      Case %IDC_SYSDATETIMEPICK32_1
                        Select Case @lpNmhdr.code
                          Case %DTN_CLOSEUP
                            Control Set Focus CbHndl, %IDC_SYSDATETIMEPICK32_1 ' change ID to send elsewhere or
                            'SetFocus GetNextDlgTabItem(CbHndl, @lpNmhdr.hWndFrom , %FALSE)  ' next Tab item
                        End Select
                    End Select
              Rgds, Dave

              Comment


              • #8
                Both your methods look simpler than mine, Dave. which involves subclassing the DTP. In any case Peter's question has been answered (I hope).

                ======================================
                High thoughts must have high language.
                Aristophanes
                ======================================
                It's a pretty day. I hope you enjoy it.

                Gösta

                JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                Comment


                • #9
                  In any case Peter's question has been answered (I hope).
                  Yes, thanks all. It was a bit annoying if you have a form displayed, that after every sysdate control the focus went to the first control on the dialog...
                  Regards,
                  Peter

                  Comment


                  • #10
                    >that after every sysdate control the focus went to the first control on the dialog...

                    I think that actually might be the expected behavior.

                    Windows does not remember focus, and if the window on which it was focused (the dropdown) is suddenly gone (destroyed) , it really has no where to go except to the first tabstop control of whatever window it decides to make active.

                    That's why all that 'boilerplate' code re "hwndSaveFocus" is generated by PBFORMS is there... to 'remember' the last focused control. (Your example in Post #1 had NO callbacks and so never did any of that stuff).
                    Michael Mattias
                    Tal Systems Inc. (retired)
                    Racine WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment

                    Working...
                    X