The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: timertik on May 19, 2008, 06:40:23 AM

Title: Limit chars in an editbox
Post by: timertik on May 19, 2008, 06:40:23 AM
I need help limiting the input aloud in an edit box I want 8 chars but if it goes over 8 I still want to keep the ones that are in the box already.
I thought about this one for a long time and I actually have no clue how to do this.  :eek
thank you for your time
Title: Re: Limit chars in an editbox
Post by: hutch-- on May 19, 2008, 06:59:15 AM
timertik,

The trick is to subclass the edit control so you can filter, limit or modify what is being typed and what is already in the control in terms of text. A subclass procedure is like an intercept to the underlying message handling procedure for a control and there is a tool in the masm32 project for creating control subclass procedures.

Once you have the subclass up and running you would process the WM_CHAR message while being able to access the entire text in the control. If its already the maximum you want you don't acept the keystroke. You would normally allow a backspace so that the text can be reduced if it has reached the maximum.
Title: Re: Limit chars in an editbox
Post by: Tedd on May 19, 2008, 11:32:26 AM
Or, just send the EM_SETLIMITTEXT message to the edit control.
Title: Re: Limit chars in an editbox
Post by: timertik on May 20, 2008, 01:59:13 AM
Its not working :/
can you tell me what I have done wrong
.elseif message==EDIT1
invoke SendMessage,hwnd,EM_SETLIMITTEXT,8,0



I figured it out  :U
invoke GetDlgItem, hwnd, 1008
        mov hWndofEdit, eax
       

        invoke SendMessage, hWndofEdit, EM_SETLIMITTEXT, amount, 0

thanks

just when I use that the text already entered or entered by the app its self doesnt get limited and I dont understand the first post well enough to get it to work I hope to hear something soon thank you both

I have the subclass but I dont know how to use WM_CHAR correctly and msdn wasnt very helpful either  :boohoo:
if you could help me out when you have the time I would appreciate it , thanks
     
Title: Re: Limit chars in an editbox
Post by: hutch-- on May 20, 2008, 07:30:45 AM
timertik,

There is an example in the early example code in the masm32 project called FILTINPT that shows how to subclass a number of edit controls. The first method will be closer to what you need but you will be testing the length of the string not its content.
Title: Re: Limit chars in an editbox
Post by: timertik on May 20, 2008, 04:33:11 PM
thanks I will check it out  :U