📄 cescreencapture.cpp
字号:
// CeScreenCapture.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "CeScreenCapture.h"
#include "gc.h"
#include "dibsection.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
// CeScreenCapture
//
// Captures the device screen into a bitmap and send the data back to the desktop.
//
CESCREENCAPTURE_API int CeScreenCapture(DWORD cbInput, BYTE* pInput, DWORD* pcbOutput, BYTE** ppOutput, LPVOID pReserved)
{
CGC gx;
int nScreenX = GetSystemMetrics(SM_CXSCREEN),
nScreenY = GetSystemMetrics(SM_CYSCREEN);
if(pInput != NULL)
LocalFree(pInput);
*pcbOutput = 0;
*ppOutput = NULL;
if(gx.Open(NULL))
{
if(gx.BeginDraw())
{
CDIBSection dib;
if(dib.CreateBitmap(nScreenX, nScreenY, (int)gx.GetBitsPerPixel()))
{
int x, y;
WORD* pBits = (WORD*)dib.GetDIBits();
for(y = nScreenY - 1; y >= 0; --y)
{
for(x = 0; x < nScreenX; ++x)
{
*pBits++ = gx.GetPixel(x, y);
}
}
DWORD dwSize;
BYTE* pBuffer;
BITMAPINFO* pInfo = dib.GetBitmapInfo();
pInfo->bmiHeader.biCompression = BI_BITFIELDS;
DWORD dw[3];
if(gx.GetDisplayFormat() & kfDirect555)
{
dw[0] = 31744; // RED bitmask Bits: 0 11111 00000 00000
dw[1] = 992; // GREEN bitmask Bits: 0 00000 11111 00000
dw[2] = 31; // BLUE bitmask Bits: 0 00000 00000 11111
}
else if(gx.GetDisplayFormat() & kfDirect565)
{
dw[0] = 0xF800; // RED bitmask Bits: 11111 000000 00000
dw[1] = 0x7E0; // GREEN bitmask Bits: 00000 111111 00000
dw[2] = 0x1F; // BLUE bitmask Bits: 00000 000000 11111
}
CopyMemory(dib.GetColorTable(), dw, sizeof(DWORD) * 3);
dwSize = sizeof(DIBINFO) + dib.GetImageSize();
pBuffer = (BYTE*)LocalAlloc(LPTR, dwSize);
if(pBuffer)
{
memcpy(pBuffer, dib.GetBitmapInfo(), sizeof(DIBINFO));
memcpy(pBuffer + sizeof(DIBINFO), dib.GetDIBits(), dib.GetImageSize());
*pcbOutput = dwSize;
*ppOutput = pBuffer;
}
}
gx.EndDraw();
}
gx.Close();
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -