Get input from textbox

Jun 5, 2010 at 11:19pm
I created a TextBox in Win32 using the CreateWindowEx function like so:

1
2
3
4
5
6
	// Creating textbox for input
	hwnd_ed_1 = CreateWindowEx(WS_EX_CLIENTEDGE, "edit", "Line one",
                              WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_LEFT,
                              CW_USEDEFAULT, CW_USEDEFAULT, 200, 24,	// x, y, w, h
                              hwnd, (HMENU)(123),
                              (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);


How can I get input from this?
Jun 5, 2010 at 11:28pm
Use the GetDlgItemtext function.
Jun 6, 2010 at 12:03am
It doesn't look like it. How do I do it?
Jun 6, 2010 at 2:03am
1
2
char* string;
GetDlgItemText(hwnd, 123,  string);
Jun 6, 2010 at 4:03pm
Okay thanks, I'll try that out.
Jun 6, 2010 at 4:56pm
This should be in a switch case statement shouldn't it? This is for getting input from MessageBox's anyways. >.<

1
2
3
4
5
6
7
8
9
10
11
12
13
char* line;

/* ... */

// Creates textbox for input
hwnd_ed_1 = CreateWindowEx(WS_EX_CLIENTEDGE, "edit", "Line one",
	WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_LEFT,
	CW_USEDEFAULT, CW_USEDEFAULT, 200, 24,	// x, y, w, h
	hwnd, (HMENU)(123),
	(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);

GetDlgItemText(hwnd, 123, line, 100);
MessageBox(NULL, line, "Stuff", MB_ICONINFORMATION | MB_OK);
Last edited on Jun 6, 2010 at 4:58pm
Jun 6, 2010 at 6:01pm
It doesn't matter where it is.
Jun 6, 2010 at 7:35pm
You should check for any change of text in this edit box...

THere is an appropriate WM for this... (I dont remember at the moment - check the msdn)...
Jun 6, 2010 at 11:26pm
The search would be in the form of... ?
Jun 7, 2010 at 7:01am
Search?... How about looking into the control library and look up for the edit box´s messages?!?...
Jun 7, 2010 at 3:17pm
There are no messages that are sent when the edit control's data changes. I recommend that you just add a button to your form, then display the message box when you click it.
Jun 7, 2010 at 4:32pm
There are messages , that will be sent to the parent window´s window procedure...
Jun 7, 2010 at 5:42pm
Yes, but there are none that are sent when the text changes. If you don't believe me, look at MSDN.
Jun 7, 2010 at 5:49pm
Bet on?!... I don´t want to go to the MSDN again... But since You are willing to do so, check for EN_UPDATE and EN_CHANGE :P...

EDIT: Notifications are Window Messages, too... (EN_xxx)
Last edited on Jun 7, 2010 at 5:50pm
Jun 7, 2010 at 7:44pm
Got it:

1
2
3
4
5
6
7
8
9
10
11
12
// Creates textbox for input
hwnd_ed_1 = CreateWindowEx(WS_EX_CLIENTEDGE, "edit", "Line one",
	WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_LEFT,
	CW_USEDEFAULT, CW_USEDEFAULT, 200, 24,	// x, y, w, h
	hwnd, (HMENU)(101),
	HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);

// char array to hold the text from the textbox
char szInput[MAX_PATH];

// Obtains input from the textbox and puts it into the char array
GetWindowText(GetDlgItem(hwnd, 101), szInput, MAX_PATH);


Thanks everyone for your effort!
Topic archived. No new replies allowed.