admin 管理员组文章数量: 887032
2024年1月17日发(作者:c语言属于汇编语言吗)
GETPRNDC.C -- GetPrinterDC function
-----------------------------------------------------------------------*/
#include
HDC GetPrinterDC (void)
{
DWORD dwNeeded, dwReturned ;
HDC hdc ;
PRINTER_INFO_4 * pinfo4 ;
PRINTER_INFO_5 * pinfo5 ;
if (GetVersion () & 0x80000000) // Windows 98
{
EnumPrinters (PRINTER_ENUM_DEFAULT, NULL, 5, NULL,
0, &dwNeeded, &dwReturned) ;
pinfo5 = malloc (dwNeeded) ;
EnumPrinters (PRINTER_ENUM_DEFAULT, NULL, 5, (PBYTE) pinfo5,
dwNeeded, &dwNeeded, &dwReturned) ;
hdc = CreateDC (NULL, pinfo5->pPrinterName, NULL, NULL) ;
free (pinfo5) ;
}
else
//Windows NT
{
EnumPrinters (PRINTER_ENUM_LOCAL, NULL, 4, NULL,
0, &dwNeeded, &dwReturned) ;
pinfo4 = malloc (dwNeeded) ;
EnumPrinters (PRINTER_ENUM_LOCAL, NULL, 4, (PBYTE) pinfo4,
dwNeeded, &dwNeeded, &dwReturned) ;
hdc = CreateDC (NULL, pinfo4->pPrinterName, NULL, NULL) ;
free (pinfo4) ;
}
return hdc ;
}
= CS_HREDRAW | CS_VREDRAW ;
dProc = WndProc ;
xtra = 0 ;
xtra = 0 ;
nce = hInstance ;
= LoadIcon (NULL, IDI_APPLICATION) ;
r = LoadCursor (NULL, IDC_ARROW) ;
kground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
nuName = szAppName ;
assName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox ( NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, NULL,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,LPARAM lParam)
{
static TCHAR szDevice[32], szWindowText[64] ;
static int cxChar, cyChar,nCurrentDevice = IDM_SCREEN,
nCurrentInfo = IDM_BASIC ;
static DWORD dwNeeded, dwReturned ;
static PRINTER_INFO_4 * pinfo4 ;
static PRINTER_INFO_5 * pinfo5 ;
DWORD i ;
HDC hdc, hdcInfo ;
HMENU hMenu ;
HANDLE hPrint ;
PAINTSTRUCT ps ;
TEXTMETRIC tm ;
switch (message)
{
case WM_CREATE :
hdc = GetDC (hwnd) ;
SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT)) ;
GetTextMetrics (hdc, &tm) ;
cxChar = harWidth ;
cyChar = ht + rnalLeading ;
ReleaseDC (hwnd, hdc) ;
// fall through
case WM_SETTINGCHANGE:
hMenu = GetSubMenu (GetMenu (hwnd), 0) ;
while (GetMenuItemCount (hMenu) > 1)
DeleteMenu (hMenu, 1, MF_BYPOSITION) ;
// Get a list of all local and remote printers
//
// First, find out how large an array we need; this
// call will fail, leaving the required size in dwNeeded
//
// Next, allocate space for the info array and fill it
//
// Put the printer names on the menu
if (GetVersion () & 0x80000000) // Windows 98
{
EnumPrinters (PRINTER_ENUM_LOCAL, NULL, 5, NULL,
0, &dwNeeded, &dwReturned) ;
pinfo5 = malloc (dwNeeded) ;
EnumPrinters (PRINTER_ENUM_LOCAL, NULL, 5, (PBYTE) pinfo5,
dwNeeded, &dwNeeded, &dwReturned) ;
for (i = 0 ; i < dwReturned ; i++)
{
AppendMenu (hMenu, (i+1) % 16 ? 0 : MF_MENUBARBREAK, i + 1,
pinfo5[i].pPrinterName) ;
}
free (pinfo5) ;
}
else
// Windows NT
{
EnumPrinters (PRINTER_ENUM_LOCAL, NULL, 4, NULL,
0, &dwNeeded, &dwReturned) ;
pinfo4 = malloc (dwNeeded) ;
EnumPrinters (PRINTER_ENUM_LOCAL, NULL, 4, (PBYTE) pinfo4,
dwNeeded, &dwNeeded, &dwReturned) ;
for (i = 0 ; i < dwReturned ; i++)
{
AppendMenu (hMenu, (i+1) % 16 ? 0 : MF_MENUBARBREAK, i + 1,
pinfo4[i].pPrinterName) ;
}
free (pinfo4) ;
}
AppendMenu (hMenu, MF_SEPARATOR, 0, NULL) ;
AppendMenu (hMenu, 0, IDM_DEVMODE, TEXT ("Properties")) ;
wParam = IDM_SCREEN ;
// fall through
case WM_COMMAND :
hMenu = GetMenu (hwnd) ;
if ( LOWORD (wParam) == IDM_SCREEN || // IDM_SCREEN & Printers
LOWORD (wParam) < IDM_DEVMODE)
{
CheckMenuItem (hMenu, nCurrentDevice, MF_UNCHECKED) ;
nCurrentDevice = LOWORD (wParam) ;
CheckMenuItem (hMenu, nCurrentDevice, MF_CHECKED) ;
}
else if (LOWORD (wParam) == IDM_DEVMODE) // Properties selection
{
GetMenuString (hMenu, nCurrentDevice, szDevice,
sizeof (szDevice) / sizeof (TCHAR), MF_BYCOMMAND);
if (OpenPrinter (szDevice, &hPrint, NULL))
{
PrinterProperties (hwnd, hPrint) ;
ClosePrinter (hPrint) ;
}
}
else
// info menu items
{
CheckMenuItem (hMenu, nCurrentInfo, MF_UNCHECKED) ;
nCurrentInfo = LOWORD (wParam) ;
CheckMenuItem (hMenu, nCurrentInfo, MF_CHECKED) ;
}
InvalidateRect (hwnd, NULL, TRUE) ;
return 0 ;
case WM_INITMENUPOPUP :
if (lParam == 0)
EnableMenuItem (GetMenu (hwnd), IDM_DEVMODE,
nCurrentDevice == IDM_SCREEMF_GRAYED : MF_ENABLED) ;
return 0 ;
case WM_PAINT :
lstrcpy (szWindowText, TEXT ("Device Capabilities: ")) ;
if (nCurrentDevice == IDM_SCREEN)
{
lstrcpy (szDevice, TEXT ("DISPLAY")) ;
hdcInfo = CreateIC (szDevice, NULL, NULL, NULL) ;
}
else
{
hMenu = GetMenu (hwnd) ;
GetMenuString (hMenu, nCurrentDevice, szDevice,
sizeof (szDevice), MF_BYCOMMAND) ;
hdcInfo = CreateIC (NULL, szDevice, NULL, NULL) ;
}
}
lstrcat (szWindowText, szDevice) ;
SetWindowText (hwnd, szWindowText) ;
hdc = BeginPaint (hwnd, &ps) ;
SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT)) ;
if (hdcInfo)
{
switch (nCurrentInfo)
{
case IDM_BASIC :
DoBasicInfo (hdc, hdcInfo, cxChar, cyChar) ;
break ;
case IDM_OTHER :
DoOtherInfo (hdc, hdcInfo, cxChar, cyChar) ;
break ;
case IDM_CURVE :
case IDM_LINE :
case IDM_POLY :
case IDM_TEXT :
DoBitCodedCaps (hdc, hdcInfo, cxChar, cyChar,
nCurrentInfo - IDM_CURVE) ;
break ;
}
DeleteDC (hdcInfo) ;
}
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY :
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
void DoBasicInfo (HDC hdc, HDC hdcInfo, int cxChar, int cyChar)
{
static struct
{
int nIndex ;
TCHAR * szDesc ;
}
info[] =
{
HORZSIZE, TEXT ("HORZSIZE Width in millimeters:"),
VERTSIZE, TEXT ("VERTSIZE Height in millimeters:"),
HORZRES, TEXT ("HORZRES Width in pixels:"),
VERTRES, TEXT ("VERTRES Height in raster lines:"),
BITSPIXEL, TEXT ("BITSPIXEL Color bits per pixel:"),
PLANES, TEXT ("PLANES Number of color planes:"),
NUMBRUSHES, TEXT ("NUMBRUSHES Number of device brushes:"),
NUMPENS, TEXT ("NUMPENS Number of device pens:"),
NUMMARKERS, TEXT ("NUMMARKERS Number of device markers:"),
NUMFONTS, TEXT ("NUMFONTS Number of device fonts:"),
NUMCOLORS, TEXT ("NUMCOLORS Number of device colors:"),
PDEVICESIZE, TEXT("PDEVICESIZESize of device structure:"),
ASPECTX, TEXT("ASPECTX Relative width of pixel:"),
ASPECTY, TEXT("ASPECTY Relative height of pixel:"),
ASPECTXY, TEXT("ASPECTXY Relative diagonal of pixel:"),
LOGPIXELSX, TEXT("LOGPIXELSX Horizontal dots per inch:"),
LOGPIXELSX, TEXT("LOGPIXELSX Horizontal dots per inch:"),
LOGPIXELSY, TEXT("LOGPIXELSY Vertical dots per inch:"),
SIZEPALETTE, TEXT("SIZEPALETTE Number of palette entries:"),
NUMRESERVED, TEXT("NUMRESERVED Reserved palette entries:"),
COLORRES, TEXT("COLORRES Actual color resolution:"),
PHYSICALWIDTH, TEXT("PHYSICALWIDTH Printer page pixel width:"),
PHYSICALHEIGHT,TEXT("PHYSICALHEIGHT Printer page pixel height:"),
PHYSICALOFFSETX,TEXT("PHYSICALOFFSETX Printer page x offset:"),
PHYSICALOFFSETY,TEXT("PHYSICALOFFSETY Printer page y offset:")
} ;
int i ;
TCHAR szBuffer[80] ;
for (i = 0 ; i < sizeof (info) / sizeof (info[0]) ; i++)
TextOut (hdc, cxChar, (i + 1) * cyChar, szBuffer,
wsprintf (szBuffer, TEXT ("%-45s%8d"), info[i].szDesc,
GetDeviceCaps (hdcInfo, info[i].nIndex))) ;
}
void DoOtherInfo (HDC hdc, HDC hdcInfo, int cxChar, int cyChar)
{
static BITS clip[] =
{
CP_RECTANGLE, TEXT ("CP_RECTANGLE Can Clip To Rectangle:")
} ;
static BITS raster[] =
{
RC_BITBLT, TEXT ("RC_BITBLT Capable of simple BitBlt:"),
RC_BANDING, TEXT ("RC_BANDING Requires banding support:"),
RC_SCALING, TEXT ("RC_SCALING Requires scaling support:"),
RC_BITMAP64, TEXT ("RC_BITMAP64 Supports bitmaps >64K:"),
RC_GDI20_OUTPUT, TEXT ("RC_GDI20_OUTPUT Has 2.0 output calls:"),
RC_DI_BITMAP, TEXT ("RC_DI_BITMAP Supports DIB to memory:"),
RC_PALETTE, TEXT ("RC_PALETTE Supports a palette:"),
RC_DIBTODEV, TEXT ("RC_DIBTODEV Supports bitmap conversion:"),
RC_BIGFONT, TEXT ("RC_BIGFONT Supports fonts >64K:"),
RC_STRETCHBLT,TEXT ("RC_STRETCHBLT Supports StretchBlt:"),
RC_FLOODFILL, TEXT ("RC_FLOODFILL Supports FloodFill:"),
RC_STRETCHDIB,TEXT ("RC_STRETCHDIB Supports StretchDIBits:")
} ;
static TCHAR * szTech[]= { TEXT ("DT_PLOTTER (Vector plotter)"),
TEXT ("DT_RASDISPLAY (Raster display)"),
TEXT ("DT_RASPRINTER (Raster printer)"),
TEXT ("DT_RASCAMERA (Raster camera)"),
TEXT ("DT_CHARSTREAM (Character stream)"),
TEXT ("DT_METAFILE (Metafile)"),
TEXT ("DT_DISPFILE (Display file)") } ;
int i ;
TCHAR szBuffer[80] ;
TextOut (hdc, cxChar, cyChar, szBuffer,
wsprintf (szBuffer, TEXT ("%-24s%04XH"), TEXT ("DRIVERVERSION:"),
GetDeviceCaps (hdcInfo, DRIVERVERSION))) ;
TextOut (hdc, cxChar, 2 * cyChar, szBuffer,
wsprintf (szBuffer, TEXT ("%-24s%-40s"), TEXT ("TECHNOLOGY:"),
szTech[GetDeviceCaps (hdcInfo, TECHNOLOGY)])) ;
TextOut (hdc, cxChar, 4 * cyChar, szBuffer,
wsprintf (szBuffer, TEXT ("CLIPCAPS (Clipping capabilities)"))) ;
for (i = 0 ; i < sizeof (clip) / sizeof (clip[0]) ; i++)
TextOut (hdc, 9 * cxChar, (i + 6) * cyChar, szBuffer,
wsprintf (szBuffer, TEXT ("%-45s %3s"), clip[i].szDesc,
GetDeviceCaps (hdcInfo, CLIPCAPS) & clip[i].iMask ?
TEXT ("Yes") : TEXT ("No"))) ;
TextOut (hdc, cxChar, 8 * cyChar, szBuffer,
TextOut (hdc, cxChar, 8 * cyChar, szBuffer,
wsprintf (szBuffer, TEXT ("RASTERCAPS (Raster capabilities)"))) ;
for (i = 0 ; i < sizeof (raster) / sizeof (raster[0]) ; i++)
TextOut (hdc, 9 * cxChar, (i + 10) * cyChar, szBuffer,
wsprintf (szBuffer, TEXT ("%-45s %3s"), raster[i].szDesc,
GetDeviceCaps (hdcInfo, RASTERCAPS) & raster[i].iMask ?
TEXT ("Yes") : TEXT ("No"))) ;
}
void DoBitCodedCaps ( HDC hdc, HDC hdcInfo, int cxChar, int cyChar,int iType)
{
static BITS curves[] =
{
CC_CIRCLES, TEXT ("CC_CIRCLES Can do circles:"),
CC_PIE, TEXT ("CC_PIE Can do pie wedges:"),
CC_CHORD, TEXT ("CC_CHORD Can do chord arcs:"),
CC_ELLIPSES, TEXT ("CC_ELLIPSES Can do ellipses:"),
CC_WIDE, TEXT ("CC_WIDE Can do wide borders:"),
CC_STYLED, TEXT ("CC_STYLED Can do styled borders:"),
CC_WIDESTYLED, TEXT ("CC_WIDESTYLED Can do wide and styled borders:"),
CC_INTERIORS, TEXT ("CC_INTERIORS Can do interiors:")
} ;
static BITS lines[] =
{
LC_POLYLINE, TEXT ("LC_POLYLINE Can do polyline:"),
LC_MARKER, TEXT ("LC_MARKER Can do markers:"),
LC_POLYMARKER, TEXT ("LC_POLYMARKER Can do polymarkers"),
LC_WIDE, TEXT ("LC_WIDE Can do wide lines:"),
LC_STYLED, TEXT ("LC_STYLED Can do styled lines:"),
LC_WIDESTYLED, TEXT ("LC_WIDESTYLED Can do wide and styled lines:"),
LC_INTERIORS, TEXT ("LC_INTERIORS Can do interiors:")
} ;
static BITS poly[] =
{
PC_POLYGON,
TEXT ("PC_POLYGON Can do alternate fill polygon:"),
PC_RECTANGLE, TEXT ("PC_RECTANGLE Can do rectangle:"),
PC_WINDPOLYGON,
TEXT ("PC_WINDPOLYGON Can do winding number fill polygon:"),
PC_SCANLINE, TEXT ("PC_SCANLINE Can do scanlines:"),
PC_WIDE, TEXT ("PC_WIDE Can do wide borders:"),
PC_STYLED, TEXT ("PC_STYLED Can do styled borders:"),
PC_WIDESTYLED,
TEXT ("PC_WIDESTYLED Can do wide and styled borders:"),
PC_INTERIORS, TEXT ("PC_INTERIORS Can do interiors:")
} ;
static BITS text[] =
{
TC_OP_CHARACTER, TEXT ("TC_OP_CHARACTER Can do character output precision:"),
TC_OP_STROKE, TEXT ("TC_OP_STROKE Can do stroke output precision:"),
TC_CP_STROKE, TEXT ("TC_CP_STROKE Can do stroke clip precision:"),
TC_CR_90, TEXT ("TC_CP_90 Can do 90 degree character rotation:"),
TC_CR_ANY, TEXT ("TC_CR_ANY Can do any character rotation:"),
TC_SF_X_YINDEP, TEXT ("TC_SF_X_YINDEP Can do scaling independent of X and Y:"),
TC_SA_DOUBLE, EXT ("TC_SA_DOUBLE Can do doubled character for scaling:"),
TC_SA_INTEGER, TEXT ("TC_SA_INTEGER Can do integer multiples for scaling:"),
TC_SA_CONTIN, TEXT ("TC_SA_CONTIN Can do any multiples for exact scaling:"),
TC_EA_DOUBLE, TEXT ("TC_EA_DOUBLE Can do double weight characters:"),
TC_IA_ABLE, TEXT ("TC_IA_ABLE Can do italicizing:"),
TC_UA_ABLE, TEXT ("TC_UA_ABLE Can do underlining:"),
TC_SO_ABLE, TEXT ("TC_SO_ABLE Can do strikeouts:"),
TC_RA_ABLE, TEXT ("TC_RA_ABLE Can do raster fonts:"),
TC_VA_ABLE, TEXT ("TC_VA_ABLE Can do vector fonts:")
} ;
static struct
{
int iIndex ;
TCHAR * szTitle ;
BITS (*pbits)[] ;
int iSize ;
}
bitinfo[] =
{
CURVECAPS, TEXT ("CURVCAPS (Curve Capabilities)"),
(BITS (*)[]) curves, sizeof (curves) / sizeof (curves[0]),
LINECAPS, TEXT ("LINECAPS (Line Capabilities)"),
(BITS (*)[]) lines, sizeof (lines) / sizeof (lines[0]),
POLYGONALCAPS, TEXT ("POLYGONALCAPS (Polygonal Capabilities)"),
(BITS (*)[]) poly, sizeof (poly) / sizeof (poly[0]),
TEXTCAPS, TEXT ("TEXTCAPS (Text Capabilities)"),
(BITS (*)[]) text, sizeof (text) / sizeof (text[0])
} ;
static TCHAR szBuffer[80] ;
BITS (*pbits)[] = bitinfo[iType].pbits ;
int i, iDevCaps = GetDeviceCaps (hdcInfo, bitinfo[iType].iIndex) ;
TextOut (hdc, cxChar, cyChar, bitinfo[iType].szTitle,
lstrlen (bitinfo[iType].szTitle)) ;
for (i = 0 ; i < bitinfo[iType].iSize ; i++)
extOut (hdc, cxChar, (i + 3) * cyChar, szBuffer,
wsprintf (szBuffer, TEXT ("%-55s %3s"), (*pbits)[i].szDesc,
iDevCaps & (*pbits)[i].iMask ? TEXT ("Yes") : TEXT ("No")));
}
(摘录)
//Microsoft Developer Studio generated resource script.
#include "resource.h"
#include "afxres.h"
/
// Menu
DEVCAPS2 MENU DISCARDABLE
BEGIN
POPUP "&Device"
BEGIN
MENUITEM "&Screen",IDM_SCREEN, CHECKED
END
POPUP "&Capabilities"
BEGIN
MENUITEM "&Basic Information",IDM_BASIC
MENUITEM "&Other Information",IDM_OTHER
MENUITEM "&Curve Capabilities",IDM_CURVE
MENUITEM "&Line Capabilities",IDM_LINE
MENUITEM "&Polygonal Capabilities",IDM_POLY
MENUITEM "&Text Capabilities",IDM_TEXT
END
END
RESOURCE.H (摘录)
= CS_HREDRAW | CS_VREDRAW ;
dProc = WndProc ;
xtra = 0 ;
xtra = 0 ;
nce = hInstance ;
= LoadIcon (NULL, IDI_APPLICATION) ;
r = LoadCursor (NULL, IDC_ARROW) ;
kground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
nuName = NULL ;
assName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox ( NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hInst = hInstance ;
hwnd = CreateWindow (szAppName, szCaption,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return ;
}
void PageGDICalls (HDC hdcPrn, int cxPage, int cyPage)
{
static TCHAR szTextStr[] = TEXT ("Hello, Printer!") ;
Rectangle (hdcPrn, 0, 0, cxPage, cyPage) ;
MoveToEx (hdcPrn, 0, 0, NULL) ;
LineTo (hdcPrn, cxPage, cyPage) ;
MoveToEx (hdcPrn, cxPage, 0, NULL) ;
LineTo (hdcPrn, 0, cyPage) ;
SaveDC (hdcPrn) ;
SetMapMode (hdcPrn, MM_ISOTROPIC) ;
SetWindowExtEx (hdcPrn, 1000, 1000, NULL) ;
SetViewportExtEx (hdcPrn, cxPage / 2, -cyPage / 2, NULL) ;
SetViewportOrgEx (hdcPrn, cxPage / 2, cyPage / 2, NULL) ;
Ellipse (hdcPrn, -500, 500, 500, -500) ;
SetTextAlign (hdcPrn, TA_BASELINE | TA_CENTER) ;
TextOut (hdcPrn, 0, 0, szTextStr, lstrlen (szTextStr)) ;
RestoreDC (hdcPrn, -1) ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,LPARAM lParam)
{
static int cxClient, cyClient ;
HDC hdc ;
HMENU hMenu ;
PAINTSTRUCT ps ;
switch (message)
{
case WM_CREATE:
hMenu = GetSystemMenu (hwnd, FALSE) ;
AppendMenu (hMenu, MF_SEPARATOR, 0, NULL) ;
AppendMenu (hMenu, 0, 1, TEXT ("&Print")) ;
return 0 ;
case WM_SIZE:
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
return 0 ;
case WM_SYSCOMMAND:
if (wParam == 1)
{
if (!PrintMyPage (hwnd))
MessageBox (hwnd, TEXT ("Could not print page!"),
szAppName, MB_OK | MB_ICONEXCLAMATION) ;
return 0 ;
}
break ;
case WM_PAINT :
hdc = BeginPaint (hwnd, &ps) ;
PageGDICalls (hdc, cxClient, cyClient) ;
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY :
PostQuitMessage (0) ;
BOOL PrintMyPage (HWND hwnd)
{
static DOCINFO di = { sizeof (DOCINFO), TEXT ("Print2: Printing") } ;
BOOL bSuccess = TRUE ;
HDC hdcPrn ;
short xPage, yPage ;
if (NULL == (hdcPrn = GetPrinterDC ()))
return FALSE ;
xPage = GetDeviceCaps (hdcPrn, HORZRES) ;
yPage = GetDeviceCaps (hdcPrn, VERTRES) ;
EnableWindow (hwnd, FALSE) ;
SetAbortProc (hdcPrn, AbortProc) ;
if (StartDoc (hdcPrn, &di) > 0)
{
if (StartPage (hdcPrn) > 0)
{
PageGDICalls (hdcPrn, xPage, yPage) ;
if (EndPage (hdcPrn) > 0)
EndDoc (hdcPrn) ;
else
bSuccess = FALSE ;
}
}
else
bSuccess = FALSE ;
EnableWindow (hwnd, TRUE) ;
DeleteDC (hdcPrn) ;
return bSuccess ;
}
EnableMenuItem (GetSystemMenu (hDlg, FALSE), SC_CLOSE, MF_GRAYED) ;
return TRUE ;
case WM_COMMAND:
bUserAbort = TRUE ;
EnableWindow (GetParent (hDlg), TRUE) ;
DestroyWindow (hDlg) ;
hDlgPrint = NULL ;
return TRUE ;
}
return FALSE ;
}
BOOL CALLBACK AbortProc (HDC hdcPrn, int iCode)
{
MSG msg ;
while (!bUserAbort && PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
{
if (!hDlgPrint || !IsDialogMessage (hDlgPrint, &msg))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
}
return !bUserAbort ;
}
BOOL PrintMyPage (HWND hwnd)
{
static DOCINFO di = { sizeof (DOCINFO), TEXT ("Print3: Printing") } ;
BOOL bSuccess = TRUE ;
HDC hdcPrn ;
int xPage, yPage ;
if (NULL == (hdcPrn = GetPrinterDC ()))
return FALSE ;
xPage = GetDeviceCaps (hdcPrn, HORZRES) ;
yPage = GetDeviceCaps (hdcPrn, VERTRES) ;
EnableWindow (hwnd, FALSE) ;
bUserAbort = FALSE ;
hDlgPrint = CreateDialog (hInst, TEXT ("PrintDlgBox"),
hwnd, PrintDlgProc) ;
SetAbortProc (hdcPrn, AbortProc) ;
if (StartDoc (hdcPrn, &di) > 0)
{
if (StartPage (hdcPrn) > 0)
{
PageGDICalls (hdcPrn, xPage, yPage) ;
if (EndPage (hdcPrn) > 0)
EndDoc (hdcPrn) ;
else
bSuccess = FALSE ;
}
}
else
bSuccess = FALSE ;
if (!bUserAbort)
{
EnableWindow (hwnd, TRUE) ;
DestroyWindow (hDlgPrint) ;
}
DeleteDC (hdcPrn) ;
return bSuccess && !bUserAbort ;
}
POPPRNT.C -- Popup Editor Printing Functions
-----------------------------------------------------------------------*/
#include
#include
#include "resource.h"
BOOL bUserAbort ;
HWND hDlgPrint ;
BOOL CALLBACK PrintDlgProc ( HWND hDlg, UINT msg, WPARAM wParam,LPARAM lParam)
{
switch (msg)
{
case WM_INITDIALOG :
EnableMenuItem (GetSystemMenu (hDlg, FALSE), SC_CLOSE, MF_GRAYED) ;
return TRUE ;
case WM_COMMAND :
bUserAbort = TRUE ;
EnableWindow (GetParent (hDlg), TRUE) ;
DestroyWindow (hDlg) ;
hDlgPrint = NULL ;
return TRUE ;
}
return FALSE ;
}
BOOL CALLBACK AbortProc (HDC hPrinterDC, int iCode)
{
MSG msg ;
while (!bUserAbort && PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
{
if (!hDlgPrint || !IsDialogMessage (hDlgPrint, &msg))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
}
return !bUserAbort ;
}
BOOL PopPrntPrintFile (HINSTANCE hInst, HWND hwnd, HWND hwndEdit,
PTSTR szTitleName)
{
static DOCINFO di = { sizeof (DOCINFO) } ;
static PRINTDLG pd ;
BOOL bSuccess ;
int yChar, iCharsPerLine, iLinesPerPage, iTotalLines,
iTotalPages, iPage, iLine, iLineNum ;
PTSTR pstrBuffer ;
TCHAR szJobName [64 + MAX_PATH] ;
TEXTMETRIC tm ;
WORD iColCopy, iNoiColCopy ;
// Invoke Print common dialog box
tSize = sizeof (PRINTDLG) ;
ner = hwnd ;
de = NULL ;
mes = NULL ;
= NULL ;
= PD_ALLPAGES | PD_COLLATE |
PD_RETURNDC | PD_NOSELECTION ;
age = 0 ;
e = 0 ;
ge = 0 ;
ge = 0 ;
s = 1 ;
s = 1 ;
nce = NULL ;
ata = 0L ;
intHook = NULL ;
tupHook = NULL ;
tTemplateName = NULL ;
pTemplateName = NULL ;
Template = NULL ;
Template = NULL ;
if (!PrintDlg (&pd))
return TRUE ;
if (0 == (iTotalLines = SendMessage (hwndEdit, EM_GETLINECOUNT, 0, 0)))
return TRUE ;
// Calculate necessary metrics for file
GetTextMetrics (, &tm) ;
yChar = ht + rnalLeading ;
iCharsPerLine = GetDeviceCaps (, HORZRES) / harWidth ;
iLinesPerPage = GetDeviceCaps (, VERTRES) / yChar ;
iTotalPages = (iTotalLines + iLinesPerPage - 1) / iLinesPerPage ;
// Allocate a buffer for each line of text
pstrBuffer = malloc (sizeof (TCHAR) * (iCharsPerLine + 1)) ;
// Display the printing dialog box
EnableWindow (hwnd, FALSE) ;
bSuccess = TRUE ;
bUserAbort = FALSE ;
hDlgPrint = CreateDialog (hInst, TEXT ("PrintDlgBox"),
hwnd, PrintDlgProc) ;
SetDlgItemText (hDlgPrint, IDC_FILENAME, szTitleName) ;
SetAbortProc (, AbortProc) ;
// Start the document
GetWindowText (hwnd, szJobName, sizeof (szJobName)) ;
cName = szJobName ;
if (StartDoc (, &di) > 0)
{
// Collation requires this loop and iNoiColCopy
for (iColCopy = 0 ;
iColCopy < ((WORD) & PD_COLLATE ? s : 1) ;
iColCopy++)
{
for (iPage = 0 ; iPage < iTotalPages ; iPage++)
{
for (iNoiColCopy = 0 ;
iNoiColCopy < ( & PD_COLLATE ? 1 : s);
iNoiColCopy++)
{
// Start the page
if (StartPage () < 0)
{
bSuccess = FALSE ;
break ;
}
// For each page, print the lines
for (iLine = 0 ; iLine < iLinesPerPage ; iLine++)
{
iLineNum = iLinesPerPage * iPage + iLine ;
if (iLineNum > iTotalLines)
break ;
*(int *) pstrBuffer = iCharsPerLine ;
TextOut (, 0, yChar * iLine, pstrBuffer,
(int) SendMessage (hwndEdit, EM_GETLINE,
(WPARAM) iLineNum, (LPARAM) pstrBuffer));
}
if (EndPage () < 0)
{
bSuccess = FALSE ;
break ;
}
if (bUserAbort)
break ;
}
if (!bSuccess || bUserAbort)
break ;
}
if (!bSuccess || bUserAbort)
break ;
}
}
else
bSuccess = FALSE ;
if (bSuccess)
EndDoc () ;
if (!bUserAbort)
{
EnableWindow (hwnd, TRUE) ;
版权声明:本文标题:教你怎么使用打印机(api) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/free/1705472402h486181.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论