int X = textbox value

hello everyone,

i am trying to create a win32 application program
I have created a textbox in a dialogbox and now i want to introduce a variable 'X' which will take the value of the textbox which will be provided by the user. Then X is to be used by the code.

Can you please tell me how to equate 'X' with the textboc value?
thank you!
When you create the text box make sure to keep a variable to hold the hwnd of it.
Once you have that to get the value you can use
GetWindowTextLength ( http://msdn.microsoft.com/en-us/library/ms633521%28v=VS.85%29.aspx ) to find the length of the text
Assign a buffer to that size, then use
GetWindowText ( http://msdn.microsoft.com/en-us/library/ms633520%28VS.85%29.aspx )
to get the actual text & assign it into a buffer.
After that you can use atoi ( http://www.cplusplus.com/reference/clibrary/cstdlib/atoi/ ) to convert string to int.

Here is a little bit of code that I used to test it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
        case WM_CREATE:
        {
             HWND textBox = CreateWindowEx(0, "EDIT", "123", WS_CHILD|WS_VISIBLE, 15, 15, 100, 35, hwnd, NULL, NULL, NULL);
             char* buffer;
             int length = GetWindowTextLength( textBox );
             ++length;
             buffer = (char*) malloc( length );
             GetWindowText( textBox, buffer, length );
             MessageBox(hwnd, buffer, "String Value", 0);
             int numValue = atoi( buffer );
             if( numValue == 123 )
             {
               MessageBox(hwnd, "it worked", "Integer Value", 0);
             }
             break;
        }
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}
Topic archived. No new replies allowed.