Announcement

Collapse
No announcement yet.

set focus on date/time picker control section

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

  • set focus on date/time picker control section

    Hello PB gurus!

    I have a picky request from our QA folks and I am not sure it is possible. It appears that the default behavior for a date/time picker control (DTP) is to have the section highlighted that was previously used. By "section " I mean month, day or year--3 sections. We have a need to set the focus on the year only or on the month only.

    I have been playing around with PBforms trying to get something to work. Here is what I have that will compile:
    Code:
    #PBFORMS CREATED V1.51
    '------------------------------------------------------------------------------
    ' The first line in this file is a PB/Forms metastatement.
    ' It should ALWAYS be the first line of the file. Other
    ' PB/Forms metastatements are placed at the beginning and
    ' end of "Named Blocks" of code that should be edited
    ' with PBForms only. Do not manually edit or delete these
    ' metastatements or PB/Forms will not be able to reread
    ' the file correctly.  See the PB/Forms documentation for
    ' more information.
    ' Named blocks begin like this:    #PBFORMS BEGIN ...
    ' Named blocks end like this:      #PBFORMS END ...
    ' Other PB/Forms metastatements such as:
    '     #PBFORMS DECLARATIONS
    ' are used by PB/Forms to insert additional code.
    ' Feel free to make changes anywhere else in the file.
    '------------------------------------------------------------------------------
    
    #COMPILE EXE
    #DIM ALL
    
    '------------------------------------------------------------------------------
    '   ** Includes **
    '------------------------------------------------------------------------------
    #PBFORMS BEGIN INCLUDES
    %USEMACROS = 1
    #IF NOT %DEF(%WINAPI)
        #INCLUDE "WIN32API.INC"
    #ENDIF
    #IF NOT %DEF(%COMMCTRL_INC)
        #INCLUDE "COMMCTRL.INC"
    #ENDIF
    #INCLUDE "PBForms.INC"
    #PBFORMS END INCLUDES
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Constants **
    '------------------------------------------------------------------------------
    #PBFORMS BEGIN CONSTANTS
    %IDD_DIALOG1             =  101
    %IDC_SYSDATETIMEPICK32_1 = 1001
    %IDC_BUTTON1             = 1002
    %IDC_BUTTON2             = 1003
    #PBFORMS END CONSTANTS
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Declarations **
    '------------------------------------------------------------------------------
    DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
    DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
    #PBFORMS DECLARATIONS
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Main Application Entry Point **
    '------------------------------------------------------------------------------
    FUNCTION PBMAIN()
        PBFormsInitComCtls (%ICC_WIN95_CLASSES OR %ICC_DATE_CLASSES OR _
            %ICC_INTERNET_CLASSES)
    
        ShowDIALOG1 %HWND_DESKTOP
    END FUNCTION
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** CallBacks **
    '------------------------------------------------------------------------------
    CALLBACK FUNCTION ShowDIALOG1Proc()
    
        SELECT CASE AS LONG CBMSG
            CASE %WM_INITDIALOG
                ' Initialization handler
    
            CASE %WM_NCACTIVATE
                STATIC hWndSaveFocus AS DWORD
                IF ISFALSE CBWPARAM THEN
                    ' Save control focus
                    hWndSaveFocus = GetFocus()
                ELSEIF hWndSaveFocus THEN
                    ' Restore control focus
                    SetFocus(hWndSaveFocus)
                    hWndSaveFocus = 0
                END IF
    
            CASE %WM_COMMAND
                ' Process control notifications
                SELECT CASE AS LONG CBCTL
                    CASE %IDC_SYSDATETIMEPICK32_1
    
                    CASE %IDC_BUTTON1
                        IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                            MSGBOX "Set Focus on day"
                            CONTROL SET FOCUS CBHNDL, %IDC_SYSDATETIMEPICK32_1
    'now we do something to set the focus on the day only
                        END IF
    
                    CASE %IDC_BUTTON2
                        IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                            MSGBOX "Set focus on year"
                            CONTROL SET FOCUS CBHNDL, %IDC_SYSDATETIMEPICK32_1
    'now we do something to set the focus on the year only
                        END IF
    
                END SELECT
        END SELECT
    END FUNCTION
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Dialogs **
    '------------------------------------------------------------------------------
    FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
        LOCAL lRslt AS LONG
    
    #PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
        LOCAL hDlg  AS DWORD
    
        DIALOG NEW hParent, "Dialog1", 289, 262, 201, 121, %WS_POPUP OR _
            %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR %WS_CLIPSIBLINGS OR _
            %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
            %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR _
            %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
        CONTROL ADD "SysDateTimePick32", hDlg, %IDC_SYSDATETIMEPICK32_1, _
            "SysDateTimePick32_1", 25, 20, 75, 20, %WS_CHILD OR %WS_VISIBLE OR _
            %WS_TABSTOP OR %DTS_SHORTDATEFORMAT, %WS_EX_LEFT OR _
            %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR OR %WS_EX_CLIENTEDGE
        CONTROL ADD BUTTON, hDlg, %IDC_BUTTON1, "Set focus on Day", 40, 65, 80, 25
        CONTROL ADD BUTTON, hDlg, %IDC_BUTTON2, "Set focus on year", 40, 95, 80, 20
    #PBFORMS END DIALOG
    
        DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
    
    #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
    #PBFORMS END CLEANUP
    
        FUNCTION = lRslt
    END FUNCTION
    Does anybody know of any way to set which part of the control has focus? Any tips or thoughts would be appreciated!
    Last edited by Bill Scharf; 1 May 2009, 07:38 AM. Reason: typo
    Bill Scharf

  • #2
    Just off the top of my head...

    After you set focus to the control, use key_event() to send the correct number of "right arrow" keys to get where you want to go?
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Michael,

      This is a good idea and better than any ideas I had. Thanks! However, by sending "right arrow" keys, then you must know which section you are in.

      Example - mouse user:

      1. User clicks on middle section (day)
      2. User clicks on button that results in setting focus on the 3rd section (year)

      How do I know to only do one "right arrow" key and not two? Maybe it is possible to sublcass the control and try to determine where the user clicked? I wonder if that would be reliable?

      Example - keyboard user
      1. User tabs to DTP
      2. User uses arrow keys to go to middle section
      3. User tabs to "set focus on year" button
      4. User hits enter/space bar to execute button

      Again, how do I know to only do one "right arrow' key and not two? Maybe it is possible to subclass the control and count the number of arrow keys. It looks like ctrl-right and ctrl-left do the same as without the ctrl key. So then I would have to account for all 4 keys.

      This method seems possible, but I am still looking for something less complicated. If anybody has any suggestions, please let me know.
      Bill Scharf

      Comment


      • #4
        If you only need to support a limited number of date formats, it might be faster to just not use the DTP, but use your own controls.

        eg put three edit controls next to each other : month, day and year. Add a button with the stock down-arrow ("dropdown") button on it to the right... when clicked, call in a calendar control.

        Subclass the month day and year controls to pick off left and right arrows... if either pressed at end of field, set focus to next/prior control.

        Something like that. The DTP control does what it does; it's your choice to use it or not.

        It's a thought.

        Also... if you go with custom format and/or APPCANPARSE style on a DTP, you get lots of notifications. Maybe that is a road worth travelling...



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

        Comment


        • #5
          Found this in my doc for the date-time picker....
          Callback fields
          In addition to the standard Format Strings and body text, you can also define certain parts of the display as Callback fields. These fields can be used to query the user for information. To declare a callback field, include one or more "X" characters (ASCII Code 88) anywhere in the format string. You can create callback fields that have a unique identity by repeating the "X" character. Thus, the format string "XX dddd MMM dd', 'yyy XXX" contains two unique callback fields, "XX" and "XXX". Like other DTP control fields, callback fields are displayed in left-to-right order based on their location in the format string.

          When the DTP control parses the format string and encounters a callback field, it sends DTN_FORMAT and DTN_FORMATQUERY notification messages. The format string element corresponding to the callback field is included with the notifications to allow the receiving application to determine which callback field is being queried. The owner of the control must respond to these notifications to ensure that the custom information is properly displayed.
          This looks very interesting. it suggests whenever the user goes to one of the fields you can get a notification (callback).


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

          Comment

          Working...
          X