dimanche 26 juillet 2015

Direct2D desktop template window class based on ATL's CWindowImpl

Kenny Kerr in his tutorials (part1, part2) on Direct2D shows how to make a simple 2D animated clock and uses the following classes hierarchy:

//Desktop window class based on ATL's CWindowImpl
template <typename T> struct DesktopWindow :
CWindowImpl<DesktopWindow<T>, CWindow, CWinTraits<WS_OVERLAPPEDWINDOW | WS_VISIBLE>>
{
    // code here, including:
    void Run() {}
};

//ClockSample class which further extends DesktopWindow
template <typename T> struct ClockSample : T
{
    //code here
};

//SampleWindow class which is empty and is needed, as far as I understand,
//to, so to speak, "untemplate" ClockSample template
struct SampleWindow : ClockSample<DesktopWindow<SampleWindow>>
{
    //empty
};

//main function
int __stdcall wWinMain(HINSTANCE, HINSTANCE, PWSTR, int)
{
    SampleWindow window;
    window.Run();
}

I didn't include actual code, because it's huge and is irrelevant for the question.

struct SampleWindow : ClockSample<DesktopWindow<SampleWindow>> - I have difficulties in understanding which class inherits from which and what here? SampleWindow inherits from ClockSample and then there is again SampleWindow which looks like a circular reference to me? I would be glad if anybody could explain in simple words what actually is going on here.

Aucun commentaire:

Enregistrer un commentaire