来自http://www.vckbase.com/bbs/prime/viewprime.asp?id=412
下面的回复非常精彩。
/** * Create a metafile that contains the plotting graph. */ HENHMETAFILE createEnhMetaFile() { HDC hdc; RECT rc, rcImg; int cxMms, cyMms, cxPix, cyPix; HENHMETAFILE hemf; hdc = GetDC(hwndClient); cxMms = GetDeviceCaps (hdc, HORZSIZE); cyMms = GetDeviceCaps (hdc, VERTSIZE); cxPix = GetDeviceCaps (hdc, HORZRES); cyPix = GetDeviceCaps (hdc, VERTRES); ReleaseDC(hwndClient, hdc); // Since RECT in CreateEnhMetaFile function specifies the // dimensions in 0.01 mm units GetClientRect(hwndClient, &rc); rcImg.left = 0; rcImg.top = 0; rcImg.right = (rc.right - rc.left) * cxMms * 100 / cxPix; rcImg.bottom = (rc.bottom - rc.top) * cyMms * 100 / cyPix; hdc = CreateEnhMetaFile(NULL, NULL, &rcImg, (LPSTR)NULL); // Coordinate drawPlotBox(hdc, rc); // Plot the data series. DATASERIES *ds = g_dsHead; while (ds != NULL) { drawDataSeries(hdc, ds, rc); ds = ds->next; } hemf = CloseEnhMetaFile(hdc); return hemf; } ( WuWuli 发表于 2002-8-31 13:20:00) A most powerful way is to transfer the content of client area to the clipboard in Windows Enhanced Metafile format, which is more flexible than bitmap: /** * Copy the graph to clipboard. */ LRESULT cmdCopyGraph(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl) { HENHMETAFILE hemf; hemf = createEnhMetaFile(); OpenClipboard(hwnd); EmptyClipboard(); SetClipboardData(CF_ENHMETAFILE, hemf); CloseClipboard(); updateStatusBar("The graph copied", 0); return 0; }