Metafile::EmfToWmfBits的使用
阅读原文时间:2023年07月09日阅读:2

其中涉及到string转换LPCWSTR以及模块绝对路径的调用

#include
#include
#include
#include
#include
#include
#include

#pragma comment (lib,"Shlwapi.lib")
#pragma comment(lib,"gdiplus.lib")
#pragma comment(lib, "shell32.lib")

using namespace Gdiplus;
using std::string;

LPWSTR ConvertToLPWSTR(const std::string& s)
{
LPWSTR ws = new wchar_t[s.size() + ]; // +1 for zero at the end
copy(s.begin(), s.end(), ws);
ws[s.size()] = ; // zero at the end
return ws;
}

int main(int argc, char **argv)
{
UINT size1 = ;
WCHAR path[MAX_PATH];
string name;

GdiplusStartupInput gdiplusStartupInput;  
ULONG\_PTR gdiplusToken;  
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

std::cout << "Please input a file name" << std::endl;  
std::cin >> name;  
LPCWSTR name\_ = LPCWSTR(ConvertToLPWSTR(name));

GetModuleFileNameW(NULL, path, MAX\_PATH);  
PathRemoveFileSpecW(path);  
PathAppendW(path, name\_);

Metafile myMetafile(path);  
Status S\_ch = myMetafile.GetLastStatus();

HENHMETAFILE hEmf = myMetafile.GetHENHMETAFILE();  
size1 = Metafile::EmfToWmfBits(  
    hEmf,  
    ,  
    NULL,  
    MM\_ANISOTROPIC,  
    EmfToWmfBitsFlagsEmbedEmf);  
std::cout << size1 << std::endl;

}