As Rick York suggested numbering the windows with SetWindowLongPtr () seems to be a good solution if you write a consecutive number after creating the window.
Insted of using a MessageBox it is better to use the StatusBar:
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hInst = hInstance;
HWND hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
if (!hWnd) {
return FALSE;
}
statusbar = CreateStatusWindow(WS_CHILD | WS_VISIBLE, _T("x"), hWnd, IDM_STATUS);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
void ShowWindowNumber(HWND hWnd)
{
size_t x = GetWindowLongPtr(hWnd, GWLP_USERDATA);
if ((x>=0) && (x < UserData.size())) {
wchar_t meChar[20] = L"";
wsprintf(meChar, _T("%ld"), x);
SendMessageW(statusbar, SB_SETTEXT, 0, (LPARAM)meChar);
}
}
case WM_CREATE:
{
SetWindowLong(hWnd, GWL_EXSTYLE,
GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED);
SetLayeredWindowAttributes(hWnd, RGB(255, 255, 255), 220, LWA_ALPHA);
Data mydata;
LONG_PTR chk, wn;
UserData.push_back(mydata);
wn = (LONG_PTR)UserData.size() - 1;
chk = SetWindowLongPtrA(hWnd, GWLP_USERDATA, wn);
but1 = CreateWindowW(L"BUTTON", L"OK",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
10, 10, 100, 100, hWnd, (HMENU)IDC_BUTTON1,
(HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE), NULL);
UserData.push_back(mydata);
wn = (LONG_PTR)UserData.size() - 1;
chk = SetWindowLongPtrA(but1, GWLP_USERDATA, wn);
}