Where Did SetWindowSubclass Come From?

Off and on for the past 4 years, I’ve been writing my own version of a Windows, C++ windowing library. Why write my own? Mainly, I just wanted to better understand the low level Windows API and thought I’d learn it by creating my own windowing library. I also wanted to better understand C++ templates which I use extensively to avoid most virtual calls associated with passing events down an object hierarchy.

My first implementations of this library were always thunk based. I got this idea from Microsoft’s ATL/WTL library and from reading various discussions like this. Thunking does some assembly level magic and allows me to redirect a static WNDPROC invocation to an object’s instance method.

It turns out that thunking isn’t exactly revered or thought to be very safe :) but it worked and it was clever so I stuck with it. Well, late last year I stumbled across SetWindowSubclass and realized I could now, via the Windows API, achieve the same results that thunking gave me. Unlike SetWindowLongPtr, SetWindowSubclass doesn’t preclude end users from using GWL_USERDATA for their own purposes.

My library was always intended to be proprietary since I thought there was some value in getting my thunk to work so consistently but with this little change, I’m considering open sourcing it under the Apache 2.0 license. It may take me a while to clean it up but hopefully I’ll create a repo on github and commit it later this year.

Loading...