📄 cepicture.cpp
字号:
// CEPicture.cpp: implementation of the CEPicture class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CEPicture.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CEPicture::CEPicture()
{
}
CEPicture::~CEPicture()
{
//DeleteObject(m_bitmap);
}
/*HBITMAP CEPicture::Init(HDC hdc,HINSTANCE hInst,LPCTSTR pictureName)
{
SetHDC(hdc);
m_bitmap = LoadBitmap(hInst,pictureName);
Use();
return m_bitmap;
}*/
//HBITMAP CEPicture::Init(PTSTR szFileName)
HBITMAP CEPicture::Init(LPCTSTR szFileName)
{
//::SetTimer(NULL,NULL,3000,(TIMERPROC)PlayRandomWave);
BITMAPFILEHEADER bmfh ;
BITMAPINFO * pbmi ;
BYTE * pBits ;
BOOL bSuccess ;
DWORD dwInfoSize, dwBytesRead ;
HANDLE hFile ;
hFile = CreateFile (szFileName, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, 0, NULL) ;
if (hFile == INVALID_HANDLE_VALUE)
return NULL ;
bSuccess = ReadFile (hFile, &bmfh, sizeof (BITMAPFILEHEADER),
&dwBytesRead, NULL) ;
if (!bSuccess || (dwBytesRead != sizeof (BITMAPFILEHEADER))
|| (bmfh.bfType != * (WORD *) "BM"))
{
CloseHandle (hFile) ;
return NULL ;
}
dwInfoSize = bmfh.bfOffBits - sizeof (BITMAPFILEHEADER) ;
pbmi = (BITMAPINFO*)malloc (dwInfoSize) ;
bSuccess = ReadFile (hFile, pbmi, dwInfoSize, &dwBytesRead, NULL) ;
if (!bSuccess || (dwBytesRead != dwInfoSize))
{
free (pbmi) ;
CloseHandle (hFile) ;
return NULL ;
}
if (m_bitmap)
{
DeleteObject (m_bitmap) ;
m_bitmap = NULL ;
}
m_bitmap = CreateDIBSection (NULL, pbmi, DIB_RGB_COLORS, (VOID**)&pBits, NULL, 0) ;
if (m_bitmap == NULL)
{
free (pbmi) ;
CloseHandle (hFile) ;
return NULL ;
}
ReadFile (hFile, pBits, bmfh.bfSize - bmfh.bfOffBits, &dwBytesRead, NULL) ;
free (pbmi) ;
CloseHandle (hFile) ;
return m_bitmap ;
}
/*
void CEPicture::SetHDC(HDC hdc)
{
m_hdc = hdc;
}
HDC CEPicture::GetHDC()
{
return m_hdc;
}
void CEPicture::Use()
{
//DeleteObject(m_oldbitmap);
//m_oldbitmap = (HBITMAP)SelectObject(m_hdc,m_bitmap);
DeleteObject(SelectObject(m_hdc,m_bitmap));
}
void CEPicture::Use(int x,int y)
{
HDC hdcMem;
GetObject (m_bitmap, sizeof (BITMAP), &bitmap) ;
hdcMem = CreateCompatibleDC (m_hdc) ;
SelectObject (hdcMem, m_bitmap) ;
BitBlt (m_hdc,x,y, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY) ;
DeleteDC (hdcMem) ;
}
void CEPicture::Use(long x,long y,long Width,long Height,long xSrc,long ySrc,long SrcWidth, long nSrcHeight)
{
HDC hdcMem;
GetObject (m_bitmap, sizeof (BITMAP), &bitmap) ;
hdcMem = CreateCompatibleDC (m_hdc) ;
SelectObject (hdcMem, m_bitmap) ;
BitBlt (m_hdc,x,y, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY) ;
StretchBlt(m_hdc,x,y,Width,Height,hdcMem,xSrc,ySrc,SrcWidth,nSrcHeight,SRCCOPY);
DeleteDC (hdcMem) ;
}
*/
/*
void CEPicture::windowRgn(HWND hwnd,COLORREF TransparentColor)
{
int x=0;
int y=0;
int lngReturn,lngReturn1;
RECT rect;
HRGN lngRgn,lngRgnTmp;
COLORREF GetColor;
HDC dc = GetDC(hwnd);
GetClientRect(hwnd,&rect);
lngRgn = CreateRectRgn(x, y, 1, 1);
//int i;
//i=NULLREGION;//1
//i=SIMPLEREGION;//2
//i=COMPLEXREGION;//3
//i=ERROR;//0
for(y = 1;y<=rect.bottom;y++)
{
for(x = 1;x<=rect.right;x++)
{
GetColor = GetPixel(dc, x, y);
if(GetColor != TransparentColor)
{
lngRgnTmp = CreateRectRgn(x, y, x+1, y+1 );
SetPixel(dc, x + 1, y + 1, RGB(0, 0, 0));
lngReturn = CombineRgn(lngRgn, lngRgn, lngRgnTmp, RGN_OR);
//lngReturn1 = SetWindowRgn(hwnd, lngRgn, TRUE);
DeleteObject (lngRgnTmp);
}
}
}
lngReturn1 = SetWindowRgn(hwnd, lngRgn, TRUE);
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -