FindWindow()
finds top-level windows, not child windows.
If you really do want to look up a child window by name, you can use the FindWindowEx()
function, but using the ID is usually more efficient.
The function that does this is GetDlgItem()
. This looks up child windows by their ID, which you provide when you create them.
HWND hwB1 = GetDlgItem(hWnd, IDC_BUTTON1);
hWnd
is the parent window, and IDC_BUTTON1
is the ID.
Another alternative is to simply store the window handle that's returned when you create the child window - hWndButton
in your code example - and then you don't need to look it up at all.