EMF格式文件导出

//请复制到MSPaint或Word查看。
#include 
#include 
#include 
#define Random (rand()%256)
void DrawEMF(HDC hdc)
{
    RECT rect;
    static HFONT hFont;
    int h=24;
    hFont=CreateFont(h,0,0,0,0,0,0,0,1,0,0,0,0,"Consolas");
    SelectObject(hdc,hFont);
    char string[]="Hello World!\n你好,世界!Hello World!\n你好,世界!Hello World!\n你好,世界!Hello World!\n你好,世界!";
    for(int i=0; i<640/h; i++) {
        SetTextColor(hdc,RGB(Random,Random,Random));
        TextOut(hdc,0,i*h,string,strlen(string));
    }
}
int main()
{
    //像素点的宽和高
    int width = 1000;
    int height = 640;
    int cxMms, cyMms, cxPix, cyPix;
    HWND hwndClient=GetDesktopWindow();
    HDC hdc = GetDC(hwndClient);
    cxMms = GetDeviceCaps (hdc, HORZSIZE);
    cyMms = GetDeviceCaps (hdc, VERTSIZE);
    cxPix = GetDeviceCaps (hdc, HORZRES);
    cyPix = GetDeviceCaps (hdc, VERTRES);
    ReleaseDC(hwndClient, hdc);
    // printf("%d %d %d %d\n",cxMms,cyMms,cxPix,cyPix);
    RECT rcImg= {0,0,(width-1)*cxMms * 100 / cxPix,(height-1)*cyMms * 100 / cyPix};
    HDC dc = CreateEnhMetaFile(NULL, NULL, &rcImg, (LPSTR)NULL);
    DrawEMF(dc);
    HENHMETAFILE hemf= CloseEnhMetaFile(dc);
    OpenClipboard(0);
    EmptyClipboard();
    SetClipboardData(CF_ENHMETAFILE, hemf);
    CloseClipboard();
    return 0;
}

EMF格式文件导出_第1张图片

你可能感兴趣的:(c++,windows)