Announcement

Collapse
No announcement yet.

How to create a special masked edit control ?

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

  • How to create a special masked edit control ?

    Hi,

    i know that I can set a style for "only digit input", but I need this a little different. Allow digits, "+" or "-" (if I want), and the "," or "." ...

    Is it possible to take over control of the keyboard behaviour of a edit control and how to do it ?
    Regards,
    Hubert

    ------------------------------------
    http://familie-brandel.de/index_e.html

  • #2
    Various methods discussed in this thread.. http://www.powerbasic.com/support/pb...ad.php?t=39504

    Especially see PB's Verify function.
    Rgds, Dave

    Comment


    • #3
      Thanks for the link, but I do need a TEXT control, that does not do anything if the wrong key is pressed. In PB 9.0 help I found:

      control add textbox .... %ES_NUMBER, but the problem is, that this will not take +-,. as valid input. They write "subclassing a textbox that does ... rejecting unwanted keystrokes..." thats the point I need to get too.

      I did this in other languages (wich is OOP), but did not find to do it in PowerBasic. Does this have somthing to do with the new objects ?
      Regards,
      Hubert

      ------------------------------------
      http://familie-brandel.de/index_e.html

      Comment


      • #4
        Yeah, I gotta write one of these today, too... I think.

        What I want is something which looks like a combobox (dropdown style), which accepts only valid formatted dates , eg..
        Code:
             [MM-DD-YYYY]
        When the user presses <Enter> I want to check that this date is not already one of the items of the combobox.. and if not, add it and reset the control to accept another "date" .... but I also want to allow the user to select one of those items to bring it into the edit control so I can delete it.

        I also wanted to incorporate a "date picker" or "calendar" control with this, but I have exactly zero space left on the screen. I was thinking maybe I'd just create date-picker control and put it over the edit box portion of the combobox when the user focuses on the combobox.

        If I overlaid the date-picker control on top the CB's edit area then I would not need to worry about subclassing and mask-editing the combobox, although I'd still have to subclass the datepicker control to pick off the "Enter" key....

        No, I did not design this originally... I'm matching the "familiar" behavior of an existing MRP system (Point.Man) for date entry.

        Basically I think it's ugly, but in this case I think ugly is what I need to make prospects feel all warm and fuzzy about the software ... so they purchase it.

        If anyone has done anything like this before I'd be interested in how you chose to do it.... since I obviously have not made up my own mind yet.


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

        Comment


        • #5
          Hubert,

          You will have to Subclass the control (Textbox) and in the SubClass test every key entered, then reject or use as you want. If you are unfamiliar with SubClassing, there's a very good starting example in the Samples folder on the PB disk.

          =============================
          "Wit is educated insolence."
          Aristotle (384-322 B.C.)
          =============================
          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


          • #6
            The best approach is to superclass the edit control.

            Superclassing, is where you create a totally new class based on an existing window class.

            Superclassing is better than subclassing when you need multiple instances of the control.

            In the window procedure of the new control class, process the following messages and customize them:

            WM_KEYUP
            WM_KEYDOWN
            WM_CHAR
            Chris Boss
            Computer Workshop
            Developer of "EZGUI"
            http://cwsof.com
            http://twitter.com/EZGUIProGuy

            Comment


            • #7
              Subclass procedure to allow only valid hex digits. The control uses style ES_UPPERCASE which should explain the way I handle some things.

              Code:
              FUNCTION DelimiterHexEditProc (BYVAL hWnd AS LONG, BYVAL wMSG AS LONG, BYVAL wPAram AS LONG, BYVAL lParam AS LONG) AS LONG
              
                STATIC dwProc AS DWORD, BeenHere AS LONG
                LOCAL szProp AS ASCIIZ * 64
                LOCAL  idCtrl AS LONG
                LOCAL  szText AS ASCIIZ * %MAX_PATH, lText AS LONG
                LOCAL  ichar  AS LONG
              
              
                IF ISFALSE beenHere THEN
                    BeenHere = %TRUE
                    szProp   = $PROP_OLD_WNDPROC
                    dwProc   = getProp (hWnd, szProp)
                END IF
              
                SELECT CASE AS LONG wMSg
              
                       CASE %WM_GETDLGCODE
                           'FUNCTION =  %DLGC_WANTALLKEYS     ' With DLCG_WANTCHARS all regular keys work but no WM-CHAR message
                           FUNCTION = %DLGC_WANTCHARS         ' doc says "WM_CHAR messages"
                           'FUNCTION   = %DLGC_WANTMESSAGE
                           EXIT FUNCTION
              
                       CASE  %WM_CHAR                      '"An application should return zero if it processes this message. "
                          ' LOWRD wparam = "the character code of the key"
                           IF wparam = %VK_TAB THEN
                               ' standard TAB behavior
                                 SetFocus       GetnextDlgTabItem(GetParent(hWnd), hWnd, (GetKeyState(%VK_SHIFT) < 0))
                                 FUNCTION = 0
                                 EXIT FUNCTION
              
                           ELSE  ' not tab
                              iChar  = LOWRD(WParam)
                              SELECT CASE AS LONG iChar
                                  CASE &h30 TO &h39, &h41 TO &h46, _    ' OK characters 0-9 and A-F
                                       &h61 TO &h66, _                  ' lower case a-f, will be uppercased when they get in
                                       %VK_TAB, %VK_HOME, %VK_END, %VK_BACK, _      ' expected control characters
                                       %VK_RIGHT, %VK_LEFT, %VK_INSERT, %VK_DELETE, _
                                       %vK_ESCAPE
              [COLOR="Red"]    ' ******************************************
                  ' AT THIS POINT YOU KNOW THE CHARACTER IS VALID, 
                  ' SO HERE YOU CAN TEST IF YOU WANT TO ALLOW THAT 
                  ' CHARACTER AT THIS POSITION BEFORE 'EXIT SELECT'  
                  ' WHICH WILL ALLOW THE NORMAL PROCESSING OF THAT 
                  ' CHARACTER
                  ' *******************************************[/COLOR]
                                      EXIT SELECT                      ' allow normal processing
                                  CASE ELSE
                                      MessageBeep  %MB_ICONHAND
                                      FUNCTION = 0
                                      EXIT FUNCTION    ' bypass normal processing
                              END SELECT
                           END IF
              
                     END SELECT
                     ' if message not handled (if handled proc was exited), call default handler
                     FUNCTION = CallWindowProc (dwProc, hWnd, wMsg, wParam,lparam)
              
              END FUNCTION
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Subclassing is probably the way to go but just for fun here's another ..
                Code:
                #COMPILE EXE
                #DIM ALL
                %USEMACROS = 1
                #INCLUDE "WIN32API.INC"
                 
                %BTN_Test      = 102
                %LBL_LABEL1    = 101
                %TXT_TEXTBOX1  = 100
                '------------------
                 
                CALLBACK FUNCTION DlgProc()
                 LOCAL sTest$, x&
                  SELECT CASE AS LONG CB.MSG
                 
                    CASE %WM_COMMAND
                      SELECT CASE AS LONG CB.CTL
                        CASE %BTN_Test
                          IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                            CONTROL GET TEXT CB.HNDL, %TXT_TEXTBOX1 TO sTest
                            MSGBOX "sTest = "+stest, ,"Result"
                          END IF
                 
                        CASE %TXT_TEXTBOX1
                          IF CB.CTLMSG = %EN_CHANGE THEN
                            CONTROL GET TEXT CB.HNDL, %TXT_TEXTBOX1 TO sTest
                            x = VERIFY (sTest , "-+,.1234567890")
                            IF x > 0 THEN
                              WinBeep 800, 50
                              sTest = REMOVE$(sTest, MID$(sTest, x, 1))
                              CONTROL SET TEXT CB.HNDL, %TXT_TEXTBOX1, sTest
                              CONTROL SEND CB.HNDL, %TXT_TEXTBOX1, %EM_SETSEL, x-1, x-1
                            END IF
                          END IF
                 
                      END SELECT
                 
                    CASE %WM_SYSCOMMAND
                      IF (CBWPARAM AND &HFFF0) = %SC_CLOSE THEN
                        DIALOG END CB.HNDL
                      END IF
                 
                  END SELECT
                END FUNCTION
                '------------------/DlgProc
                 
                FUNCTION PBMAIN()
                 LOCAL hDlg  AS DWORD
                 
                  DIALOG NEW 0, "Test", , , 200, 120, %WS_CAPTION OR %WS_SYSMENU, TO hDlg
                  CONTROL ADD LABEL,  hDlg, %LBL_LABEL1, "-+,.1234567890 allowed", 50, 25, 120, 20
                  CONTROL ADD BUTTON,  hDlg, %BTN_Test, "Test", 75, 60, 50, 15
                  CONTROL ADD TEXTBOX, hDlg, %TXT_TEXTBOX1, "", 45, 90, 100, 13
                 
                  DIALOG SHOW MODAL hDlg, CALL DlgProc
                 
                END FUNCTION
                '------------------/PbMain
                Last edited by Dave Biggs; 23 Jan 2009, 11:29 PM. Reason: Correction 'x' -> 'x-1' cursor position ok when editing now
                Rgds, Dave

                Comment


                • #9
                  seacrhing the forums using "superclass numeric" I came up with this:

                  http://www.powerbasic.com/support/pb...rclass+numeric

                  Comment


                  • #10
                    Hmm... seems "IS NUMERIC" has at least as many definitions as does "Comma-separated Values file"
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      >> If you are unfamiliar with SubClassing, there's a very good
                      >> starting example in the Samples folder on the PB disk.

                      Yes I am and I must be blind too ... now I found the SubClass Example
                      Regards,
                      Hubert

                      ------------------------------------
                      http://familie-brandel.de/index_e.html

                      Comment


                      • #12
                        One suggestion

                        I wrote a edit control for FireFly. I did NOT take the approach of using a mask:

                        ###,###.00

                        Type of formating. I found that a bit harder to program. I created category codes:

                        S10 = Any string up to 10 characters
                        N10.2 = Numeric with two decimals
                        Z8 = Digits Only and Left zero filled for a total of 8 characters
                        D1 = Date field

                        I have more but you get the idea. I found that parsing off the codes for the length and decimals then jumping to a section of code worked fairly easy.

                        Food for thought.
                        Mark Strickland, CISSP, CEH
                        SimplyBASICsecurity.com

                        Comment


                        • #13
                          I think Dave Biggs method could be expanded to type into a 1-character text box. The character could be checked against a format string and if
                          valid at the postion use CONTROL GET TEXT and then CONTROL SET TEXT adding the new character. I've seen floating textboxes used
                          with grids that are read only using a similar method.

                          Comment

                          Working...
                          X