Thread: Win32 Text Field For Input

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    3

    Question Win32 Text Field For Input

    Hello, I am currently programming a Win32 application and I need a "text field" or a "text box" that the user can type in a number to. I will need a few of these so a example would be great.

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Try the windows programming section of the forum.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    .. and moved!
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Jul 2010
    Posts
    3
    Sorry for posting in the wrong section. I didn't see the Windows programming section..

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Use the resource editor to create the Editbox OR use CreateWindowEx() to create one at run time. If you have a lot I suggest the resource editor.

    Read the text with GetDlgItemInt() or GetDlgItemText() and atoi().

    Check some recent threads for code.
    "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

  6. #6
    Registered User
    Join Date
    Aug 2010
    Location
    New York
    Posts
    11

    Smile

    Code:
    HWND hEdit =CreateWindowEx(WS_EX_CLIENTEDGE,"EDIT",
    "Type Text Here",WS_CHILD|WS_VISIBLE|WS_HSCROLL|ES_AUTOHSCROLL,
    0,0,100,20,hwnd,(HMENU)SOME_KIND_OF_ID,GetModuleHandle(NULL),
    NULL);
    put this code in the WM_CREATE part of your WndProc. the code
    above makes a TextBox at x0 and y0 with a width of 100 and a
    height of 20. the SOME_KIND_OF_ID should be defined somewhere
    in your program like this:

    Code:
    #define SOME_KIND_OF_ID 50
    the WS_HSCROLL and ES_AUTOHSCROLL can be removed (they make
    an horizontal scroll bar). 'hwnd' is the window to put this
    control on. if any questions, ask please.

    Cheers, ComputerWarrior.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Detecting Edit Control Text
    By yoonkwun in forum Windows Programming
    Replies: 2
    Last Post: 07-12-2009, 08:48 AM
  2. DirectX | Drawing text
    By gavra in forum Game Programming
    Replies: 4
    Last Post: 06-08-2009, 12:23 AM
  3. Input a Hex number and output hex number to a text field
    By zoobaby in forum C++ Programming
    Replies: 4
    Last Post: 05-12-2009, 11:26 AM
  4. Replies: 3
    Last Post: 05-25-2005, 01:50 PM
  5. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM