Restricting input to an edit control

This is a discussion on Restricting input to an edit control within the Windows Programming forums, part of the Platform Specific Boards category; I can't believe it, but I'm having trouble restricting input to an edit control. I only want the user to ...

  1. #1
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401

    Restricting input to an edit control

    I can't believe it, but I'm having trouble restricting input to an edit control. I only want the user to be able to enter in certain keys, but placing the restriction in WM_KEYDOWN didn't work:

    Code:
    	case WM_KEYDOWN:
    		if (wParam!='I')
    			if (wParam!='V')
    				if (wParam!='X')
    					if (wParam!='L')
    						if (wParam!='C')
    							if (wParam!='M')
    								if (wParam!='~')
    									return 0;
    		break;
    The user can still enter anything into the edit control. How can I fix this problem?
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Don't worry, I put the restriction code in WM_CHAR and now it works fine. I feel so.... n00bish.

    Code:
    	case WM_CHAR:
    		if (wParam!='I')
    			if (wParam!='V')
    				if (wParam!='X')
    					if (wParam!='L')
    						if (wParam!='C')
    							if (wParam!='M')
    								if (wParam!='~')
    									return 0;
    
    		break;
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  3. #3
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Dude, use &&
    Away.

  4. #4
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Probably works out to the same assembly commands confuted. But anyway, is this what you mean?

    Code:
    	case WM_CHAR:
    		if (wParam!='I' &&
    		wParam!='V' &&
    		wParam!='X' &&
    		wParam!='L' &&
    		wParam!='C' &&
    		wParam!='M' &&
    		wParam!='~')
    		    return 0;
    
    		break;
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  5. #5
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Yes, that's what I meant. I hadn't thought about it working out to the same ASM... I wonder if it does.
    Away.

  6. #6
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Well, let's consider what happens:

    My code:
    1 MOV wParam to register
    2 MOV 'I' to register
    3 JE 8
    4 MOV wParam to register
    5 MOV 'V' to register
    6 JE 8
    7 return 0; //whatever that would be in ASM
    8 break;

    Your code:
    Can't be bothered trying it but maybe it would contain a counter to check how many expressions come out TRUE or something. It might depend on the compiler, ie, your code may end up exactly the same as mine in the end.

    Who really cares though? I'll just do whichever one takes the least time to type out.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  7. #7
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Pointless post follows.

    Code:
    switch (wParam) {
    	case  'I':
    	case  'V':
    	case  'X':
    	case  'L':
    	case  'C':
    	case  'M':
    	case  '~':
    		break;
    	default:
    		return 0;
    }

  8. #8
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Yeah I guess that'd work too.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can't disable ctrl-V on a rich edit control
    By rakan in forum Windows Programming
    Replies: 1
    Last Post: 02-06-2008, 08:37 AM
  2. Help on restricting input to a numbers only (or text only)
    By BongoBob in forum C++ Programming
    Replies: 6
    Last Post: 05-14-2006, 09:32 PM
  3. Buttons + Edit Control
    By jay kay in forum Windows Programming
    Replies: 6
    Last Post: 03-09-2005, 05:36 PM
  4. Controlling an edit control
    By master5001 in forum Windows Programming
    Replies: 2
    Last Post: 10-16-2001, 04:08 PM
  5. Rich edit control example Win API
    By Echidna in forum Windows Programming
    Replies: 1
    Last Post: 09-17-2001, 03:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21