//在客户端上一级目录创建一个文件夹
//inloadName 创建的文件夹名称
//outFileload 文件夹的路径
int SoftInfosetDownloadLoad(std::string inloadName, std::string& outFileload)
{
//用于存储模块路径
CHAR szMoudlePath[MAX_PATH];
//使用NULL参数,获取本模块路径
if (!GetModuleFileNameA(NULL, szMoudlePath, MAX_PATH))
{
return -1;
}
std::string folderPath = +szMoudlePath;
//查找在s1中任意一个字符在s中最后一次出现的位置,并返回(包括0)
int last = folderPath.find_last_of("\\");
int secLast = (folderPath.substr(0, last)).find_last_of("\\");
std::string finalFolderPath = folderPath.substr(0, secLast);
finalFolderPath += "\\";
finalFolderPath += inloadName;
if ((GetFileAttributesA(finalFolderPath.c_str()) == FILE_ATTRIBUTE_DIRECTORY))
{
outFileload = finalFolderPath;
return 0;
}
else {
bool flag = CreateDirectory(finalFolderPath.c_str(), NULL);
if (!flag)
{
return -1;
}
}
outFileload = finalFolderPath;
return 0;
}
HRESULT SaveIcon(HICON hIcon, const char* path) {
// Create the IPicture intrface
PICTDESC desc = { sizeof(PICTDESC) };
desc.picType = PICTYPE_ICON;
desc.icon.hicon = hIcon;
IPicture* pPicture = 0;
HRESULT hr = OleCreatePictureIndirect(&desc, IID_IPicture, FALSE, (void**)&pPicture);
if (FAILED(hr)) return hr;
// Create a stream and save the image
IStream* pStream = 0;
CreateStreamOnHGlobal(0, TRUE, &pStream);
LONG cbSize = 0;
hr = pPicture->SaveAsFile(pStream, TRUE, &cbSize);
// Write the stream content to the file
if (!FAILED(hr)) {
HGLOBAL hBuf = 0;
GetHGlobalFromStream(pStream, &hBuf);
void* buffer = GlobalLock(hBuf);
HANDLE hFile = CreateFile(path, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_FLAG_SEQUENTIAL_SCAN, 0);
if (!hFile) hr = HRESULT_FROM_WIN32(GetLastError());
else {
DWORD written = 0;
WriteFile(hFile, buffer, cbSize, &written, 0);
CloseHandle(hFile);
}
GlobalUnlock(buffer);
}
//Cleanup
pStream->Release();
pPicture->Release();
return hr;
}
int GetLogo(std::string inExePath, std::string inlogoName, std::string inlogoFilename, std::string& outLogoPath)
{
LPCSTR testIcon = inExePath.c_str();
HICON hIcon = NULL;
SHFILEINFOA fileInfo;
//将获取的图标信息传到 fileinfo
DWORD_PTR dwRet = SHGetFileInfoA(testIcon, 0, &fileInfo, sizeof(SHFILEINFO), SHGFI_SYSICONINDEX | SHGFI_ICON | SHGFI_USEFILEATTRIBUTES);
hIcon = fileInfo.hIcon;
if (!hIcon) {
return -1;
}
else {
std::string outLogoFile;
SoftInfosetDownloadLoad(inlogoFilename, outLogoFile);
//添加名字
outLogoFile += "\\";
outLogoFile += inlogoName;
HRESULT hr = SaveIcon(hIcon, outLogoFile.c_str());
outLogoPath = outLogoFile.c_str();
}
::DestroyIcon(hIcon);
return 0;
}
获取图标(失真)
最新推荐文章于 2023-06-17 11:08:46 发布