怎樣在剪貼簿中以CF_ENHMETAFILE放一副圖?

來源:互聯網
上載者:User

來自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;
}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.