RenderedBitmap *ChmEngineImpl::CreateThumbnail(SizeI size) { RenderedBitmap *bmp = NULL; // We render twice the size of thumbnail and scale it down RectI area(0, 0, size.dx * 2, size.dy * 2); // reusing WC_STATIC. I don't think exact class matters (WndProc // will be taken over by HtmlWindow anyway) but it can't be NULL. int winDx = area.dx + GetSystemMetrics(SM_CXVSCROLL); int winDy = area.dy + GetSystemMetrics(SM_CYHSCROLL); HWND hwnd = CreateWindow(WC_STATIC, L"BrowserCapture", WS_POPUP, 0, 0, winDx, winDy, NULL, NULL, NULL, NULL); if (!hwnd) return NULL; #if 0 // when debugging set to 1 to see the window ShowWindow(hwnd, SW_SHOW); #endif SetParentHwnd(hwnd); DisplayPage(1); if (!htmlWindow || !htmlWindow->WaitUntilLoaded(5 * 1000)) goto Exit; HBITMAP hbmp = htmlWindow->TakeScreenshot(area, size); if (!hbmp) goto Exit; bmp = new RenderedBitmap(hbmp, size); Exit: DestroyWindow(hwnd); return bmp; }
virtual void OnDocumentComplete(const WCHAR *url) { if (url && *url == '/') url++; if (str::Eq(url, homeUrl)) { RectI area(0, 0, size.dx * 2, size.dy * 2); HBITMAP hbmp = hw->TakeScreenshot(area, size); if (hbmp) { RenderedBitmap *bmp = new RenderedBitmap(hbmp, size); tnCb->SaveThumbnail(bmp); tnCb = NULL; } uitask::Post(this); } }
virtual void OnDocumentComplete(const WCHAR *url) { if (url && *url == '/') url++; if (str::Eq(url, homeUrl)) { RectI area(0, 0, size.dx * 2, size.dy * 2); HBITMAP hbmp = hw->TakeScreenshot(area, size); if (hbmp) { RenderedBitmap *bmp = new RenderedBitmap(hbmp, size); saveThumbnail(bmp); } // TODO: why is destruction on the UI thread necessary? uitask::Post([=] { delete this; }); } }