The handle in WM_CREATE
I would like to use the handle of CreateWindow in WM_CREATE outside of WM_CREATE to update the picture in the listbox but i get
error 1400 Invalid window handle.
hwndImage = CreateWindowEx(0, WC_LISTVIEW,
TEXT(""), WS_CHILD | WS_VISIBLE,
0, 0, width, height,
(HMODULE) GetWindowLongPtr(hwnd, GWLP_HINSTANCE),
hWnd_Image2 = hwndImage;
What I usually do is make a global array of window handles and assign into it from the CreateWindow() calls. I also save the HINSTANCE parameter from the WinMain globally. It saves a lot of time and code figuring these things out on the fly.
HINSTANCE PgmInst; // global instance handle
HWND Wind; // global window handles
// main window
Wind = CreateWindowEx(WS_EX_CONTROLPARENT | WS_EX_APPWINDOW,
RMC_CLASS,L"Remote Media Client",
WS_TILED | WS_SYSMENU | WS_MINIMIZEBOX,// | WS_VISIBLE,
Wind = CreateWindow(L"BUTTON",L" Server ",
WS_CHILD | WS_VISIBLE |
Wind = CreateWindow(L"COMBOBOX",NULL,
WS_CHILD | WS_VISIBLE | WS_TABSTOP |
CBS_DROPDOWNLIST | CBS_SORT,
If you use the WS_CHILD style when creating a window then the HMENU param should be the ID# of the window (cast to a HMENU).
This means you do not have to save all the HWNDs but can use GetDlgItem() to retrieve the HWND as required (works with any child, not just controls).
You should not use a NULL HMENU param when creating a control/window with the WS_CHILD style.
Windows/dialogs with multiple controls with the same ID (apart from static controls) may experience undefined behaviour (as the ID number may be used to identify which child control notified the parent about some event).
Great! Thanks a lot CommonTater and Novacain!