Repository: libsdl-org/SDL
File: src/tray/windows/SDL_tray.c (C)

Code before:
    void* p = SDL_GetPointerProperty(g, SDL_PROP_TRAY_CLEANUP, NULL);
    if (p) {
        return true;
    }

    WNDCLASSEX wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.hCursor = NULL;
    wcex.hIcon = NULL;
    wcex.hIconSm = NULL;
    wcex.lpszMenuName = NULL;
    wcex.lpszClassName = className;
    wcex.style = 0;
    wcex.hbrBackground = NULL;
    wcex.lpfnWndProc = TrayWindowProc;
    wcex.hInstance = NULL;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;

    if (!RegisterClassEx(&wcex)) {
        return SDL_SetError("Couldn't register tray class");
    }

    SDL_SetPointerPropertyWithCleanup(g, SDL_PROP_TRAY_CLEANUP, (void*)wcex.lpszClassName, SDL_PropTrayCleanupCb, NULL);
    return true;
}

SDL_Tray *SDL_CreateTray(SDL_Surface *icon, const char *tooltip)
{
    if (!SDL_IsMainThread()) {
        SDL_SetError("This function should be called on the main thread");
        return NULL;
    }

    SDL_Tray *tray = (SDL_Tray *)SDL_calloc(1, sizeof(*tray));

    if (!tray) {
        return NULL;
    }

    tray->menu = NULL;
    if (!SDL_RegisterTrayClass(TEXT("SDL_TRAY"))) {
        SDL_SetError("Failed to register SDL_TRAY window class");
        return NULL;
    }
    tray->hwnd = CreateWindowEx(0, TEXT("SDL_TRAY"), NULL, WS_OVERLAPPEDWINDOW,
                                CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, NULL, NULL);

    WIN_UpdateDarkModeForHWND(tray->hwnd);


Review comment (suggestion):
```suggestion
    SDL_PropertiesID props = SDL_GetGlobalProperties();
    if (!props) {
        return false;
    }
    if (SDL_GetPointerProperty(props, SDL_PROP_TRAY_CLEANUP, NULL) != NULL) {
        return true;
    }

    WNDCLASSEX wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.hCursor = NULL;
    wcex.hIcon = NULL;
    wcex.hIconSm = NULL;
    wcex.lpszMenuName = NULL;
    wcex.lpszClassName = className;
    wcex.style = 0;
    wcex.hbrBackground = NULL;
    wcex.lpfnWndProc = TrayWindowProc;
    wcex.hInstance = NULL;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;

    if (!RegisterClassEx(&wcex)) {
        return SDL_SetError("Couldn't register tray class");
    }

    SDL_SetPointerPropertyWithCleanup(props, SDL_PROP_TRAY_CLEANUP, (void*)wcex.lpszClassName, SDL_PropTrayCleanupCb, NULL);
    return true;
```

Code after:
    }
    if (SDL_GetPointerProperty(props, SDL_PROP_TRAY_CLEANUP, NULL) != NULL) {
        return true;
    }

    WNDCLASSEX wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.hCursor = NULL;
    wcex.hIcon = NULL;
    wcex.hIconSm = NULL;
    wcex.lpszMenuName = NULL;
    wcex.lpszClassName = className;
    wcex.style = 0;
    wcex.hbrBackground = NULL;
    wcex.lpfnWndProc = TrayWindowProc;
    wcex.hInstance = NULL;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;

    if (!RegisterClassEx(&wcex)) {
        return SDL_SetError("Couldn't register tray class");
    }

    SDL_SetPointerPropertyWithCleanup(props, SDL_PROP_TRAY_CLEANUP, (void *)wcex.lpszClassName, SDL_PropTrayCleanupCb, NULL);
    return true;
}

SDL_Tray *SDL_CreateTray(SDL_Surface *icon, const char *tooltip)
{
    if (!SDL_IsMainThread()) {
        SDL_SetError("This function should be called on the main thread");
        return NULL;
    }

    SDL_Tray *tray = (SDL_Tray *)SDL_calloc(1, sizeof(*tray));

    if (!tray) {
        return NULL;
    }

    tray->menu = NULL;
    if (!SDL_RegisterTrayClass(TEXT("SDL_TRAY"))) {
        SDL_SetError("Failed to register SDL_TRAY window class");
        return NULL;
    }
    tray->hwnd = CreateWindowEx(0, TEXT("SDL_TRAY"), NULL, WS_OVERLAPPEDWINDOW,
                                CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, NULL, NULL);

    WIN_UpdateDarkModeForHWND(tray->hwnd);