home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
windows
/
slap2.zip
/
SLAP2.C
< prev
next >
Wrap
C/C++ Source or Header
|
1986-03-20
|
4KB
|
171 lines
/* Slap2
The main routine creates a printer DC, gets a DC for the screen
[using GetDC(0)] and blts from the screen to the printer.
*/
#include "windows.h"
#include "winexp.h"
#include "slap2.h"
Slap()
{
char *pch;
char *pchFile;
char *pchPort;
HBITMAP hbm;
HDC hdcmem;
HDC hPrintDC;
HDC hdc;
int xres, yres;
bMenuUp = FALSE;
EnumWindows(lpfnEnumWnd, (long)NULL);
if (bMenuUp) {
/* put in string table */
Death((LPSTR)"Can't copy with menu visible.", TRUE);
return;
}
/* get printer info to make a call to CreateDC */
GetProfileString((LPSTR)"windows", (LPSTR)"Device",
(LPSTR)"", (LPSTR)fileandport, 40);
for (pch = fileandport; *pch && *pch != ','; ++pch)
;
if (*pch)
*pch++=0;
while(*pch && *pch <= ' ')
pch++;
pchFile = pch;
while(*pch && *pch != ',' && *pch > ' ')
pch++;
if (*pch)
*pch++ = 0;
while (*pch && (*pch <= ' ' || *pch == ','))
pch++;
pchPort = pch;
while (*pch && *pch > ' ')
pch++;
*pch = 0;
if (!(hPrintDC = CreateDC((LPSTR)pchFile, (LPSTR)fileandport,
(LPSTR)pchPort, (LPSTR)NULL)))
{
CantPrint:
if (hPrintDC)
DeleteDC(hPrintDC);
if (!bmessage) {
bmessage = TRUE;
Death((LPSTR)"Unable to copy screen to printer.", FALSE);
bmessage = FALSE;
}
return(NULL);
}
hdc = GetDC((HANDLE)NULL);
xres = GetDeviceCaps( hdc, HORZRES);
yres = GetDeviceCaps( hdc, VERTRES);
hdcmem = CreateCompatibleDC(hdc);
hbm = CreateCompatibleBitmap(hdcmem, xres, yres);
if (!hbm)
goto CantPrint;
Escape(hPrintDC, SETABORTPROC, 0, (LPSTR)lpfnAbortProc, (LPSTR)0);
if (Escape(hPrintDC, STARTDOC, lstrlen((LPSTR)"SLAP - Screen Print"),
(LPSTR)"SLAP - Screen Print", (LPSTR)0) < 0)
goto CantPrint;
SelectObject(hdcmem, hbm);
BitBlt(hdcmem, 0, 0, xres, yres,
hdc, 0, 0, SRCCOPY);
BitBlt(hPrintDC, 0, 0, xres, yres,
hdcmem, 0, 0, SRCCOPY);
Escape(hPrintDC, NEWFRAME, 0, (LPSTR)NULL, (LPSTR)0);
Escape(hPrintDC, ENDDOC, 0, (LPSTR)0, (LPSTR)0);
DeleteDC(hPrintDC);
ReleaseDC(0, hdc);
}
/** EnumWnd
Callback routine from EnumWindows to determine if a menu is currently
pulled down.
*/
BOOL FAR PASCAL EnumWnd( hwnd, lparam)
HWND hwnd;
long lparam;
{
char buf [10];
GetClassName(hwnd, (LPSTR)buf, 10);
if (!lstrcmp((LPSTR)buf, (LPSTR)"#32768")) {
bMenuUp = TRUE;
return FALSE;
}
return TRUE;
}
/** CheckPrintKey
This routine gets called every time a key is pressed on the
keyboard. This is because the WH_KEYBOARD Windows Hook is set
to this routine.
*/
BOOL far PASCAL CheckPrintKey(wParam, lParam)
WORD wParam;
LONG lParam;
{
if (wParam == VK_F7 && lParam < 0) { /* up transition of key */
if (Slap())
return(TRUE);
}
if (lpfnOldHook != (FARPROC)NULL)
return((*lpfnOldHook)(wParam, lParam));
else
return(FALSE);
}
/** MyLoad
This is the entry point to the whole thing.
*/
BOOL near pascal MyLoad(hInstance)
HANDLE hInstance;
{
hSlapInstance = hInstance;
lpfnCheckKey = MakeProcInstance(CheckPrintKey, hInstance);
lpfnOldHook = SetWindowsHook(WH_KEYBOARD, lpfnCheckKey);
lpfnEnumWnd = MakeProcInstance(EnumWnd, hInstance);
lpfnAbortProc = MakeProcInstance(fnAbortProc, hInstance);
Death((LPSTR)"F7 set to copy screen to printer.", FALSE);
return(TRUE);
}
/** Death
Generic Message system.
*/
Death(message, bModal)
LPSTR message;
BOOL bModal;
{
MessageBox( NULL,
(LPSTR)message,
(LPSTR)"",
MB_SYSTEMMODAL | MB_OK | (bModal ? MB_ICONHAND : MB_ICONEXCLAMATION));
}
/** fnAbortProc
stub needed so spooler can operate correctly
*/
int FAR PASCAL fnAbortProc(hPrintDC, iReserved)
HDC hPrintDC;
int iReserved;
{
return(TRUE);
}