我最近在做html文件用缩略图预览。我看到用IExtractImage可以取得图形
,需要用<shobjidl.h>头文件。因为我的机上没有,就在网上下载了<shobjidl.h>,
但编译时提示许多变量重复定义,我不知道怎么办。请各位大侠多多指点。如果有其他办法也可以,要在WIN2000和WIN XP都能用。我想用的方法如下:
#define _WIN32_DCOM
#include <windows.h>
#include <atlbase.h>
#include <shobjidl.h>
int main(int argc, char** argv)
{
USES_CONVERSION;
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
{
CComPtr<IPersistFile> p1;
p1.CoCreateInstance(L"Shell.ThumbnailExtract.HTML.1");
p1->Load(T2OLE(argv[1]), 0);
CComQIPtr<IExtractImage, &IID_IExtractImage> p2(p1);
WCHAR s[512];
DWORD Priority = 0;
SIZE sz;
sz.cx = 140; sz.cy = 140;
DWORD Flags = IEIFLAG_SCREEN;
p2->GetLocation(s, 512, &Priority, &sz, 32, &Flags);
HBITMAP hBitmap = NULL;
p2->Extract(&hBitmap); HDC hDC = GetDC(NULL);
HDC hDCMem = CreateCompatibleDC(hDC);
SelectObject(hDCMem, hBitmap);
BitBlt(hDC, 0, 0, sz.cx, sz.cy, hDCMem, 0, 0, SRCCOPY);
DeleteDC(hDCMem);
ReleaseDC(NULL, hDC); DeleteObject(hBitmap);
}
CoUninitialize();
return 0;
,需要用<shobjidl.h>头文件。因为我的机上没有,就在网上下载了<shobjidl.h>,
但编译时提示许多变量重复定义,我不知道怎么办。请各位大侠多多指点。如果有其他办法也可以,要在WIN2000和WIN XP都能用。我想用的方法如下:
#define _WIN32_DCOM
#include <windows.h>
#include <atlbase.h>
#include <shobjidl.h>
int main(int argc, char** argv)
{
USES_CONVERSION;
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
{
CComPtr<IPersistFile> p1;
p1.CoCreateInstance(L"Shell.ThumbnailExtract.HTML.1");
p1->Load(T2OLE(argv[1]), 0);
CComQIPtr<IExtractImage, &IID_IExtractImage> p2(p1);
WCHAR s[512];
DWORD Priority = 0;
SIZE sz;
sz.cx = 140; sz.cy = 140;
DWORD Flags = IEIFLAG_SCREEN;
p2->GetLocation(s, 512, &Priority, &sz, 32, &Flags);
HBITMAP hBitmap = NULL;
p2->Extract(&hBitmap); HDC hDC = GetDC(NULL);
HDC hDCMem = CreateCompatibleDC(hDC);
SelectObject(hDCMem, hBitmap);
BitBlt(hDC, 0, 0, sz.cx, sz.cy, hDCMem, 0, 0, SRCCOPY);
DeleteDC(hDCMem);
ReleaseDC(NULL, hDC); DeleteObject(hBitmap);
}
CoUninitialize();
return 0;
把新的sdk路径的优先级提高。
propidl.h不需要的