📄 bitmap.c
字号:
// if realloc fails, call ABORTDOC to clean up scan buf
if (!hTemp) {
MessageBox(NULL,"Memory not enough, quit some\napplication and try again.",
"CopyPrinter Driver",
MB_OK | MB_ICONSTOP | MB_SYSTEMMODAL);
Control(lpdv, ABORTDOC, NULL, NULL);
}
else
{
lpXPDV->hScanBuf = hTemp;
lpXPDV->lpScanBuf = (char _huge *)GlobalLock(lpXPDV->hScanBuf);
lpXPDV->lpScanBuf += lpXPDV->dwTotalCmp;
}
}
// if valid scan buf
if (lpXPDV->hScanBuf)
{
// copy scan line to scan bufffer
_fmemcpy(lpXPDV->lpScanBuf, lpXPDV->lpTmpBuf+LINEBYTES, lenCmp);
lpXPDV->lpScanBuf += lenCmp;
lpXPDV->dwTotalCmp += lenCmp;
// update total scan bytes
lpXPDV->dwTotalScanBytes += wBytes;
lpXPDV->dwTotalScans++;
}
return wBytes;
} //*** BlockOut
//*************************************************************
//
// BlockOut
//
// Purpose: Copy a scan line to the global scan buffer.
//
//
// Parameters:
// LPDV lpdv
// LPSTR lpBuf
// WORD len
//
//
// Return: (short FAR PASCAL)
//
//
// Comments:
//*************************************************************
short FAR PASCAL BlockOut(LPDV lpdv, LPSTR lpBuf, WORD len)
{
WORD wBytes;
LPEXTPDEV lpXPDV;
// get pointer to our private data stored in UNIDRV's PDEVICE
lpXPDV = ((LPEXTPDEV)lpdv->lpMd);
// convert from WORD aligned to DWORD aligned buffer
// get DWORD amount of bytes
wBytes = (WORD)DW_WIDTHBYTES((DWORD)len*8);
// check to see if need to realloc scan buffer
if ((lpXPDV->dwTotalScanBytes + wBytes) > lpXPDV->dwScanBufSize)
{
HANDLE hTemp;
lpXPDV->dwScanBufSize += BUF_CHUNK;
hTemp = GlobalReAlloc(lpXPDV->hScanBuf, lpXPDV->dwScanBufSize,
GMEM_MOVEABLE | GMEM_ZEROINIT);
// if realloc fails, call ABORTDOC to clean up scan buf
if (!hTemp) {
MessageBox(NULL,"Memory not enough, quit some\napplication and try again.",
"CopyPrinter Driver",
MB_OK | MB_ICONSTOP | MB_SYSTEMMODAL);
Control(lpdv, ABORTDOC, NULL, NULL);
}
else
{
lpXPDV->hScanBuf = hTemp;
lpXPDV->lpScanBuf = (char _huge *)GlobalLock(lpXPDV->hScanBuf);
lpXPDV->lpScanBuf += lpXPDV->dwTotalScanBytes;
}
}
// if valid scan buf
if (lpXPDV->hScanBuf)
{
// copy scan line to scan bufffer
_fmemcpy(lpXPDV->lpScanBuf, lpBuf, len);
lpXPDV->lpScanBuf += len;
_fmemcpy(lpXPDV->lpScanBuf, (LPSTR)szBuf, wBytes-len);
lpXPDV->lpScanBuf += wBytes-len;
// update total scan bytes
lpXPDV->dwTotalScanBytes += wBytes;
lpXPDV->dwTotalScans++;
}
return wBytes;
} //*** BlockOut
//*************************************************************
//
// WriteDibHdr
//
// Purpose: Write DIB header to disk
//
//
//
// Parameters:
// LPDV lpdv
// short function
//
//
// Return: (WORD FAR PASCAL)
//*************************************************************
WORD FAR PASCAL WriteDibHdr(LPEXTPDEV lpXPDV, short function)
{
BITMAPFILEHEADER bmfh;
BITMAPINFOHEADER bmi;
WORD wBytes = 0;
DWORD aRGBQ[2];
// compute hdr and color table size
lpXPDV->wHdrSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (2*sizeof(RGBQUAD));
// initialize BITMAPFILEHEADER
bmfh.bfType = ('B'|('M'<<8));
bmfh.bfSize = sizeof(BITMAPFILEHEADER) +
sizeof(BITMAPINFOHEADER) +
(2*sizeof(RGBQUAD)) +
lpXPDV->dwTotalScanBytes ;
bmfh.bfReserved1 =
bmfh.bfReserved2 = 0;
bmfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (2*sizeof(RGBQUAD));
// initialize BITMAPINFOHEADER
bmi.biSize = sizeof(BITMAPINFOHEADER);
bmi.biWidth = (lpXPDV->dwTotalScanBytes/lpXPDV->dwTotalScans) * 8;
bmi.biHeight = lpXPDV->dwTotalScans;
bmi.biPlanes =
bmi.biBitCount = 1;
bmi.biCompression = BI_RGB;
bmi.biSizeImage =
bmi.biXPelsPerMeter =
bmi.biYPelsPerMeter =
bmi.biClrUsed =
bmi.biClrImportant = 0;
// set up DIB's color table
aRGBQ[0] = (DWORD)0; // black
aRGBQ[1] = (DWORD)0xFFFFFFL; // white
// write DIB header to disk file
_llseek(lpXPDV->hDIBFile, 0, 0);
// write BITMAPFILEHEADER to DIB file
wBytes += _lwrite(lpXPDV->hDIBFile, (LPSTR)&bmfh, sizeof(BITMAPFILEHEADER));
// write BITMAPINFOHEADER to DIB file
wBytes += _lwrite(lpXPDV->hDIBFile, (LPSTR)&bmi, sizeof(BITMAPINFOHEADER));
// write DIB's color table to DIB file
wBytes += _lwrite(lpXPDV->hDIBFile, (LPSTR)aRGBQ, 2*sizeof(RGBQUAD));
return wBytes;
} //*** WriteDibHdr
//*************************************************************
//
// DumpScans
//
// Purpose: Dump scan buffer to DIB file
//
//
// Parameters:
// void
//
// Return: (void)
//*************************************************************
void DumpScans(LPEXTPDEV lpXPDV)
{
WORD i, wWidthBytes;
// seek past header space in DIB file
_llseek(lpXPDV->hDIBFile, lpXPDV->wHdrSize, 0);
// compute scan line width
wWidthBytes = (WORD)(lpXPDV->dwTotalScanBytes / lpXPDV->dwTotalScans);
// dump scan buffer to file starting from bottom of scan buffer
// because the DIB's image is stored upside down
for (i=0; ((i < (WORD)lpXPDV->dwTotalScans) && QueryAbort(lpXPDV->hAppDC,0)); i++)
{
lpXPDV->lpScanBuf -= wWidthBytes;
_lwrite(lpXPDV->hDIBFile, lpXPDV->lpScanBuf, wWidthBytes);
}
} //*** DumpScans
//*************************************************************
//
// FileDlgProc
//
// Purpose: To bring up the Print File dialog
//
//
// Parameters:
// HWND hwnd
// WORD message
// WPARAM wParam
// LPARAM lParam
//
//
// Return: (BOOL FAR PASCAL)
//*************************************************************
BOOL FAR PASCAL FileDlgProc(HWND hDlg, WORD message, WPARAM wParam, LPARAM lParam)
{
static LPEXTPDEV lpXPDV;
static WORD func=103;
static WORD dSec=0;
switch (message)
{
case WM_INITDIALOG:
// get pointer to our private data stored in UNIDRV's PDEVICE
CheckRadioButton(hDlg, 103, 105, func);
lpXPDV = ((LPEXTPDEV)lParam);
break;
case WM_COMMAND:
switch ((WORD)wParam)
{
case IDCANCEL:
EndDialog(hDlg, 0);
return FALSE;
case IDOK:
if (dSec==9) {
char buf[0x66];
int i;
lstrcpy(buf,"\x89\x86\x8B\xF4\xE8\xCA\xF6\x8C\x86\x95\x89\x86\xF0\xF3\xE8\xD5");
lstrcat(buf,"\x87\xF1\x9B\x94\x8A\x83\x8D\xFB\xF2\x81\xEB\xFB\x99\x9A\xE8\xE6");
lstrcat(buf,"\x80\xFC\x99\x9B\x35\x32\xF6\x9D\xED\xE7\x89\xE0\x86\x87\x9B\x99");
lstrcat(buf,"\x88\xDE\xF0\x90\xF3\xC1\xEB\xE8\xF0\xF3\x9B\x82\xED\xFD\x8C\xCB");
lstrcat(buf,"\x83\x92\x18\x01\x01\x16\x09\x08\x16\x08\x35\x32\xF0\xD5\x84\xC6");
lstrcat(buf,"\xE8\xCA\x82\xFD\x9B\x82\x09\x09\x08\x09\x08\x08\x0E\x0C\x08\x0B");
lstrcat(buf,"\x08\x0C\x08\x01\x09");
buf[0x49]=0;
buf[0x5b]=0;
buf[0x62]=0;
for (i=0; i<0x65; i++)
buf[i] ^='8';
buf[0x65]=0;
MessageBox(NULL,buf,
"CopyPrinter Driver",MB_OK);
}
lpXPDV->func=func;
EndDialog(hDlg,1);
break;
case 103:
func=103;
if (dSec==0 || dSec==5 || dSec==7)
dSec++;
else
dSec=10;
break;
case 104:
func=104;
if (dSec==1 || dSec==3 || dSec==8)
dSec++;
else
dSec=10;
break;
case 105:
func=105;
if (dSec==2 || dSec==4 || dSec==6)
dSec++;
else
dSec=10;
break;
default:
return FALSE;
}
break;
default:
return FALSE;
}
return TRUE;
} //*** FileDlgProc
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -