33
44#include < iwcdx.h>
55
6+ #include < d3d9.h>
67#include < DxErr.h>
78#include < Shlwapi.h>
9+ #include < comdef.h>
810
911#include < algorithm>
1012#include < memory>
2729
2830struct WindowData
2931{
30- Wcdx& wcdx;
32+ IWcdx* wcdx;
3133 vector<unique_ptr<Bitmap>> images;
3234 size_t imageIndex;
3335};
@@ -76,7 +78,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpComma
7678 L" Wcdx Test" , WS_OVERLAPPEDWINDOW & ~(WS_THICKFRAME | WS_MAXIMIZEBOX),
7779 CW_USEDEFAULT, CW_USEDEFAULT, 1024 , 768 ,
7880 nullptr , nullptr , hInstance, nullptr );
79- Wcdx wcdx (window);
81+ IWcdx* wcdx = CreateWcdx (window);
8082 WindowData windowData = { wcdx };
8183 ::SetWindowLongPtr (window, GWLP_USERDATA, reinterpret_cast <LONG_PTR>(&windowData));
8284
@@ -132,15 +134,15 @@ void ShowImage(HWND window, Bitmap& image)
132134 image.GetPalette (&palette, paletteData.size ());
133135
134136 assert (palette.Count == 256 );
135- windowData.wcdx . SetPalette (reinterpret_cast <PALETTEENTRY*>(palette.Entries ));
137+ windowData.wcdx -> SetPalette (reinterpret_cast <PALETTEENTRY*>(palette.Entries ));
136138
137139 Rect imageRect (0 , 0 , image.GetWidth (), image.GetHeight ());
138140 BitmapData bits;
139141 image.LockBits (&imageRect, 0 , image.GetPixelFormat (), &bits);
140142 at_scope_exit ([&]{ image.UnlockBits (&bits); });
141143
142144 RECT updateRect = { 0 , 0 , image.GetWidth (), image.GetHeight () };
143- windowData.wcdx . UpdateFrame (bits. Scan0 , updateRect, bits.Stride );
145+ windowData.wcdx -> UpdateFrame (updateRect. left , updateRect. top , updateRect. right - updateRect. left , updateRect. bottom - updateRect. top , bits.Stride , reinterpret_cast <byte*>(bits. Scan0 ) );
144146}
145147
146148bool OnCreate (HWND window, const CREATESTRUCT& create)
@@ -152,6 +154,8 @@ bool OnCreate(HWND window, const CREATESTRUCT& create)
152154
153155void OnDestroy (HWND window)
154156{
157+ WindowData& windowData = *reinterpret_cast <WindowData*>(::GetWindowLongPtr (window, GWLP_USERDATA));
158+ windowData.wcdx ->Release ();
155159 ::CoUninitialize ();
156160 ::PostQuitMessage (EXIT_SUCCESS);
157161}
@@ -178,7 +182,7 @@ void OnRender(HWND window)
178182 return ;
179183
180184 WindowData& windowData = *reinterpret_cast <WindowData*>(::GetWindowLongPtr (window, GWLP_USERDATA));
181- windowData.wcdx . Present ();
185+ windowData.wcdx -> Present ();
182186
183187// ::PostMessage(window, WM_APP_RENDER, 0, 0);
184188}
0 commit comments