Get int from edit box

I want the int beatsperminute, which can be changed in an edit box, to be updated on button click. Any help?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 case WM_CREATE: {
				mySzInput = "30";
				hwnd_ed_1 = CreateWindowEx(WS_EX_CLIENTEDGE, "edit", mySzInput,
					WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_LEFT | ES_NUMBER,
					50, 90, 60, 30,	// x, y, w, h
					hwnd, (HMENU)(100),
					(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
				szInput[MAX_PATH] = {mySzInput[0]};
				szString = GetWindowText(GetDlgItem(hwnd_ed_1, 100), szInput, MAX_PATH);

case WM_COMMAND: {
	        	wmId    = LOWORD(wParam);
	        	wmEvent = HIWORD(wParam);
if(LOWORD(wParam) == 143){

					const HWND text_box = GetDlgItem( hwnd_ed_1, 100 );
					beatsperminute = (int)text_box;//.asInt();

				std::string test = std::to_string(beatsperminute);
	            	const char* testcount = test.c_str();
	                MessageBox(hwnd, testcount, "Version info", MB_ICONINFORMATION);
Maybe

1
2
3
char str[100];
GetWindowText(hwnd, str, sizeof str);
int n = atoi(str);

https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getwindowtexta
Last edited on
there is a way to attach a variable to the edit box (you may need to set the box to 'number only' ) for direct access. (Or this used to be the way to do it, its been a while).
This works for me:
1
2
3
char str[1000];
GetWindowTextA(GetDlgItem(hwnd, 100), str, GetWindowTextLength(hwnd)+1);
beatsperminute = atoi(str);
Topic archived. No new replies allowed.