|
|
1.1 ! root 1: /************************************************************************ ! 2: ! 3: File: print.c ! 4: ! 5: Purpose: To manage CDTEST's print dialog box. ! 6: ! 7: ! 8: Functions: ! 9: ! 10: DoPrintDlg() -- Creates CDTEST's print dialog box. ! 11: ! 12: PrintProc() -- Callback function for CDTEST's print dialog box. ! 13: ! 14: DevnamesProc() -- Callback function for CDTESTS Devnames dlg box. ! 15: ! 16: DevmodeProc() -- Callback function for CDTESTS Devmode dlg box. ! 17: ! 18: InitPrintStruct() -- Fills a PRINTDLG struct with some default values. ! 19: ! 20: FillPrintDlg() -- Fills CDTEST's print dialog with contents of a ! 21: PRINTDLG structure. ! 22: ! 23: GetPrintDlg() -- Retrieves the users edits from CDTEST's print dlg. ! 24: ! 25: FillDevnamesDlg() -- Fills CDTEST's Devnames dialog with the contents ! 26: of a DEVNAMES structure. ! 27: ! 28: GetDevnamesDlg() -- Retrieves the user's edits from CDTEST's devnames dlg. ! 29: ! 30: FillDevmodeDlg() -- Fills CDTEST's devmode dialog with the contents of ! 31: a DEVMODE structure. ! 32: ! 33: GetDevmodeDlg() -- Retrieves the user's edits from CDTEST's devmode dlg. ! 34: ! 35: GetPrintDlgHandle() -- Loads and returns a handle to a Print dlg custom template. ! 36: ! 37: GetSetupDlgHandle() -- Loads and returns a handle to a Setup dlg custom template. ! 38: ! 39: PrintHookProc() -- Callback function for PRINTDLG->lpfnPrintHook and ! 40: for PRINTDLG->lpfnSetupHook ! 41: ! 42: PrintMultiProc1() -- Starting address for multithread option thread 1 ! 43: ! 44: PrintMultiProc2() -- Starting address for multithread option thread 2 ! 45: ! 46: MultiThreadPrintDlg() -- Creates two threads which each call PrintDlg() ! 47: ! 48: EnablePrintControls() -- Enables or disables CDTEST's print dlg controls. ! 49: ! 50: DoPrintDlgStuff() -- Calls PrintDlg() ! 51: ! 52: ************************************************************************/ ! 53: ! 54: ! 55: #include <windows.h> ! 56: #include <commdlg.h> ! 57: #include <stdlib.h> ! 58: #include <winnls.h> ! 59: #include "cdtest.h" ! 60: #include "print.h" ! 61: #include "devnames.h" ! 62: #include "devmode.h" ! 63: #include "dlgs.h" ! 64: ! 65: ! 66: ! 67: /* Externs, prototypes, variable declarations for print.c */ ! 68: ! 69: extern UINT uMode ; ! 70: extern LONG MyAtol(LPTSTR, BOOL, LPBOOL) ; ! 71: UINT APIENTRY PrintHookProc(HWND hwnd, UINT msg, UINT wParam, LONG lParam) ; ! 72: void InitPrintStruct(HWND, LPPRINTDLG) ; ! 73: void FillPrintDlg(HWND, LPPRINTDLG) ; ! 74: void GetPrintDlg(HWND, LPPRINTDLG) ; ! 75: void FillDevnamesDlg(HWND, LPPRINTDLG) ; ! 76: void GetDevnamesDlg(HWND, LPPRINTDLG) ; ! 77: void FillDevmodeDlg(HWND, LPPRINTDLG) ; ! 78: void GetDevmodeDlg(HWND, LPPRINTDLG) ; ! 79: HANDLE GetPrintDlgHandle(void) ; ! 80: HANDLE GetSetupDlgHandle(void) ; ! 81: void DoPrintDlgStuff(HWND, LPPRINTDLG) ; ! 82: ! 83: HANDLE hResPrint ; ! 84: HANDLE hDialogPrint ; ! 85: PRINTDLG pd ; ! 86: HANDLE hDevNames ; ! 87: HANDLE hDevMode ; ! 88: ! 89: TCHAR szDriverOffset[100] ; ! 90: TCHAR szDeviceOffset[100] ; ! 91: TCHAR szOutputOffset[100] ; ! 92: TCHAR szPrintTempName[40] ; ! 93: TCHAR szSetupTempName[40] ; ! 94: ! 95: ! 96: /* Multithreading function declarations, variables */ ! 97: ! 98: DWORD PrintMultiProc1(LPDWORD) ; ! 99: DWORD PrintMultiProc2(LPDWORD) ; ! 100: void MultiThreadPrintDlg(void) ; ! 101: void EnablePrintControls(HWND, BOOL) ; ! 102: ! 103: HANDLE hPrintThread1 ; ! 104: HANDLE hPrintThread2 ; ! 105: DWORD dwPrintThreadID1 ; ! 106: DWORD dwPrintThreadID2 ; ! 107: DWORD dwPrintThreadParm1 ; ! 108: DWORD dwPrintThreadParm2 ; ! 109: PRINTDLG pdThread1 ; ! 110: PRINTDLG pdThread2 ; ! 111: HWND hwndMainPrint ; ! 112: int nOpenDialogCount ; ! 113: ! 114: HBRUSH hBrushDlg ; ! 115: HBRUSH hBrushEdit ; //brush handles for new colors done with hook proc ! 116: HBRUSH hBrushButton ; ! 117: ! 118: ! 119: ! 120: ! 121: ! 122: /************************************************************************ ! 123: ! 124: Function: DoPrintDialog(HWND) ! 125: ! 126: Purpose: Creates CDTEST's print dialog box. ! 127: ! 128: Returns: Nothing. ! 129: ! 130: Comments: There is only one dialog for both Print Setup and Print Print. ! 131: The Print Print dialog is the default. To create the Print ! 132: Setup dialog, enter the value for PD_PRINTSETUP into the ! 133: "Flags" edit box and click OK. ! 134: ! 135: ************************************************************************/ ! 136: ! 137: void DoPrintDialog(HWND hwnd) ! 138: { ! 139: ! 140: ! 141: DialogBox(hInst, MAKEINTRESOURCE(ID_PRINTDIALOG), ! 142: hwnd, PrintProc) ; ! 143: ! 144: } ! 145: ! 146: ! 147: ! 148: ! 149: ! 150: ! 151: ! 152: /************************************************************************ ! 153: ! 154: Function: PrintProc(HWND, UINT, UINT, LONG) ! 155: ! 156: Purpose: Callback function for CDTEST's print dialog box. ! 157: ! 158: Returns: TRUE or FALSE depending on the situation/message. ! 159: ! 160: Comments: ! 161: ! 162: ************************************************************************/ ! 163: ! 164: BOOL APIENTRY PrintProc(HWND hwnd, UINT msg, UINT wParam, LONG lParam) ! 165: { ! 166: switch (msg) ! 167: { ! 168: case WM_INITDIALOG: ! 169: ! 170: InitPrintStruct(hwnd, &pd) ; ! 171: FillPrintDlg(hwnd, &pd) ; ! 172: ! 173: *(&pdThread1) = *(&pdThread2) = *(&pd) ; ! 174: ! 175: hwndMainPrint = hwnd ; ! 176: ! 177: nOpenDialogCount = 0 ; ! 178: ! 179: SetFocus(GetDlgItem(hwnd, ID_STRUCTSIZEP)) ; ! 180: ! 181: break ; ! 182: ! 183: ! 184: case UMSG_DECREMENTDLGCOUNT: //user defined message that is send when ! 185: //each thread created when multithreading ends ! 186: nOpenDialogCount-- ; ! 187: ! 188: if (nOpenDialogCount == 0) //once both multitheading dlgs ! 189: EnablePrintControls(hwnd, TRUE) ; //are done, enable the controls again ! 190: ! 191: break ; ! 192: ! 193: ! 194: case WM_COMMAND: ! 195: { ! 196: switch (LOWORD(wParam)) ! 197: { ! 198: case IDOK: ! 199: GetPrintDlg(hwnd, &pd) ; ! 200: DoPrintDlgStuff(hwnd, &pd) ; ! 201: break ; ! 202: ! 203: case IDCANCEL: ! 204: ! 205: if (pd.hDC) ! 206: ReleaseDC(hwnd, pd.hDC) ; ! 207: ! 208: EndDialog(hwnd, FALSE) ; ! 209: break ; ! 210: ! 211: case ID_RESETPRINT: ! 212: SetFocus(GetDlgItem(hwnd, ID_STRUCTSIZEP)) ; ! 213: InitPrintStruct(hwnd, &pd) ; ! 214: FillPrintDlg(hwnd, &pd) ; ! 215: SendDlgItemMessage(hwnd, ID_PRESETUPP, BM_SETCHECK, (WPARAM)0, (LPARAM)0) ; ! 216: SendDlgItemMessage(hwnd, ID_PREPRINTP, BM_SETCHECK, (WPARAM)0, (LPARAM)0) ; ! 217: SendDlgItemMessage(hwnd, ID_NULLSTRUCTP, BM_SETCHECK, (WPARAM)0, (LPARAM)0) ; ! 218: break ; ! 219: ! 220: case ID_EDITDEVNAMES: ! 221: DialogBox(hInst, MAKEINTRESOURCE(ID_DEVNAMESDIALOG), ! 222: hwnd, DevnamesProc) ; ! 223: break ; ! 224: ! 225: case ID_EDITDEVMODE: ! 226: DialogBox(hInst, MAKEINTRESOURCE(ID_DEVMODEDIALOG), ! 227: hwnd, DevmodeProc) ; ! 228: break ; ! 229: ! 230: case ID_MULTITHREADPRINT: ! 231: nOpenDialogCount = 2 ; ! 232: EnablePrintControls(hwnd, FALSE) ; ! 233: MultiThreadPrintDlg() ; ! 234: break ; ! 235: ! 236: default: break ; ! 237: } ! 238: } ! 239: ! 240: default: ! 241: ! 242: /* If the help button is pressed in the PrintDlg() dialog box, ! 243: it will send a message Registered with RegisterWindowMessage() ! 244: to the parent window. The message nHelpMessage was registered ! 245: at application startup */ ! 246: ! 247: if (msg == nHelpMessage) ! 248: MessageBox(GetForegroundWindow(), TEXT("Hello from the help button"), ! 249: TEXT("Print Help Button"), MB_OK | MB_APPLMODAL) ; ! 250: break ; ! 251: } ! 252: ! 253: return FALSE ; ! 254: } ! 255: ! 256: ! 257: ! 258: ! 259: ! 260: ! 261: ! 262: ! 263: /************************************************************************ ! 264: ! 265: Function: DevnamesProc(HWND, UINT, UINT, LONG) ! 266: ! 267: Purpose: Callback function for the Devnames dialog box ! 268: ! 269: Returns: TRUE or FALSE depending on situation / message ! 270: ! 271: Comments: ! 272: ! 273: ************************************************************************/ ! 274: ! 275: BOOL APIENTRY DevnamesProc(HWND hwnd, UINT msg, UINT wParam, LONG lParam) ! 276: { ! 277: switch (msg) ! 278: { ! 279: case WM_INITDIALOG: ! 280: FillDevnamesDlg(hwnd, &pd) ; ! 281: break ; ! 282: ! 283: case WM_COMMAND: ! 284: { ! 285: switch (LOWORD(wParam)) ! 286: { ! 287: case IDOK: ! 288: GetDevnamesDlg(hwnd, &pd) ; ! 289: EndDialog(hwnd, TRUE) ; ! 290: break ; ! 291: ! 292: case IDCANCEL: ! 293: EndDialog(hwnd, FALSE) ; ! 294: break ; ! 295: ! 296: default: break ; ! 297: } ! 298: } ! 299: ! 300: default: break ; ! 301: } ! 302: ! 303: return FALSE ; ! 304: } ! 305: ! 306: ! 307: ! 308: ! 309: ! 310: ! 311: /************************************************************************ ! 312: ! 313: Function: DevmodeProc(HWND, UINT, UINT, LONG) ! 314: ! 315: Purpose: Callback function for the Devmode dialog box ! 316: ! 317: Returns: TRUE or FALSE depending on situation / message ! 318: ! 319: Comments: ! 320: ! 321: ************************************************************************/ ! 322: ! 323: BOOL APIENTRY DevmodeProc(HWND hwnd, UINT msg, UINT wParam, LONG lParam) ! 324: { ! 325: switch (msg) ! 326: { ! 327: case WM_INITDIALOG: ! 328: FillDevmodeDlg(hwnd, &pd) ; ! 329: break ; ! 330: ! 331: case WM_COMMAND: ! 332: { ! 333: switch (LOWORD(wParam)) ! 334: { ! 335: case IDOK: ! 336: GetDevmodeDlg(hwnd, &pd) ; ! 337: EndDialog(hwnd, TRUE) ; ! 338: break ; ! 339: ! 340: case IDCANCEL: ! 341: EndDialog(hwnd, FALSE) ; ! 342: break ; ! 343: ! 344: default: break ; ! 345: } ! 346: } ! 347: ! 348: default: break ; ! 349: } ! 350: ! 351: return FALSE ; ! 352: } ! 353: ! 354: ! 355: ! 356: ! 357: ! 358: ! 359: ! 360: ! 361: /************************************************************************ ! 362: ! 363: Function: InitPrintStruct(HWND, LPPRINTDLG) ! 364: ! 365: Purpose: Fills a PRINTDLG structure with some default values. ! 366: ! 367: Returns: Nothing. ! 368: ! 369: Comments: ! 370: ! 371: In order to fill in the hDevMode and hDevNames PRINTDLG structure ! 372: elements, a call to PrintDlg() must be made with the ! 373: (PD_RETURNDEFAULT | PD_RETURNDC) flag bits set. ! 374: ! 375: ************************************************************************/ ! 376: ! 377: void InitPrintStruct(HWND hwnd, LPPRINTDLG ppd) ! 378: { ! 379: DWORD dwTempFlags = 0 ; ! 380: ! 381: ppd->lStructSize = sizeof(PRINTDLG) ; ! 382: ppd->hwndOwner = hwnd ; ! 383: ppd->hDevMode = (HANDLE) 0 ; ! 384: ppd->hDevNames = (HANDLE) 0 ; ! 385: ppd->hDC = (HDC) 0 ; ! 386: ppd->Flags = PD_RETURNDC | PD_COLLATE | PD_SHOWHELP | PD_PAGENUMS ; ! 387: ppd->nFromPage = 1 ; ! 388: ppd->nToPage = 10 ; ! 389: ppd->nMinPage = 0 ; ! 390: ppd->nMaxPage = 9 ; ! 391: ppd->nCopies = 1000 ; ! 392: ppd->hInstance = (HANDLE) hInst ; ! 393: ppd->lCustData = 0L ; ! 394: ! 395: ppd->lpfnPrintHook = PrintHookProc ; ! 396: ppd->lpfnSetupHook = PrintHookProc ; ! 397: ! 398: lstrcpy(szPrintTempName, TEXT("prtemp1")) ; ! 399: ppd->lpPrintTemplateName = szPrintTempName ; ! 400: ! 401: lstrcpy(szSetupTempName, TEXT("prtemp2")) ; ! 402: ppd->lpSetupTemplateName = szSetupTempName ; ! 403: ! 404: ppd->hPrintTemplate = (HANDLE) 0 ; //these are unknown right now ! 405: ppd->hSetupTemplate = (HANDLE) 0 ; ! 406: ! 407: ! 408: /* Let's fill the hDevMode and hDevNames structures. */ ! 409: /* This call should just return handles to structures of this */ ! 410: /* type filled with the info for the default printer */ ! 411: ! 412: dwTempFlags = ppd->Flags ; ! 413: ppd->Flags = PD_RETURNDEFAULT | PD_RETURNDC ; ! 414: PrintDlg(ppd) ; ! 415: ! 416: ppd->Flags = dwTempFlags ; ! 417: } ! 418: ! 419: ! 420: ! 421: ! 422: ! 423: ! 424: ! 425: /************************************************************************ ! 426: ! 427: Function: FillPrintDlg(HWND, LPPRINTDLG) ! 428: ! 429: Purpose: Fills CDTEST's print dialog with the contents of a ! 430: PRINTDLG structure. ! 431: ! 432: Returns: Nothing. ! 433: ! 434: Comments: ! 435: ! 436: ************************************************************************/ ! 437: ! 438: ! 439: void FillPrintDlg(HWND hwnd, LPPRINTDLG ppd) ! 440: { ! 441: wsprintf(szTemp, szLongFilter, ppd->lStructSize) ; ! 442: SetDlgItemText(hwnd, ID_STRUCTSIZEP, szTemp) ; ! 443: ! 444: wsprintf(szTemp, szLongFilter, (DWORD) ppd->hwndOwner) ; ! 445: SetDlgItemText(hwnd, ID_HWNDOWNERP, szTemp) ; ! 446: ! 447: wsprintf(szTemp, szLongFilter, (DWORD) ppd->hDevMode) ; ! 448: SetDlgItemText(hwnd, ID_HDEVMODEP, szTemp) ; ! 449: ! 450: wsprintf(szTemp, szLongFilter, (DWORD) ppd->hDevNames) ; ! 451: SetDlgItemText(hwnd, ID_HDEVNAMESP, szTemp) ; ! 452: ! 453: wsprintf(szTemp, szLongFilter, (DWORD) ppd->hDC) ; ! 454: SetDlgItemText(hwnd, ID_HDCP, szTemp) ; ! 455: ! 456: wsprintf(szTemp, szLongFilter, (DWORD) ppd->Flags) ; ! 457: SetDlgItemText(hwnd, ID_FLAGSP, szTemp) ; ! 458: ! 459: wsprintf(szTemp, szLongFilter, (DWORD) ppd->nFromPage) ; ! 460: SetDlgItemText(hwnd, ID_FROMPAGEP, szTemp) ; ! 461: ! 462: wsprintf(szTemp, szLongFilter, (DWORD) ppd->nToPage) ; ! 463: SetDlgItemText(hwnd, ID_TOPAGEP, szTemp) ; ! 464: ! 465: wsprintf(szTemp, szLongFilter, (DWORD) ppd->nMinPage) ; ! 466: SetDlgItemText(hwnd, ID_MINPAGEP, szTemp) ; ! 467: ! 468: wsprintf(szTemp, szLongFilter, (DWORD) ppd->nMaxPage) ; ! 469: SetDlgItemText(hwnd, ID_MAXPAGEP, szTemp) ; ! 470: ! 471: wsprintf(szTemp, szLongFilter, (DWORD) ppd->nCopies) ; ! 472: SetDlgItemText(hwnd, ID_COPIESP, szTemp) ; ! 473: ! 474: wsprintf(szTemp, szLongFilter, ppd->hInstance) ; ! 475: SetDlgItemText(hwnd, ID_HINSTANCEP, szTemp) ; ! 476: ! 477: wsprintf(szTemp, szLongFilter, ppd->lCustData) ; ! 478: SetDlgItemText(hwnd, ID_CUSTDATAP, szTemp) ; ! 479: ! 480: wsprintf(szTemp, szLongFilter, (DWORD) ppd->lpfnPrintHook) ; ! 481: SetDlgItemText(hwnd, ID_PRINTHOOKP, szTemp) ; ! 482: ! 483: wsprintf(szTemp, szLongFilter, (DWORD) ppd->lpfnSetupHook) ; ! 484: SetDlgItemText(hwnd, ID_SETUPHOOKP, szTemp) ; ! 485: ! 486: SetDlgItemText(hwnd, ID_LPPRINTTEMPP, ppd->lpPrintTemplateName) ; ! 487: ! 488: SetDlgItemText(hwnd, ID_LPSETUPTEMPP, ppd->lpSetupTemplateName) ; ! 489: ! 490: wsprintf(szTemp, szLongFilter, (DWORD) ppd->hPrintTemplate) ; ! 491: SetDlgItemText(hwnd, ID_HPRINTTEMPP, szTemp) ; ! 492: ! 493: wsprintf(szTemp, szLongFilter, (DWORD) ppd->hSetupTemplate) ; ! 494: SetDlgItemText(hwnd, ID_HSETUPTEMPP, szTemp) ; ! 495: } ! 496: ! 497: ! 498: ! 499: ! 500: ! 501: ! 502: ! 503: ! 504: ! 505: /************************************************************************ ! 506: ! 507: Function: GetPrintDlg(HWND, LPPRINTDLG) ! 508: ! 509: Purpose: Fills a PRINTDLG structure with the users choices in CDTEST's ! 510: print dialog box. ! 511: ! 512: Returns: Nothing. ! 513: ! 514: Comments: ! 515: ! 516: ************************************************************************/ ! 517: ! 518: void GetPrintDlg(HWND hwnd, LPPRINTDLG ppd) ! 519: { ! 520: BOOL b ; ! 521: TCHAR szNum[20] ; ! 522: ! 523: #define WMAX 20 ! 524: ! 525: GetDlgItemText(hwnd, ID_STRUCTSIZEP, szNum, WMAX) ; ! 526: ppd->lStructSize = MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 527: ! 528: GetDlgItemText(hwnd, ID_HWNDOWNERP, szNum, WMAX) ; ! 529: ppd->hwndOwner = (HWND) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 530: ! 531: GetDlgItemText(hwnd, ID_HDEVMODEP, szNum, WMAX) ; ! 532: ppd->hDevMode = (HANDLE) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 533: ! 534: GetDlgItemText(hwnd, ID_HDEVNAMESP, szNum, WMAX) ; ! 535: ppd->hDevNames = (HANDLE) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 536: ! 537: GetDlgItemText(hwnd, ID_HDCP, szNum, WMAX) ; ! 538: ppd->hDC = (HDC) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 539: ! 540: GetDlgItemText(hwnd, ID_FLAGSP, szNum, WMAX) ; ! 541: ppd->Flags = MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 542: ! 543: GetDlgItemText(hwnd, ID_FROMPAGEP, szNum, WMAX) ; ! 544: ppd->nFromPage = (WORD) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 545: ! 546: GetDlgItemText(hwnd, ID_TOPAGEP, szNum, WMAX) ; ! 547: ppd->nToPage = (WORD) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 548: ! 549: GetDlgItemText(hwnd, ID_MINPAGEP, szNum, WMAX) ; ! 550: ppd->nMinPage = (WORD) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 551: ! 552: GetDlgItemText(hwnd, ID_MAXPAGEP, szNum, WMAX) ; ! 553: ppd->nMaxPage = (WORD) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 554: ! 555: GetDlgItemText(hwnd, ID_COPIESP, szNum, WMAX) ; ! 556: ppd->nCopies = (WORD) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 557: ! 558: GetDlgItemText(hwnd, ID_HINSTANCEP, szNum, WMAX) ; ! 559: ppd->hInstance = (HANDLE) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 560: ! 561: GetDlgItemText(hwnd, ID_CUSTDATAP, szNum, WMAX) ; ! 562: ppd->lCustData = MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 563: ! 564: GetDlgItemText(hwnd, ID_PRINTHOOKP, szNum, WMAX) ; ! 565: ppd->lpfnPrintHook = (LPPRINTHOOKPROC) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 566: ! 567: GetDlgItemText(hwnd, ID_SETUPHOOKP, szNum, WMAX) ; ! 568: ppd->lpfnSetupHook = (LPSETUPHOOKPROC) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 569: ! 570: GetDlgItemText(hwnd, ID_LPPRINTTEMPP, szPrintTempName, 100) ; ! 571: ! 572: GetDlgItemText(hwnd, ID_LPSETUPTEMPP, szSetupTempName, 100) ; ! 573: ! 574: GetDlgItemText(hwnd, ID_HPRINTTEMPP, szNum, WMAX) ; ! 575: ppd->hPrintTemplate = (HANDLE) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 576: ! 577: GetDlgItemText(hwnd, ID_HSETUPTEMPP, szNum, WMAX) ; ! 578: ppd->hSetupTemplate = (HANDLE) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 579: ! 580: } ! 581: ! 582: ! 583: ! 584: ! 585: ! 586: ! 587: ! 588: ! 589: /************************************************************************ ! 590: ! 591: Function: FillDevnamesDlg(HWND, LPPRINTDLG) ! 592: ! 593: Purpose: Fills CDTEST's devnames dialog box with the values in ! 594: The hDevNames structure member of a PRINTDLG structure. ! 595: ! 596: Returns: Nothing. ! 597: ! 598: Comments: ! 599: ! 600: ************************************************************************/ ! 601: ! 602: ! 603: void FillDevnamesDlg(HWND hwnd, LPPRINTDLG ppd) ! 604: { ! 605: LPDEVNAMES pn = (LPDEVNAMES) 0 ; ! 606: ! 607: if (ppd->hDevNames == (HANDLE) 0) ! 608: return ; ! 609: ! 610: pn = (LPDEVNAMES) GlobalLock(ppd->hDevNames) ; ! 611: if (pn == (LPDEVNAMES) NULL) return ; ! 612: ! 613: ! 614: /* To find the strings in this block of memory, add the correct ! 615: offset to the original pointer returned by GlobalLock() */ ! 616: ! 617: SetDlgItemText(hwnd, ID_WDRIVEROFF, (LPTSTR) pn + pn->wDriverOffset) ; ! 618: ! 619: SetDlgItemText(hwnd, ID_WDEVICEOFF, (LPTSTR) pn + pn->wDeviceOffset) ; ! 620: ! 621: SetDlgItemText(hwnd, ID_WOUTPUTOFF, (LPTSTR) pn + pn->wOutputOffset) ; ! 622: ! 623: ! 624: wsprintf(szTemp, szShortFilter, (int) pn->wDefault) ; ! 625: SetDlgItemText(hwnd, ID_WDEFAULT, szTemp) ; ! 626: ! 627: ! 628: GlobalUnlock(ppd->hDevNames) ; ! 629: } ! 630: ! 631: ! 632: ! 633: ! 634: ! 635: ! 636: ! 637: /************************************************************************ ! 638: ! 639: Function: GetDevnamesDlg(HWND, LPPRINTDLG) ! 640: ! 641: Purpose: Retrieves the user's choices in CDTEST's devnames dialog box, ! 642: Allocates some memory to hold a new DEVNAMES structure, fills ! 643: the users choices into the new DEVNAMES structure, and sets ! 644: the hDevNames member of a PRINTDLG structure to this new ! 645: memory handle. ! 646: ! 647: ! 648: Returns: Nothing. ! 649: ! 650: Comments: ! 651: ! 652: ************************************************************************/ ! 653: ! 654: void GetDevnamesDlg(HWND hwnd, LPPRINTDLG ppd) ! 655: { ! 656: BOOL b ; ! 657: TCHAR szNum[30] ; ! 658: LPDEVNAMES pn ; ! 659: TCHAR sz1[100] ; ! 660: TCHAR sz2[100] ; ! 661: TCHAR sz3[100] ; ! 662: DWORD dwSize ; ! 663: int n1, n2, n3 ; ! 664: ! 665: GetDlgItemText(hwnd, ID_WDRIVEROFF, sz1, 100) ; ! 666: GetDlgItemText(hwnd, ID_WDEVICEOFF, sz2, 100) ; ! 667: GetDlgItemText(hwnd, ID_WOUTPUTOFF, sz3, 100) ; ! 668: ! 669: n1 = lstrlen(sz1) ; ! 670: n2 = lstrlen(sz2) ; ! 671: n3 = lstrlen(sz3) ; ! 672: ! 673: if (hDevNames) ! 674: { ! 675: GlobalFree(hDevNames) ; ! 676: hDevNames = (HANDLE) 0 ; ! 677: } ! 678: ! 679: ! 680: /* allocate size of everything + 5 extra bytes for zeroes */ ! 681: ! 682: dwSize = sizeof(DEVNAMES) + ((n1+n2+n3+5) * sizeof(TCHAR)) ; ! 683: ! 684: ! 685: /* Allocate the memory and lock it down */ ! 686: ! 687: if (!(hDevNames = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, dwSize))) ! 688: { ! 689: MessageBox(hwnd, TEXT("Can't Alloc memory for hDevNames!"), ! 690: TEXT("Fatal Error!"), MB_OK | MB_APPLMODAL) ; ! 691: return ; ! 692: } ! 693: ! 694: if (!(pn = (LPDEVNAMES) GlobalLock(hDevNames))) ! 695: { ! 696: MessageBox(hwnd, TEXT("Can't Lock New hDevNames memory!"), ! 697: TEXT("Fatal Error"), MB_OK | MB_APPLMODAL) ; ! 698: ! 699: GlobalFree(hDevNames) ; ! 700: ! 701: hDevNames = (HANDLE) 0 ; ! 702: ! 703: return ; ! 704: } ! 705: ! 706: ! 707: /* skip over devnames and copy string 1 there. Make sure to ! 708: divide by sizeof(TCHAR) or the compiler will create a pointer ! 709: that points too far if you compile as a UNICODE program */ ! 710: ! 711: pn->wDriverOffset = sizeof(DEVNAMES) / sizeof(TCHAR) ; ! 712: lstrcpy((LPTSTR) pn + pn->wDriverOffset, (LPTSTR) sz1) ; ! 713: ! 714: ! 715: ! 716: /* skip over string 1 and add string 1 with a zero between them */ ! 717: ! 718: pn->wDeviceOffset = pn->wDriverOffset + n1 + 1 ; ! 719: lstrcpy((LPTSTR) pn + pn->wDeviceOffset, (LPTSTR) sz2) ; ! 720: ! 721: ! 722: ! 723: /* skip over string 2 and put string 3 there with a zero between them */ ! 724: ! 725: pn->wOutputOffset = pn->wDeviceOffset + n2 + 1 ; ! 726: lstrcpy((LPTSTR) pn + pn->wOutputOffset, (LPTSTR) sz3) ; ! 727: ! 728: ! 729: GetDlgItemText(hwnd, ID_WDEFAULT, szNum, 30) ; ! 730: pn->wDefault = (WORD) MyAtol(szNum, uMode == IDM_HEXMODE, &b) ; ! 731: ! 732: GlobalUnlock(hDevNames) ; ! 733: ! 734: ppd->hDevNames = hDevNames ; ! 735: ! 736: wsprintf(szTemp, szLongFilter, ppd->hDevNames) ; ! 737: SetDlgItemText(GetParent(hwnd), ID_HDEVNAMESP, szTemp) ; ! 738: ! 739: } ! 740: ! 741: ! 742: ! 743: ! 744: ! 745: ! 746: /************************************************************************ ! 747: ! 748: Function: FillDevmodeDlg(HWND, LPPRINTDLG) ! 749: ! 750: Purpose: Fills CDTEST's devmode dialog with the contents of the DEVMODE ! 751: structure handle of a PRINTDLG structure. ! 752: ! 753: ! 754: Returns: Nothing. ! 755: ! 756: Comments: ! 757: ! 758: ************************************************************************/ ! 759: ! 760: void FillDevmodeDlg(HWND hwnd, LPPRINTDLG ppd) ! 761: { ! 762: LPDEVMODE p ; ! 763: ! 764: if (ppd->hDevMode == (HANDLE) 0) ! 765: return ; ! 766: ! 767: p = (LPDEVMODE) GlobalLock(ppd->hDevMode) ; ! 768: if (p == (LPDEVMODE) NULL) return ; ! 769: ! 770: SetDlgItemText(hwnd, ID_DMDEVNAME, (LPTSTR) p->dmDeviceName) ; ! 771: ! 772: wsprintf(szTemp, szShortFilter, (int) p->dmSpecVersion) ; ! 773: SetDlgItemText(hwnd, ID_DMSPECVER, szTemp) ; ! 774: ! 775: wsprintf(szTemp, szShortFilter, (int) p->dmDriverVersion) ; ! 776: SetDlgItemText(hwnd, ID_DMDRIVERVER, szTemp) ; ! 777: ! 778: wsprintf(szTemp, szShortFilter, (int) p->dmSize) ; ! 779: SetDlgItemText(hwnd, ID_DMSIZEDEV, szTemp) ; ! 780: ! 781: wsprintf(szTemp, szShortFilter, (int) p->dmDriverExtra) ; ! 782: SetDlgItemText(hwnd, ID_DMDRIVEREXTRA, szTemp) ; ! 783: ! 784: wsprintf(szTemp, szShortFilter, (int) p->dmFields) ; ! 785: SetDlgItemText(hwnd, ID_DMFIELDS, szTemp) ; ! 786: ! 787: wsprintf(szTemp, szShortFilter, (int) p->dmOrientation) ; ! 788: SetDlgItemText(hwnd, ID_DMORIENTATION, szTemp) ; ! 789: ! 790: wsprintf(szTemp, szShortFilter, (int) p->dmPaperSize) ; ! 791: SetDlgItemText(hwnd, ID_DMPAPERSIZE, szTemp) ; ! 792: ! 793: wsprintf(szTemp, szLongFilter, p->dmPaperLength) ; ! 794: SetDlgItemText(hwnd, ID_DMPAPERLENGTH, szTemp) ; ! 795: ! 796: wsprintf(szTemp, szLongFilter, p->dmPaperWidth) ; ! 797: SetDlgItemText(hwnd, ID_DMPAPERWIDTH, szTemp) ; ! 798: ! 799: wsprintf(szTemp, szLongFilter, p->dmScale) ; ! 800: SetDlgItemText(hwnd, ID_DMSCALE, szTemp) ; ! 801: ! 802: wsprintf(szTemp, szLongFilter, p->dmCopies) ; ! 803: SetDlgItemText(hwnd, ID_DMCOPIES, szTemp) ; ! 804: ! 805: wsprintf(szTemp, szLongFilter, p->dmDefaultSource) ; ! 806: SetDlgItemText(hwnd, ID_DMDEFAULTSOURCE, szTemp) ; ! 807: ! 808: wsprintf(szTemp, szLongFilter, p->dmPrintQuality) ; ! 809: SetDlgItemText(hwnd, ID_DMPRINTQUALITY, szTemp) ; ! 810: ! 811: wsprintf(szTemp, szLongFilter, p->dmColor) ; ! 812: SetDlgItemText(hwnd, ID_DMCOLOR, szTemp) ; ! 813: ! 814: wsprintf(szTemp, szLongFilter, p->dmDuplex) ; ! 815: SetDlgItemText(hwnd, ID_DMDUPLEX, szTemp) ; ! 816: ! 817: wsprintf(szTemp, szLongFilter, p->dmCollate) ; ! 818: SetDlgItemText(hwnd, ID_DMCOLLATE, szTemp) ; ! 819: ! 820: SetDlgItemText(hwnd, ID_DMFORMNAME, (LPTSTR) p->dmFormName) ; ! 821: ! 822: wsprintf(szTemp, szLongFilter, p->dmBitsPerPel) ; ! 823: SetDlgItemText(hwnd, ID_DMBITSPERPEL, szTemp) ; ! 824: ! 825: wsprintf(szTemp, szLongFilter, p->dmPelsWidth) ; ! 826: SetDlgItemText(hwnd, ID_DMPELSWIDTH, szTemp) ; ! 827: ! 828: wsprintf(szTemp, szLongFilter, p->dmPelsHeight) ; ! 829: SetDlgItemText(hwnd, ID_DMPELSHEIGHT, szTemp) ; ! 830: ! 831: wsprintf(szTemp, szLongFilter, p->dmDisplayFrequency) ; ! 832: SetDlgItemText(hwnd, ID_DMDISPLAYFREQ, szTemp) ; ! 833: ! 834: GlobalUnlock(ppd->hDevMode) ; ! 835: } ! 836: ! 837: ! 838: ! 839: ! 840: ! 841: ! 842: ! 843: ! 844: ! 845: /************************************************************************ ! 846: ! 847: Function: GetDevmodeDlg(HWND, LPPRINTDLG) ! 848: ! 849: Purpose: Retrieves the user's edits in CDTEST's DEVMODE dialog box, ! 850: allocates memory for a new DEVMODE structure, fills that ! 851: memory with the user's edits, and puts a handle to that ! 852: memory in the hDevMode member of a PRINTDLG structure. ! 853: ! 854: Returns: Nothing. ! 855: ! 856: Comments: ! 857: ! 858: ************************************************************************/ ! 859: ! 860: void GetDevmodeDlg(HWND hwnd, LPPRINTDLG ppd) ! 861: { ! 862: LPDEVMODE p ; ! 863: BOOL b ; ! 864: TCHAR szNum[30] ; ! 865: ! 866: #define WMAXDEV 30 ! 867: ! 868: if (hDevMode) ! 869: { ! 870: GlobalFree(hDevMode) ; ! 871: hDevMode = (HANDLE) 0 ; ! 872: } ! 873: ! 874: if (!(hDevMode = GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE, sizeof(DEVMODE)))) ! 875: { ! 876: MessageBox(hwnd, TEXT("Can't allocate memory for hDevMode"), ! 877: TEXT("Fatal Error"), MB_OK | MB_APPLMODAL) ; ! 878: return ; ! 879: } ! 880: ! 881: if (!(p = (LPDEVMODE) GlobalLock(hDevMode))) ! 882: { ! 883: MessageBox(hwnd, TEXT("Can't lock memory for hDevMode"), ! 884: TEXT("Fatal Error"), MB_OK | MB_APPLMODAL) ; ! 885: ! 886: GlobalFree(hDevMode) ; ! 887: hDevMode = (HANDLE) 0 ; ! 888: ! 889: return ; ! 890: } ! 891: ! 892: GetDlgItemText(hwnd, ID_DMDEVNAME, p->dmDeviceName, 32) ; ! 893: ! 894: GetDlgItemText(hwnd, ID_DMSPECVER, szNum, WMAXDEV) ; ! 895: p->dmSpecVersion = (WORD) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 896: ! 897: GetDlgItemText(hwnd, ID_DMDRIVERVER, szNum, WMAXDEV) ; ! 898: p->dmDriverVersion = (WORD) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 899: ! 900: GetDlgItemText(hwnd, ID_DMSIZEDEV, szNum, WMAXDEV) ; ! 901: p->dmSize = (WORD) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 902: ! 903: GetDlgItemText(hwnd, ID_DMDRIVEREXTRA, szNum, WMAXDEV) ; ! 904: p->dmDriverExtra = (WORD) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 905: ! 906: GetDlgItemText(hwnd, ID_DMFIELDS, szNum, WMAXDEV) ; ! 907: p->dmFields = MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 908: ! 909: GetDlgItemText(hwnd, ID_DMORIENTATION, szNum, WMAXDEV) ; ! 910: p->dmOrientation = (short) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 911: ! 912: GetDlgItemText(hwnd, ID_DMPAPERSIZE, szNum, WMAXDEV) ; ! 913: p->dmPaperSize = (short) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 914: ! 915: GetDlgItemText(hwnd, ID_DMPAPERLENGTH, szNum, WMAXDEV) ; ! 916: p->dmPaperLength = (short) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 917: ! 918: GetDlgItemText(hwnd, ID_DMPAPERWIDTH, szNum, WMAXDEV) ; ! 919: p->dmPaperWidth = (short) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 920: ! 921: GetDlgItemText(hwnd, ID_DMSCALE, szNum, WMAXDEV) ; ! 922: p->dmScale = (short) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 923: ! 924: GetDlgItemText(hwnd, ID_DMCOPIES, szNum, WMAXDEV) ; ! 925: p->dmCopies = (short) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 926: ! 927: GetDlgItemText(hwnd, ID_DMDEFAULTSOURCE, szNum, WMAXDEV) ; ! 928: p->dmDefaultSource = (short) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 929: ! 930: GetDlgItemText(hwnd, ID_DMPRINTQUALITY, szNum, WMAXDEV) ; ! 931: p->dmPrintQuality = (short) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 932: ! 933: GetDlgItemText(hwnd, ID_DMCOLOR, szNum, WMAXDEV) ; ! 934: p->dmColor = (short) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 935: ! 936: GetDlgItemText(hwnd, ID_DMDUPLEX, szNum, WMAXDEV) ; ! 937: p->dmDuplex = (short) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 938: ! 939: GetDlgItemText(hwnd, ID_DMCOLLATE, szNum, WMAXDEV) ; ! 940: p->dmCollate = (short) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 941: ! 942: GetDlgItemText(hwnd, ID_DMFORMNAME, p->dmFormName, 32) ; ! 943: ! 944: GetDlgItemText(hwnd, ID_DMBITSPERPEL, szNum, WMAXDEV) ; ! 945: p->dmBitsPerPel = (USHORT) MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 946: ! 947: GetDlgItemText(hwnd, ID_DMPELSWIDTH, szNum, WMAXDEV) ; ! 948: p->dmPelsWidth = MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 949: ! 950: GetDlgItemText(hwnd, ID_DMPELSHEIGHT, szNum, WMAXDEV) ; ! 951: p->dmPelsHeight = MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 952: ! 953: GetDlgItemText(hwnd, ID_DMDISPLAYFREQ, szNum, WMAXDEV) ; ! 954: p->dmDisplayFrequency = MyAtol(szNum, uMode==IDM_HEXMODE, &b) ; ! 955: ! 956: GlobalUnlock(hDevMode) ; ! 957: ppd->hDevMode = hDevMode ; ! 958: ! 959: wsprintf(szTemp, szLongFilter, (DWORD) ppd->hDevMode) ; ! 960: SetDlgItemText(GetParent(hwnd), ID_HDEVMODEP, szTemp) ; ! 961: } ! 962: ! 963: ! 964: ! 965: ! 966: ! 967: ! 968: /************************************************************************ ! 969: ! 970: Function: GetPrintDlgHandle(void) ! 971: ! 972: Purpose: Finds the custom Print dialog template in the EXE, loads it ! 973: into a handle, and returns the handle. ! 974: ! 975: Returns: Nothing. ! 976: ! 977: Comments: ! 978: ! 979: ************************************************************************/ ! 980: ! 981: HANDLE GetPrintDlgHandle(void) ! 982: { ! 983: hResPrint = FindResource(hInst, TEXT("prtemp1"), RT_DIALOG) ; ! 984: ! 985: hDialogPrint = LoadResource(hInst, hResPrint) ; ! 986: ! 987: ! 988: return hDialogPrint ; ! 989: } ! 990: ! 991: ! 992: ! 993: ! 994: ! 995: ! 996: ! 997: ! 998: /************************************************************************ ! 999: ! 1000: Function: GetSetupDlgHandle(void) ! 1001: ! 1002: Purpose: Finds the custom Setup dialog template in the EXE, loads it ! 1003: into a handle, and returns the handle. ! 1004: ! 1005: Returns: Nothing. ! 1006: ! 1007: Comments: ! 1008: ! 1009: ************************************************************************/ ! 1010: ! 1011: HANDLE GetSetupDlgHandle(void) ! 1012: { ! 1013: hResPrint = FindResource(hInst, TEXT("prtemp2"), RT_DIALOG) ; ! 1014: ! 1015: hDialogPrint = LoadResource(hInst, hResPrint) ; ! 1016: ! 1017: return hDialogPrint ; ! 1018: } ! 1019: ! 1020: ! 1021: ! 1022: ! 1023: ! 1024: ! 1025: ! 1026: ! 1027: /************************************************************************ ! 1028: ! 1029: Function: PrintHookProc(HWND, UINT, UINT, LONG) ! 1030: ! 1031: Purpose: A callback function that will receive messages intended for ! 1032: the PrintDlg() dialog boxes before the normal common dialog ! 1033: routine receives them. ! 1034: ! 1035: ! 1036: Returns: FALSE to allow the common dialogs to process the message ! 1037: with its normal logic. TRUE to discard the message. ! 1038: ! 1039: Comments: ! 1040: ! 1041: To enable this function for the Print dialog in CDTEST, enter the ! 1042: value for PD_ENABLEPRINTHOOK in the "Flags" edit box. ! 1043: ! 1044: To enable this function for the Setup dialog in CDTEST, enter the ! 1045: value for (PD_ENABLESETUPHOOK | PD_PRINTSETUP) in the "Flags" edit box. ! 1046: ! 1047: ************************************************************************/ ! 1048: ! 1049: UINT APIENTRY PrintHookProc(HWND hwnd, UINT msg, UINT wParam, LONG lParam) ! 1050: { ! 1051: LPPRINTDLG pPr ; ! 1052: TCHAR szMsg[50] ; ! 1053: ! 1054: switch(msg) ! 1055: { ! 1056: case WM_INITDIALOG: ! 1057: ! 1058: pPr = (LPPRINTDLG) lParam ; ! 1059: ! 1060: if (pPr->lCustData != 0) ! 1061: { ! 1062: wsprintf(szMsg, TEXT("PRINTDLG->lCustData is: %ld"), pPr->lCustData) ; ! 1063: ! 1064: MessageBox(hwnd, szMsg, TEXT("lCustData Sent!"), MB_OK | MB_APPLMODAL) ; ! 1065: } ! 1066: ! 1067: SetWindowText(hwnd, TEXT("Print Hook Proc Dialog")) ; ! 1068: ! 1069: break ; ! 1070: ! 1071: /* use the WM_CTLCOLOR* messages to change the color of the Open ! 1072: dialog */ ! 1073: ! 1074: case WM_CTLCOLORDLG: ! 1075: ! 1076: if (!hBrushDlg) ! 1077: hBrushDlg = GetStockObject(LTGRAY_BRUSH) ; ! 1078: ! 1079: return (UINT) hBrushDlg ; ! 1080: ! 1081: break ; ! 1082: ! 1083: ! 1084: case WM_CTLCOLORBTN: ! 1085: ! 1086: SetBkMode((HDC) wParam, TRANSPARENT) ; //sets background color ! 1087: //for push and check box ! 1088: //buttons... ! 1089: ! 1090: if (!hBrushButton) ! 1091: hBrushButton = GetStockObject(LTGRAY_BRUSH) ; ! 1092: ! 1093: return (UINT) hBrushButton ; ! 1094: ! 1095: break ; ! 1096: ! 1097: ! 1098: case WM_CTLCOLORSTATIC: ! 1099: ! 1100: SetTextColor((HDC) wParam, RGB(0x00, 0xff, 0x00)) ; //green ! 1101: SetBkMode((HDC) wParam, TRANSPARENT) ; //transparent text ! 1102: ! 1103: if (!hBrushDlg) ! 1104: hBrushDlg = GetStockObject(LTGRAY_BRUSH) ; ! 1105: ! 1106: return (UINT) hBrushDlg ; ! 1107: ! 1108: break ; ! 1109: ! 1110: ! 1111: default: ! 1112: break ; ! 1113: } ! 1114: ! 1115: return FALSE ; //send msg to the common dialog code ! 1116: } ! 1117: ! 1118: ! 1119: ! 1120: ! 1121: ! 1122: ! 1123: ! 1124: ! 1125: /************************************************************************ ! 1126: ! 1127: Function: PrintMultiProc1(LPDWORD) ! 1128: ! 1129: Purpose: Is the starting address for the first new thread when ! 1130: multithreading. ! 1131: ! 1132: Returns: Any DWORD value. ! 1133: ! 1134: Comments: ! 1135: The new thread will start executing here and will end when ! 1136: the PrintDlg() function returns and it has posted a message ! 1137: to the CDTEST's print dialog window saying that one of the ! 1138: two multithreading dialogs been terminated. ! 1139: ! 1140: ************************************************************************/ ! 1141: ! 1142: DWORD PrintMultiProc1(LPDWORD pdw) ! 1143: { ! 1144: GetPrintDlg(hwndMainPrint, &pdThread1) ; ! 1145: ! 1146: DoPrintDlgStuff(hwndMainPrint, &pdThread1) ; ! 1147: ! 1148: PostMessage(hwndMainPrint, UMSG_DECREMENTDLGCOUNT, 0, 0L ) ; ! 1149: ! 1150: return 0L ; ! 1151: } ! 1152: ! 1153: ! 1154: ! 1155: ! 1156: ! 1157: ! 1158: ! 1159: ! 1160: ! 1161: /************************************************************************ ! 1162: ! 1163: Function: PrintMultiProc2(LPDWORD) ! 1164: ! 1165: Purpose: Is the starting address for the second new thread when ! 1166: multithreading. ! 1167: ! 1168: Returns: Any DWORD value. ! 1169: ! 1170: Comments: ! 1171: The new thread will start executing here and will end when ! 1172: the PrintDlg() function returns and it has posted a message ! 1173: to the CDTEST's print dialog window saying that one of the ! 1174: two multithreading dialogs been terminated. ! 1175: ! 1176: ************************************************************************/ ! 1177: ! 1178: DWORD PrintMultiProc2(LPDWORD pdw) ! 1179: { ! 1180: GetPrintDlg(hwndMainPrint, &pdThread2) ; ! 1181: ! 1182: DoPrintDlgStuff(hwndMainPrint, &pdThread2) ; ! 1183: ! 1184: PostMessage(hwndMainPrint, UMSG_DECREMENTDLGCOUNT, 0, 0L ) ; ! 1185: ! 1186: return 0L ; ! 1187: } ! 1188: ! 1189: ! 1190: ! 1191: ! 1192: ! 1193: ! 1194: ! 1195: ! 1196: /************************************************************************ ! 1197: ! 1198: Function: MultiThreadPrintDlg(void) ! 1199: ! 1200: Purpose: Is the starting address for the first new thread when ! 1201: multithreading. ! 1202: ! 1203: Returns: Any DWORD value. ! 1204: ! 1205: Comments: ! 1206: The new thread will start executing here and will end when ! 1207: the PrintDlg() function returns and it has posted a message ! 1208: to the CDTEST's print dialog window saying that one of the ! 1209: two multithreading dialogs been terminated. ! 1210: ! 1211: ************************************************************************/ ! 1212: ! 1213: void MultiThreadPrintDlg(void) ! 1214: { ! 1215: ! 1216: dwPrintThreadParm1 = dwPrintThreadParm2 = 0L ; ! 1217: ! 1218: if (!(hPrintThread1 = CreateThread((LPSECURITY_ATTRIBUTES) NULL, 0, ! 1219: (LPTHREAD_START_ROUTINE) PrintMultiProc1, ! 1220: &dwPrintThreadParm1, CREATE_SUSPENDED, &dwPrintThreadID1))) ! 1221: ! 1222: { ! 1223: MessageBox(GetForegroundWindow(), TEXT("Error creating thread 1"), NULL, ! 1224: MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL) ; ! 1225: ! 1226: nOpenDialogCount = 0 ; ! 1227: ! 1228: EnablePrintControls(hwndMainPrint, TRUE) ; ! 1229: ! 1230: return ; ! 1231: } ! 1232: ! 1233: ! 1234: if (!(hPrintThread2 = CreateThread((LPSECURITY_ATTRIBUTES) NULL, 0, ! 1235: (LPTHREAD_START_ROUTINE) PrintMultiProc2, ! 1236: &dwPrintThreadParm2, CREATE_SUSPENDED, &dwPrintThreadID2))) ! 1237: { ! 1238: MessageBox(GetForegroundWindow(), TEXT("Error creating thread 2"), NULL, ! 1239: MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL) ; ! 1240: ! 1241: nOpenDialogCount = 0 ; ! 1242: ! 1243: EnablePrintControls(hwndMainPrint, TRUE) ; ! 1244: ! 1245: return ; ! 1246: } ! 1247: ! 1248: ResumeThread(hPrintThread1) ; ! 1249: ! 1250: ResumeThread(hPrintThread2) ; ! 1251: ! 1252: return ; ! 1253: } ! 1254: ! 1255: ! 1256: ! 1257: ! 1258: ! 1259: ! 1260: ! 1261: /************************************************************************ ! 1262: ! 1263: Function: EnablePrintControls(HWND, BOOL) ! 1264: ! 1265: Purpose: Enable or disable CDTEST's print dialog's controls. ! 1266: ! 1267: Returns: Nothing. ! 1268: ! 1269: Comments: This is necessary when CDTEST is multithreading. ! 1270: ! 1271: ************************************************************************/ ! 1272: ! 1273: void EnablePrintControls(HWND hwnd, BOOL bEnable) ! 1274: { ! 1275: EnableWindow(GetDlgItem(hwnd, IDOK), bEnable) ; ! 1276: EnableWindow(GetDlgItem(hwnd, IDCANCEL), bEnable) ; ! 1277: EnableWindow(GetDlgItem(hwnd, ID_RESETPRINT), bEnable) ; ! 1278: EnableWindow(GetDlgItem(hwnd, ID_MULTITHREADPRINT), bEnable) ; ! 1279: EnableWindow(GetDlgItem(hwnd, ID_EDITDEVMODE), bEnable) ; ! 1280: EnableWindow(GetDlgItem(hwnd, ID_EDITDEVNAMES), bEnable) ; ! 1281: } ! 1282: ! 1283: ! 1284: ! 1285: ! 1286: ! 1287: ! 1288: /************************************************************************ ! 1289: ! 1290: Function: DoPrintDlgStuff(HWND, LPPRINTDLG) ! 1291: ! 1292: Purpose: Calls PrintDlg() with the correct parameters. ! 1293: ! 1294: Returns: Nothing. ! 1295: ! 1296: Comments: ! 1297: ! 1298: ************************************************************************/ ! 1299: ! 1300: ! 1301: void DoPrintDlgStuff(HWND hwnd, LPPRINTDLG ppd) ! 1302: { ! 1303: BOOL bRet = FALSE ; ! 1304: ! 1305: ! 1306: /* Figure out how the user want's to call PrintDlg() */ ! 1307: ! 1308: if (IsDlgButtonChecked(hwnd, ID_PREPRINTP) == 1) ! 1309: ppd->hPrintTemplate = GetPrintDlgHandle() ; ! 1310: ! 1311: if (IsDlgButtonChecked(hwnd, ID_PRESETUPP) == 1) ! 1312: ppd->hSetupTemplate = GetSetupDlgHandle() ; ! 1313: ! 1314: wsprintf(szTemp, szLongFilter, (DWORD) ppd->hPrintTemplate) ; ! 1315: SetDlgItemText(hwnd, ID_HPRINTTEMPP, szTemp) ; ! 1316: ! 1317: wsprintf(szTemp, szLongFilter, (DWORD) ppd->hSetupTemplate) ; ! 1318: SetDlgItemText(hwnd, ID_HSETUPTEMPP, szTemp) ; ! 1319: ! 1320: ! 1321: ! 1322: /* Call the function */ ! 1323: ! 1324: if (IsDlgButtonChecked(hwnd, ID_NULLSTRUCTP) == 1) ! 1325: bRet = PrintDlg((LPPRINTDLG) NULL) ; ! 1326: else ! 1327: bRet = PrintDlg(ppd) ; ! 1328: ! 1329: ! 1330: ! 1331: /* Clean up and show results */ ! 1332: ! 1333: wsprintf(szTemp, szLongFilter, CommDlgExtendedError()) ; ! 1334: SetDlgItemText(hwnd, ID_ERRORP, szTemp) ; ! 1335: ! 1336: SetDlgItemInt(hwnd, ID_RETURNP, bRet, TRUE) ; ! 1337: ! 1338: if (hDialogPrint) ! 1339: { ! 1340: FreeResource(hDialogPrint) ; //obsolete call, but ! 1341: hDialogPrint = (HANDLE) 0 ; //it's possible that this ! 1342: hResPrint = (HANDLE) 0 ; //might be recompiled for win 3.x ! 1343: } ! 1344: ! 1345: pd.hDevMode = ppd->hDevMode ; //need to fix this so that FillDevnamesDlg() ! 1346: pd.hDevNames = ppd->hDevNames ; //and FillDevmodeDlg() work... ! 1347: ! 1348: FillPrintDlg(hwnd, ppd) ; ! 1349: ! 1350: if (ppd->hDC) //release the HDC after its value is ! 1351: //returned to the test app ! 1352: { ! 1353: ReleaseDC(ppd->hwndOwner, ppd->hDC) ; ! 1354: ppd->hDC = (HDC) 0 ; ! 1355: } ! 1356: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.