CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: general

  1. #1
    Join Date
    Nov 1999
    Posts
    1

    general

    i want only numbers to be entered in my text box and must not allow any thing to be entered into it.
    how can i do it.
    i am not getting with like operator in keydown event.
    please help me

    -srikanth


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: general

    There is only ONE truly reliable solution to this that I know of:
    use the SetWindowLong API and set the GWL_STYLE to ES_NUMBER.
    Other approaches (trapping keyup, keypress and so on), although widely used, do not work in all cases, because the usually fail to trap Paste operations via Ctrl+V and Shift+Ins or the context menu.


  3. #3
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: general

    Hi Lothar,

    ES_NUMBER for GWL_STYLE of a Text box is defined only for WINVER > 0x400. DOes that mean it works on 95? I dont think so. It sure works on WIn nt 4.0 SP3 through. I tried.

    As an aside:
    Whay is that this code doesn't work for setting the text box read only??

    lStyle = GetWindowLong(txtboxHwnd, GWL_STYLE)
    lStyle = lStyle Or ES_READONLY
    ' lrtn = SetWindowLong(txtboxHwnd, GWL_STYLE, lStyle) ' DOESnt work
    lrtn = SendMessageLong(txtboxHwnd, EM_SETREADONLY, 1, 0) ' Only works??




    Any ideas?

    RK

  4. #4
    Join Date
    May 1999
    Posts
    3,332

    Re: general

    some styles are only interpreted when the control is created. ES_READONLY is one of them.
    from the docs:
    "To change this style after the control has been created, use the EM_SETREADONLY message"


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured