PAINT_PR.C
资源名称:winpaint.zip [点击查看]
上传用户:cncajx
上传日期:2007-01-03
资源大小:190k
文件大小:4k
源码类别:
GDI/图象编程
开发平台:
Visual C++
- 1 #include "paint.h"
- 2 #include <windows.h>
- 3
- 4 BOOL FAR PASCAL AbortProc(HWND, short);
- 5 BOOL FAR PASCAL PrnDlgProc(HWND, WORD, WORD, LONG);
- 6
- 7 BOOL bCancel;
- 8 HWND hPrnDlg;
- 9
- 10 extern HDC hMemDC;
- 11 extern HANDLE hInst;
- 12
- 13
- 14 HDC CreateDC_Printer()
- 15 {
- 16 HDC hPrnDC;
- 17 char szProfile[70];
- 18 char *szDriver, *szDevice, *szOutput;
- 19
- 20 GetProfileString("windows", "device", "", szProfile, 70);
- 21
- 22 szDevice = (char *) strtok(szProfile, ",");
- 23 szDriver = (char *) strtok(NULL, ",");
- 24 szOutput = (char *) strtok(NULL, ",");
- 25
- 26 if (szDevice && szDriver && szOutput)
- 27 {
- 28 hPrnDC = CreateDC(szDriver, szDevice, szOutput, NULL);
- 29 return (hPrnDC);
- 30 }
- 31
- 32 return (NULL);
- 33 }
- 34
- 35
- 36
- 37 void PrintGraph(HWND hWnd, int MemX, int MemY)
- 38 {
- 39 HDC hPrnDC;
- 40 BOOL bPrinted = TRUE;
- 41 FARPROC lpAbortProc;
- 42 FARPROC lpPrnDlgProc;
- 43 char szName[] = "Paint - Printing";
- 44
- 45 hPrnDC = CreateDC_Printer();
- 46 if (hPrnDC == NULL)
- 47 {
- 48 MessageBox(hWnd, "Printer Error", NULL,
- 49 MB_OK | MB_ICONHAND);
- 50 return ;
- 51 }
- 52
- 53 lpPrnDlgProc = MakeProcInstance(PrnDlgProc, hInst);
- 54 lpAbortProc = MakeProcInstance(AbortProc, hInst);
- 55
- 56 bCancel = FALSE;
- 57 hPrnDlg = CreateDialog(hInst, "PRNDLG", hWnd,
- 58 lpPrnDlgProc);
- 59 Escape(hPrnDC, SETABORTPROC, 0, (LPSTR) lpAbortProc,
- 60 NULL);
- 61
- 62 if (Escape(hPrnDC, STARTDOC,
- 63 strlen(szName), szName, NULL) > 0)
- 64 {
- 65 BitBlt(hPrnDC, 0, 0, MemX, MemY,
- 66 hMemDC, 0, 0, SRCCOPY);
- 67
- 68 if (Escape(hPrnDC, NEWFRAME, 0, NULL, NULL) > 0)
- 69 Escape(hPrnDC, ENDDOC, 0, NULL, NULL);
- 70 else
- 71 bPrinted = FALSE;
- 72 }
- 73 else
- 74 bPrinted = FALSE;
- 75
- 76 if (! bPrinted)
- 77 MessageBox(hWnd, "Print Error", NULL,
- 78 MB_OK | MB_ICONHAND);
- 79
- 80 if (! bCancel)
- 81 {
- 82 EnableWindow(hWnd, TRUE);
- 83 DestroyWindow(hPrnDlg);
- 84 }
- 85
- 86 DeleteDC(hPrnDC);
- 87 FreeProcInstance(lpPrnDlgProc);
- 88 FreeProcInstance(lpAbortProc);
- 89 }
- 90
- 91
- 92 BOOL FAR PASCAL AbortProc(HDC hPrnDC, short nCode)
- 93 {
- 94 MSG msg;
- 95
- 96 while (!bCancel &&
- 97 PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
- 98 {
- 99 if (! IsDialogMessage(hPrnDlg, &msg))
- 100 {
- 101 TranslateMessage(&msg);
- 102 DispatchMessage(&msg);
- 103 }
- 104 }
- 105
- 106 return (! bCancel);
- 107 }
- 108
- 109
- 110 BOOL FAR PASCAL PrnDlgProc(HWND hDlg, WORD msg,
- 111 WORD wParam, LONG lParam)
- 112 {
- 113 HWND hPWnd;
- 114 HMENU hSysMenu;
- 115
- 116 switch (msg)
- 117 {
- 118 case WM_INITDIALOG :
- 119 hPWnd = GetParent(hDlg);
- 120 EnableWindow(hPWnd, FALSE);
- 121
- 122 hSysMenu = GetSystemMenu(hDlg, 0);
- 123 EnableMenuItem(hSysMenu, SC_CLOSE,
- 124 MF_GRAYED);
- 125 return (TRUE);
- 126
- 127 case WM_COMMAND :
- 128 switch (wParam)
- 129 {
- 130 case DI_CANCEL :
- 131 bCancel = TRUE;
- 132 hPWnd = GetParent(hDlg);
- 133 EnableWindow(hPWnd, TRUE);
- 134 DestroyWindow(hDlg);
- 135 break;
- 136 }
- 137 return (TRUE);
- 138 }
- 139
- 140 return (FALSE);
- 141 }