I'm hanging on to my edit control window handle and calling GetWindowText every time I get a WM_COMMAND with EN_CHANGE on the parent window
From there I don't get any reasonable value back. It's just an empty string.
How the heck do I get the text from an edit control if not with GetWindowText?
Why doesn't the code in what I tried work?
What I have tried:
static LRESULT CALLBACK WindowProcGpio(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
if(uMsg==WM_CREATE) {
gpio_t& g = *(gpio_t*)((LPCREATESTRUCT) lParam)->lpCreateParams;
SetWindowLongPtrW(hWnd,GWLP_USERDATA,(LONG_PTR)&g);
HWND hwnd_st_u, hwnd_ed_u;
int x, w, y, h;
y = 10; h = 20;
x = 10; w = 50;
hwnd_st_u = CreateWindowW(L"static", L"ST_U",
WS_CHILD | WS_VISIBLE | WS_TABSTOP,
x, y, w, h,
hWnd, (HMENU)(501),
(HINSTANCE) GetModuleHandle(NULL), NULL);
SetWindowTextW(hwnd_st_u, L"Value:");
x += w; w = 60;
hwnd_ed_u = CreateWindowW(L"edit", L"",
WS_CHILD | WS_VISIBLE | WS_TABSTOP | (WS_DISABLED*(!g.is_input()))
| ES_LEFT | WS_BORDER,
x, y, w, h,
hWnd, (HMENU)(502),
(HINSTANCE) GetModuleHandle(NULL), NULL);
wchar_t val[64];
if(g.value==HIGH) {
wcscpy(val,L"HIGH");
} else if(g.value==LOW) {
wcscpy(val,L"LOW");
} else {
_itow(g.value,val,10);
}
SetWindowTextW(hwnd_ed_u, val);
g.hwnd_text = hwnd_ed_u;
}
if(uMsg==WM_COMMAND) {
if(HIWORD (wParam) == EN_CHANGE) {
uint8_t gpio = GetWindowLongPtrW(hWnd,GWLP_USERDATA);
wchar_t sz[1024];
gpio_t& g = gpios[gpio];
GetWindowTextW(g.hwnd_text,sz,sizeof(sz)/sizeof(wchar_t));
char ssz[1024];
GetWindowTextA(g.hwnd_text,ssz,sizeof(ssz));
Serial.print(ssz);
Serial.print("\r\n");
sz[63]=0;
if(0==wcsicmp(sz,L"LOW")) {
g.value=LOW;
} else if(0==wcsicmp(sz,L"HIGH")) {
g.value=HIGH;
} else {
size_t l = wcslen(sz);
bool isnum = true;
for(int i = 0;i<l;++i) {
if(!iswdigit(sz[i])) {
isnum = false;
break;
}
}
if(isnum) {
g.value = _wtoi(sz);
}
}
}
return 0;
}
if (uMsg == WM_CLOSE) {
gpio_t& g = *(gpio_t*)GetWindowLongPtrW(hWnd,GWLP_USERDATA);
g.hwnd_text = NULL;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}