Skip to content

Use {Get,Set}WindowLongPtr() instead of a global lookup table #1

@tilkinsc

Description

@tilkinsc

Hello, I was watching your video.

It appears you created a global lookup table 'pmap' which you use to convert a hWnd into muCOSA specific data.

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowlongptrw
For each window, you can store a pointer into GWLP_USERDATA via SetWindowLongPtrW(hWnd, GWLP_USERDATA, LONG_PTR);.

Quote,
Certain window data is cached, so changes you make using SetWindowLongPtr will not take effect until you call the SetWindowPos function.

// window creation/whenever you feel like it
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) muCOSA);
SetWindowPos(hWnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);

...

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static muCOSA_struct window = NULL;
    window = (muCOSA_struct*) GetWindowLongPtr(hWnd, GWLP_USERDATA);
    ....
}

This is a game changer in how your API handles.

Excited to see where your API takes you, as I am unifying linux/mac/windows for rendering but exposing the OS specific stuff while I am at it under a higher and lower order library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions