So, I am wondering, how do you save the input in a text field. For instance, say I want to have the user enter two values in the window, and then add them up and display them. How would I do that? WM_COMMAND?
There are a couple steps involved here. It takes two or vthree lines of code. To put text into an edit control you need the HWND of the edit control. When you created the edit control the HMENU parameter was the Control ID you assigned to the edit control such as ...
You can retrieve the HWND from the return of the original CreateWindow() call with the GetDlgItem() Api function. You feed into that function the HWND of the 'parent' of the edit control, i.e., possibly your main window, and the Control ID of the edit bcontrol for which you want the text and its HWND ...
1 2 3
TCHAR szBuffer[]=_T("Here Is Text I Want To Put In Edit Control");
HWND hEdit=GetDlgItem(hMainWindow, IDC_MY_TEXT_BOX_1);
SetWindowText(hEdit,szBuffer);
To retrieve text from an edit control its about the reverse of that. First get the HWND of the edit control from which you want the text. Then create a text buffer into which the call to GetWindowText() will write the text string...
Now, you can refine that by first calling GetWindowTextLen() to first determine how much text is there, and program accordingly. But that may involve memory allocations and a bit more complexity.
Yes. Very handy and easy to use little function. No need to ever make globals out of child window controls, because control ids serve as proxies for them. If you know the parent HWND and the child window identifier, you can get the HWND of the child window control and manipulate it.