ソースコード付きの情報が無いので作った分だけ掲載

Visual Studio .NET 2003 のC++でやってみた(CHtmlViewを使ったSDIアプリの例)


void CMainFrame::OnEditCopy()

{
// TODO : ここにコマンド ハンドラ コードを追加します。
long w=800/*希望する幅*/, h=2000/*適当*/;

ChtmlviewView * pView = (ChtmlviewView*)GetActiveView( );
HDC hdc = CreateDC("DISPLAY",0,0,0);
if( hdc ) {
HDC memDC = CreateCompatibleDC (hdc);
if( memDC ) {
IDispatch* pApp = (IDispatch*)pView->GetApplication();
if(pApp){
IHTMLDocument2 *pHtml = (IHTMLDocument2 *)pView->GetHtmlDocument();
IOleObject *p;
pHtml->QueryInterface(IID_IOleObject,(void**)&p);
IHTMLElement *pElement = NULL;
IHTMLElement2 *pElement2 = NULL;
pHtml->get_body(&pElement);
if( pElement ) {
pElement->QueryInterface(IID_IHTMLElement2,(void**)&pElement2);
if( pElement2 )
pElement2->get_scrollHeight(&h);
}
// 幅・高さ(pixel)を0.01mm単位に変換
SIZEL sz, szOrg;
sz.cx = w * 2540 / GetDeviceCaps(memDC,LOGPIXELSX);
sz.cy = h * 2540 / GetDeviceCaps(memDC,LOGPIXELSY);
p->GetExtent(DVASPECT_CONTENT,&szOrg);
p->SetExtent(DVASPECT_CONTENT,&sz);
HBITMAP hHtmlImg = CreateCompatibleBitmap(hdc,w,h);
HBITMAP hBmp = (HBITMAP)SelectObject(memDC, hHtmlImg);

RECT rect;
SetRect(&rect,0,0,w,h);
OleDraw(pApp,DVASPECT_CONTENT,memDC,&rect);
p->SetExtent(DVASPECT_CONTENT,&szOrg);
pApp->Release();

SelectObject(memDC, hBmp);

SaveToFile(hHtmlImg, w, h);
if( OpenClipboard() ) {
EmptyClipboard();
SetClipboardData(CF_BITMAP,hHtmlImg);
CloseClipboard();
}
}

DeleteDC(memDC);
}
DeleteDC(hdc);
}
}