May 12, 2024, 03:05:25 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Masked Editbox example

Started by Guilect, August 14, 2009, 08:07:33 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Guilect

If I understood Haim correctly he was looking for a control like this.
REM Masked EditBox
REM by Guilect

' define a window variable
DEF w1 as WINDOW

' Editbox Constants
Const EM_SETPASSWORDCHAR = 0xCC
Const ES_PASSWORD = 0x20
Const ES_CENTER = 0x1

Const WS_BORDER = 0x800000
Const WS_CHILD = 0x40000000
Const WS_VISIBLE = 0x10000000

' open the window
OPENWINDOW w1,0,0,450,250,@MINBOX|@MAXBOX|@SIZE,NULL,"Simple Password Example - Type in the Editbox",&main

' create and editbox and set its style to password(masked)
CONTROL w1,@EDIT,"",56,100,80,20,WS_VISIBLE | WS_CHILD | WS_BORDER | ES_PASSWORD | ES_CENTER, 1
SETFOCUS w1, 1

' set its control event
OnControl w1,1,@ENCHANGE,&DoEditChanged

' when w1 = 0 the window has been closed
WAITUNTIL w1 = 0
END

' every time there is a message for our window
' the operating system will GOSUB here
SUB main
    IF @MESSAGE = @IDCLOSEWINDOW
        REM closes the window and sets w1 = 0
        CLOSEWINDOW w1
    ENDIF
RETURN
ENDSUB

SUB DoEditChanged(),INT
Move w1, 0,0
print w1,"                      "
Move w1, 0,0
       print w1,GetControlText(w1,1),
       Return 0
ENDSUB

Ionic Wind Support Team

Actually no, and you can set the password style (ES_PASSWORD) of an edit control to do what your showing automatically.  And you can also set the character the edit control uses instead of the typed password with EM_SETPASSWORDCHAR

What haim is asking for is a custom control where the user can supply a mask to restrict character input to conform to the mask itself.  Such as a date entry where you would supply a mask of "##/##/##" and the edit control with automatically jump to the next field upon proper entry.  More complex would be to provide a range for each field of the mask.

Which requires subclassing the control, and redefining the default behavior of the window process of the control.

They don't usually ask me to create something that's easy to do Guilect, and your reply should have gone in the thread where it was asked.

Thanks,
Paul.
Ionic Wind Support Team

Duffer

August 14, 2009, 10:45:15 PM #2 Last Edit: August 14, 2009, 10:52:13 PM by BriceManuel
Paul took his nasty pills today  :(

Guilect was just trying to help.

LarryMc

I don't see anything that appears "nasty"  ;)

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

Not nasty at all lol.  Just factual, haim might not be looking here so it's polite to post the reply in the thread where the question was asked.  Or at least ask to clarify.

Jeex, I am not always in a bad mood Brice, just 47.593% of the time ;)
Ionic Wind Support Team

Duffer

QuoteThey don't usually ask me to create something that's easy to do Guilect, and your reply should have gone in the thread where it was asked.

^  That is the line I was referring to  ^

A case of something not being taken the way it was intended  ;)

I know Guilect from outside this community.  Was just sticking up for him the same way I stick up for Paul on other forums, even when it leads to me being banned.

Ionic Wind Support Team

Don't really see how you could take that the wrong way, but whatever  ::) 

Later,
Paul.
Ionic Wind Support Team

Haim

Thanks to all for your responses.
The conrol i referred to is, as Paul understood, a general purpose masked edit control, to allow for input of dates, telephone numbers and various other formatted input strings.
I think that additional control would be welcome by the users and make the languages even more attractive.
Haim


Guilect

August 15, 2009, 04:30:16 PM #8 Last Edit: August 15, 2009, 06:17:58 PM by Paul Turley
Sorry,
I just figured that code for an Emergence Basic GUI control would go in the Emergence Basic GUI section of the forum.

It is good for this code to be properly categorized here for others to see it, even when they are not logged in, and to be able to find it again in the future.

