Handle the WM_CREATE message, which is a C based Constructor call of the window being created/constructed, and the HWND parameter will be the HWND of the window being created. In other words, when you make a CreateWindowEx() call in WinMain(), when you receive the WM_CREATE message in WNDPROC(), that function call will be executing within the CreateWindowEx() call, and you'll get the HWND of the window being created before the CreateWindowEx() call in WinMain() returns.