Thread: EDIT box int?(PLEASE ANSWER)

  1. #1
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Question EDIT box int?(PLEASE ANSWER)

    I have an edit box. I need to know how to getan int from the box. I know GetDlgItemInt is only for Dialog Boxes. I can't find a GetWindowInt cause I don't think there is one. What function gets an int from an EDIT box?
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: [email protected]

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  2. #2
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    If you're absolutely sure the user will enter an integer, you could fetch the data as you regularly would with GetWindowText() and convert the resulting text to a number with _atoi().
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Set the property on the EDIT to number only to ensure only numbers are entered.
    If using VC resource editor, get the properties of the EDIT, select STYLES. Find the NUMBER check box, should be near the MULTILINE.

    >>I know GetDlgItemInt is only for Dialog Boxes
    No it's not. It will work with any edit or static control just as GetDlgItemText() will. Validate the input with isdigit()

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    17
    Sir,

    I have tried GetDlgItemInt(int j) to get the data as integer from the dialog box but it is not working. I am using Microsoft VC++.

    Help

    juhi

  5. #5
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    GetDlgItemInt takes 4 parameters -

    GetDlgItemInt(YourWindowHWND,EditBoxID,successBOOL ,signBOOL);

    and returns the integer if successful.
    zen

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    As Zen says

    iEditContents= GetDlgItemInt(hWndofDialog, ID_OF_EDIT, bGoodRead, bSignedInt);

    'hWndofDialog' is the HWND returned when you created the dialog or window.

    ID_OF_EDIT is the int ID you gave the edit control when you made it in the resource editor or the element cast as the hmenu if you created it on the fly ie (HMENU)ID_OF_EDIT

    bGoodRead is only needed if you are testing for errors.

    bSignedInt will be FALSE unless you need negative values from the edit. eg if bSignedInt==FALSE then iEditContents must be >=0
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating an Edit Box (Subclassing)
    By csonx_p in forum Windows Programming
    Replies: 9
    Last Post: 05-05-2008, 06:36 AM
  2. Replies: 9
    Last Post: 02-13-2008, 02:59 PM
  3. edit box
    By beene in forum Windows Programming
    Replies: 3
    Last Post: 11-11-2006, 04:40 AM
  4. How to program a "back" button with MFC
    By 99atlantic in forum Windows Programming
    Replies: 3
    Last Post: 04-26-2005, 08:34 PM
  5. Edit box with automatic scrollbars?
    By SMurf in forum Windows Programming
    Replies: 3
    Last Post: 04-04-2002, 11:24 PM