-
Text Box without Dialogs
what if I make a window, and then a TextBox in it, but this time not by creating it in a Dialog, but creating a child window with the EDIT class. The textbox looks fine, but. how do I get what text does it contain?
I haven't made a program yet, and I don't micd using C or C++, I just want to know how do you do it.
Oskilian
-
Use GetDlgItemText(). As the dlg box handle use the parent window's handle. Even though it's not a dlg box it will work.
-
When you create the EDIT you specify an ID number as the HMENU param.
Msg's are sent to the callback of the parent (as specified by the HWNDPARENT param).
Use hash defines
ie
#define IDC_CHILD_EDIT 10001
Then use IDC_CHILD_EDIT in both the CreateWindow() and WM_COMMAND switch in the parents callback.
-
that's right, but you don't use GetDlgItemText() becuase you're not using a dialog box.
just use:
int GetWindowText(HWND window, LPTSTR buffer, int bufferSize);
good luck
U
-
to Urador:
I think, you may use GetDlgItemText as well, because dialog is a regular window.
For GetDlgItemText, you specify handle of dialog (as a parent window) and ID of child control.
For GetWindowText you must provide handle of child control.
You may choose the method, which is more suitable for you.
-
GetWindowText. that was what I was looking for, thanks!
I am not planning to do any program with that yet, I was just curious. Thanks!
Oskilian
-
Golem: Yes, a dialog is a window, but a window isn't necessarily a dialog. Since Oskilian said that he had a window (not a dialog) and that he had created the edit box using CreateWindow() (hence he would have a handle to the window itself) he would be much better off using GetWindowText..... GetDlgItemText in this situation is overkill..
To my understanding
GetDlgItemText calls GetDlgItem, and then GetWindowText anyway... so it's also quicker.
Oskilian: GetWindowText() is exactly what you need :D