I did not ask for any further explaination of the control at the time because I believed that this was what was being looked for.
I see now I was mistaken and apologize.

The control that Paul describes would indeed be very useful.

mrainey

August 15, 2009, 05:27:02 PM #9 Last Edit: August 15, 2009, 06:49:37 PM by Larry McCaughn
Here's some code I saved way back when (Paul's?).


' Subclass the edit control an process @IDCHAR messages yourself, only allowing the ones allowed to be passed on to the default handler...

' This should get you started

' Edit Box check entry
DEF txt as string
DIALOG d1
CREATEDIALOG d1,0,0,280,150,@CAPTION|@SYSMENU|@BORDER,0,"Type in Amount $",&diaghandler
CONTROL d1,@STATIC,"Amount $",44,30,70,20,0x5000010B,2
CONTROL d1,@EDIT,"",100,26,97,20,0x50800000,3
CONTROL d1,@BUTTON,"Accept",91,75,70,20,0x50000000,4


DOMODAL d1
END

SUB diaghandler
SELECT @MESSAGE
   CASE @IDINITDIALOG
      CENTERWINDOW d1
     SubclassNumEdit(d1,3)
   CASE @IDCONTROL
        SELECT @CONTROLID
            CASE 3
               IF @NOTIFYCODE = @ENCHANGE
               ' check if the char entered in 3 is a number or a full stop
               ' otherwise drop the entry
             txt = getcontroltext(d1,3)
               ' examine each char in txt for a digit or a '.'
               ENDIF
         CASE 4
            UnSubclassNumEdit(d1,3)
            CLOSEDIALOG d1,@IDOK
         ENDSELECT         
   CASE @IDCLOSEWINDOW
     UnSubclassNumEdit(d1,3)
      CLOSEDIALOG d1,@IDOK
ENDSELECT
RETURN
ENDSUB

DECLARE IMPORT,CallWindowProcA(lpPrevWndFunc:int,hWnd:int,Msg:int,wParam:int,lParam:int),int
DECLARE IMPORT,SetWindowLongA(hWnd:int,nIndex:int,dwNewLong:int),int
DECLARE IMPORT,SetPropA(hwnd as UINT,lpString as STRING,hData as UINT),INT
DECLARE IMPORT,GetPropA(hwnd as UINT,lpString as STRING),UINT
DECLARE IMPORT,RemovePropA(hwnd as UINT,lpString as STRING),UINT
CONST GWL_WNDPROC=-4

SUB SubclassNumEdit(parent as WINDOW,id as INT)
   hEdit = GETCONTROLHANDLE(parent,id)
   lpfn = SetWindowLongA(hEdit,-4,&numEditHandler)
   'save the old handler as a property in the edit control
   'this way we don't need any global variables
   SetPropA(hEdit,"edit_handler",lpfn)   
RETURN
ENDSUB

SUB UnSubclassNumEdit(parent as WINDOW,id as INT)
   'restore the old handler and remove the property
   hEdit = GETCONTROLHANDLE(parent,id)
   SetWindowLongA(hEdit,-4,GetPropA(hEdit,"edit_handler"))
   RemovePropA(hEdit,"edit_handler")
RETURN
ENDSUB

SUB numEditHandler(hwnd:int,uMsg:int,wParam:int,lParam:pointer),int
   SELECT uMsg
      CASE @IDCHAR
         IF ((wParam < 0x30) OR (wParam > 0x39)) AND (wParam <> ASC(".")) AND (wParam <> 0x08) THEN RETURN 1
   ENDSELECT
RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)
ENDSUB
Software For Metalworking
http://closetolerancesoftware.com

Ionic Wind Support Team

Close Mike, but only a very small portion of a masked edit control.  That is just an example of how to subclass a control and restrict characters entered.

For an example of about 1/3 of what is needed see the example program CFilterEdit.eba that comes with Emergence BASIC. Which will be my starting point for the masked edit.

Paul.

Ionic Wind Support Team