📄 writeavi.cpp
字号:
static void MakeFrames(LPLPBI alpbi, UINT bits, UINT wXSize,UINT wYSize )
{
HDC hdc ;
HDC hdcMem ;
HBITMAP hbitmap,hbitmapOld ;
HPEN hpen3,hpen1,hpenwhite,hpenOld ;
HFONT hfont,hfontOld ;
HBRUSH hbrush,hbrushOld ;
RECT rc ;
RECT rcFrameNo ;
int wXCent,wYCent ;
int cxPixInch ;
int cyPixInch ;
int cxPixels ;
int cyPixels ;
int radius ;
int x0,y0,x1,y1 ;
int i,j ;
char szNumber[3] ;
//
// Make sure our resources are freed
//
FreeFrames(alpbi);
//
// Find the center of the movie
//
wXCent = wXSize/2 ;
wYCent = wYSize/2 ;
hdc = GetDC(NULL) ;
hdcMem = CreateCompatibleDC(NULL) ;
//
// We need some gray and white brushes and pens, and a bitmap
//
hpen3 = CreatePen(PS_SOLID,3,RGB(128,128,128)) ;
hpen1 = CreatePen(PS_SOLID,1,RGB(64,64,64));
hpenwhite = CreatePen(PS_SOLID,1,RGB(255,255,255));
hpenOld = SelectPen(hdcMem, hpen3);
hbrush = CreateSolidBrush(RGB(192,192,192)) ;
hbrushOld = SelectBrush(hdcMem,hbrush) ;
hbitmap = CreateCompatibleBitmap(hdc,wXSize,wYSize) ;
cxPixInch = GetDeviceCaps(hdc,LOGPIXELSX) ;
cyPixInch = GetDeviceCaps(hdc,LOGPIXELSY) ;
//
// What radius of circle can we fit in this frame? Make sure it's round
// regardless of the aspect ratio
//
radius = ( wXSize < wYSize ) ? wXSize : (wYSize*cxPixInch)/cyPixInch ;
radius = ( radius * 95 ) / 200 ;
//
// Make a Rectangle in the center where the number will go
//
/* x0 = radius / sqrt(2) */
x0 = (radius*100)/141 ;
y0 = (x0*cyPixInch)/cxPixInch ;
x0 = (x0*9)/10 ;
y0 = (y0*9)/10 ;
SetRect( &rcFrameNo,wXCent-x0,wYCent-y0,wXCent+x0,wYCent+y0 ) ;
//
// Move the rectangle in a little and make a font big enough for it
//
x0 = (x0*9)/10 ;
y0 = (y0*9)/10 ;
hfont = CreateFont(
y0*2,
x0,
0,
0,
FW_BOLD,
0,
0,
0,
ANSI_CHARSET,
OUT_DEVICE_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH|FF_SWISS,
NULL
);
hfontOld = SelectFont(hdcMem, hfont);
//
// Now walk through and make all the frames
//
for ( i=0; i<N_FRAMES; i++ ) {
hbitmapOld = SelectBitmap(hdcMem, hbitmap);
//
// Fill the whole frame with white
//
SetRect(&rc,0,0,wXSize,wYSize) ;
FillRect(hdcMem,&rc,GetStockBrush(WHITE_BRUSH)) ;
//
// Draw the circle inside the previously calculated radius
//
cxPixels = radius ;
cyPixels = (cxPixels*cyPixInch)/cxPixInch ;
SelectPen(hdcMem,hpen3) ;
Ellipse(hdcMem,wXCent-cxPixels,wYCent-cyPixels,wXCent+cxPixels,
wYCent+cyPixels) ;
SelectPen(hdcMem,hpen1) ;
//
// Draw the number in the previously calculated area
//
wsprintf(szNumber,"%02u",i+1) ;
SetBkColor(hdcMem,RGB(192,192,192)) ;
SetTextColor(hdcMem,RGB(255,255,255)) ;
ExtTextOut(
hdcMem,
rcFrameNo.left,
rcFrameNo.top+(rcFrameNo.bottom-rcFrameNo.top)/20,
ETO_CLIPPED,
&rcFrameNo,
szNumber,
2,
NULL);
//
// Draw tic marks around the inside of the circle in equal divisions
//
for ( j=0; j<N_FRAMES; j++ ) {
x0 = (radius*aSin[j])/100 ;
y0 = (radius*aCos[j])/100 ;
x1 = (((radius*aSin[j])/100)*11)/12 ;
y1 = (((radius*aCos[j])/100)*11)/12 ;
y0 = -(y0*cyPixInch)/cxPixInch ;
y1 = -(y1*cyPixInch)/cxPixInch ;
MoveToEx(hdcMem,wXCent+x0,wYCent+y0,NULL) ;
LineTo(hdcMem,wXCent+x1,wYCent+y1) ;
}
//
// Now draw the hand of the clock in the appropriate position
//
x1 = (((radius*aSin[i])/100)*5)/8 ;
y1 = (((radius*aCos[i])/100)*5)/8 ;
y1 = -(y1*cyPixInch)/cxPixInch ;
MoveToEx(hdcMem,wXCent,wYCent,NULL) ;
LineTo(hdcMem,wXCent+x1,wYCent+y1) ;
SelectBitmap(hdcMem, hbitmapOld);
//
// Make this into a DIB and stuff it into the array
//
alpbi[i] = (LPBITMAPINFOHEADER)GlobalLock(MakeDib(hbitmap, bits));
//
// For an error, just duplicate the last frame if we can
//
if (alpbi[i] == NULL && i )
alpbi[i] = alpbi[i-1] ;
}
//
// Select all the old objects back and delete resources
//
SelectPen(hdcMem, hpenOld);
SelectBrush(hdcMem,hbrushOld) ;
SelectFont(hdcMem,hfontOld) ;
DeletePen(hpen1) ;
DeletePen(hpen3) ;
DeletePen(hpenwhite) ;
DeleteBrush(hbrush) ;
DeleteBitmap(hbitmap) ;
DeleteFont(hfont) ;
DeleteObject(hdcMem) ;
ReleaseDC(NULL,hdc) ;
}
//
// Walk through our array of LPBI's and free them
//
static void FreeFrames(LPLPBI alpbi)
{
UINT w ;
if (!alpbi[0])
return ;
//
// Don't free a frame if it's a duplicate of the previous one
//
for (w=0; w<N_FRAMES; w++)
if (alpbi[w] && alpbi[w] != alpbi[w-1])
GlobalFreePtr(alpbi[w]);
for (w=0; w<N_FRAMES; w++)
alpbi[w] = NULL;
}
/*
** MakeDib(hbitmap)
**
** Take the given bitmap and transform it into a DIB with parameters:
**
** BitsPerPixel: 8
** Colors: palette
**
*/
static HANDLE MakeDib( HBITMAP hbitmap, UINT bits )
{
HANDLE hdib ;
HDC hdc ;
BITMAP bitmap ;
UINT wLineLen ;
DWORD dwSize ;
DWORD wColSize ;
LPBITMAPINFOHEADER lpbi ;
LPBYTE lpBits ;
GetObject(hbitmap,sizeof(BITMAP),&bitmap) ;
//
// DWORD align the width of the DIB
// Figure out the size of the colour table
// Calculate the size of the DIB
//
wLineLen = (bitmap.bmWidth*bits+31)/32 * 4;
wColSize = sizeof(RGBQUAD)*((bits <= 8) ? 1<<bits : 0);
dwSize = sizeof(BITMAPINFOHEADER) + wColSize +
(DWORD)(UINT)wLineLen*(DWORD)(UINT)bitmap.bmHeight;
//
// Allocate room for a DIB and set the LPBI fields
//
hdib = GlobalAlloc(GHND,dwSize);
if (!hdib)
return hdib ;
lpbi = (LPBITMAPINFOHEADER)GlobalLock(hdib) ;
lpbi->biSize = sizeof(BITMAPINFOHEADER) ;
lpbi->biWidth = bitmap.bmWidth ;
lpbi->biHeight = bitmap.bmHeight ;
lpbi->biPlanes = 1 ;
lpbi->biBitCount = (WORD) bits ;
lpbi->biCompression = BI_RGB ;
lpbi->biSizeImage = dwSize - sizeof(BITMAPINFOHEADER) - wColSize ;
lpbi->biXPelsPerMeter = 0 ;
lpbi->biYPelsPerMeter = 0 ;
lpbi->biClrUsed = (bits <= 8) ? 1<<bits : 0;
lpbi->biClrImportant = 0 ;
//
// Get the bits from the bitmap and stuff them after the LPBI
//
lpBits = (LPBYTE)(lpbi+1)+wColSize ;
hdc = CreateCompatibleDC(NULL) ;
GetDIBits(hdc,hbitmap,0,bitmap.bmHeight,lpBits,(LPBITMAPINFO)lpbi, DIB_RGB_COLORS);
// Fix this if GetDIBits messed it up....
lpbi->biClrUsed = (bits <= 8) ? 1<<bits : 0;
DeleteDC(hdc) ;
GlobalUnlock(hdib);
return hdib ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -