Get input from textbox

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?
Use the GetDlgItemtext function.
It doesn't look like it. How do I do it?
1
2
char* string;
GetDlgItemText(hwnd, 123,  string);
Okay thanks, I'll try that out.
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
It doesn't matter where it is.
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)...
The search would be in the form of... ?
Search?... How about looking into the control library and look up for the edit box´s messages?!?...
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.
There are messages , that will be sent to the parent window´s window procedure...
Yes, but there are none that are sent when the text changes. If you don't believe me, look at MSDN.
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
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.