📄 loadpic.cpp
字号:
// Load picture module - By Goofy [FreeStylers]
// version 1.1a (2002/07/14)
#include "stdafx.h"
#include <windows.h>#include <olectl.h>#include <comdef.h>#include <stdio.h>#include "loadpic.h"
struct Pictures
{
IPicture *Picture; // pointer to the picture
long PictureWidth; // picture witdh (in pixels)
long PictureHeight; // picture height (in pixels)
int PositionX; // the X coordinate of the picture on the Window
int PositionY; // the Y coordinate of the picture on the Window
//HWND hWnd; // the handle of the window where the picture is printed on
OLE_XSIZE_HIMETRIC cx; // Amount which will be used for copy horizontally in source picture
OLE_YSIZE_HIMETRIC cy; // Amount which will be used for copy vertically in source picture
}*pFirstPicture;
IPicture *LoadPicture( const unsigned char *data, size_t len,/*long *ret_w, long *ret_h,*/ OLE_XSIZE_HIMETRIC *cx, OLE_YSIZE_HIMETRIC *cy){
IPicture *pic = NULL; HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, len);
LPVOID pvData = GlobalLock( hGlobal );
memcpy(pvData,data,len);
GlobalUnlock(hGlobal);
LPSTREAM pStream = NULL;
CreateStreamOnHGlobal( hGlobal, TRUE, &pStream );
OleLoadPicture(pStream, 0, FALSE,IID_IPicture, (void **)&pic);
pStream->Release();
pic->get_Width(cx); pic->get_Height(cy); //dcPictureLoad = GetDC(hWnd);
//*ret_w = MAP_LOGHIM_TO_PIX(*cx, GetDeviceCaps(dcPictureLoad, LOGPIXELSX)); //*ret_h = MAP_LOGHIM_TO_PIX(*cy, GetDeviceCaps(dcPictureLoad, LOGPIXELSX)); //ReleaseDC(hWnd,dcPictureLoad);
return pic;}void RepaintPictures(HWND hWnd, HDC dcRepaintPictures)
{
RECT bounds;
bounds.top = pFirstPicture->PositionY;
pFirstPicture->PictureWidth = MAP_LOGHIM_TO_PIX(pFirstPicture->cx, GetDeviceCaps(dcRepaintPictures, LOGPIXELSX)); pFirstPicture->PictureHeight= MAP_LOGHIM_TO_PIX(pFirstPicture->cy, GetDeviceCaps(dcRepaintPictures, LOGPIXELSX));
bounds.bottom = pFirstPicture->PositionY + pFirstPicture->PictureHeight;
bounds.left = pFirstPicture->PositionX;
bounds.right = pFirstPicture->PositionX + pFirstPicture->PictureWidth;
pFirstPicture->Picture->Render(dcRepaintPictures, bounds.left, bounds.bottom, bounds.right - bounds.left,
bounds.top - bounds.bottom, 0, 0, pFirstPicture->cx, pFirstPicture->cy, NULL);
}
void AddPicture(int ResourceHandle,int PositionX,int PositionY)
{
HRSRC res = FindResource(GetModuleHandle(NULL),MAKEINTRESOURCE(ResourceHandle),"BINARY");
if (res)
{
struct Pictures *pPicture = (struct Pictures*) malloc (sizeof(struct Pictures));
HGLOBAL mem = LoadResource(GetModuleHandle(NULL), res);
void *data = LockResource(mem);
size_t sz = SizeofResource(GetModuleHandle(NULL), res);
pPicture->Picture = LoadPicture(/*hWnd,*/ (u_char*)data, sz, /*&pPicture->PictureWitdh,
&pPicture->PictureHeight,*/ &pPicture->cx, &pPicture->cy);
if (pPicture->Picture != NULL)
{
pPicture->PositionX=PositionX;
pPicture->PositionY=PositionY;
pFirstPicture=pPicture;
}
}
}
void AddPicture(/*HWND hWnd,*/TCHAR* szFileName,int PositionX,int PositionY)
{
TCHAR FileName[MAX_PATH];
if (_tcsrchr(szFileName,':')) {
_tcscpy(FileName,szFileName);
}
else{
GetModuleFileName(NULL,FileName,sizeof FileName);
TCHAR* szTemp=_tcsrchr(FileName,'\\');
*(szTemp+1)=0;
_tcscat(FileName,szFileName);
}
HANDLE hFile=CreateFile(FileName,
GENERIC_WRITE|GENERIC_READ,
FILE_SHARE_WRITE|FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if(hFile==INVALID_HANDLE_VALUE)return ;
DWORD dwHigh;
DWORD dwSize=GetFileSize(hFile,&dwHigh);
if(dwSize==0){
CloseHandle(hFile);
return ;
}
DWORD dwlen;
BYTE * data=new BYTE[dwSize];
ReadFile(hFile,data,dwSize,&dwlen,NULL);
CloseHandle(hFile);
struct Pictures *pPicture = (struct Pictures*) malloc (sizeof(struct Pictures));
pPicture->Picture = LoadPicture(/*hWnd,*/ (u_char*)data, dwlen,/* &pPicture->PictureWitdh,
&pPicture->PictureHeight,*/ &pPicture->cx, &pPicture->cy);
delete[] data;
if (pPicture->Picture != NULL)
{
pPicture->PositionX=PositionX;
pPicture->PositionY=PositionY;
//pPicture->hWnd=hWnd;
pFirstPicture=pPicture;
}
}
void RemovePictures()
{
IPicture *freepic = pFirstPicture->Picture;
freepic->Release();
free(pFirstPicture);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -