home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dbcs.zip / PRNWND.C < prev    next >
C/C++ Source or Header  |  1996-01-19  |  10KB  |  291 lines

  1. #pragma    title("DBCS Driver  --  Version 1  --  (PrnWnd.C)")
  2. #pragma    subtitle("   Application Window - Interface Definitions")
  3.  
  4. #pragma    info(noext)
  5.  
  6. #define    INCL_DOS           /* Include OS/2 DOS Kernal        */
  7. #define    INCL_GPI           /* Include OS/2 PM GPI Interface    */
  8. #define    INCL_WIN           /* Include OS/2 PM Windows Interface    */
  9.  
  10. #include <os2.h>
  11. #include <string.h>
  12.  
  13. #include "appdefs.h"
  14. #include "prnsetup.h"
  15.  
  16. /* This    module contains    application window procedure.            */
  17.  
  18. /* Filename:   PrnWnd.C                            */
  19.  
  20. /*  Version:   3                            */
  21. /*  Created:   1996-01-19                        */
  22. /*  Revised:   1996-01-19                        */
  23.  
  24. /* Routines:   MRESULT EXPENTRY    PrintDriverWndProc(HWND    hWnd,        */
  25. /*                           ULONG msg,        */
  26. /*                           MPARAM mp1,        */
  27. /*                           MPARAM mp2);        */
  28.  
  29. /************************************************************************/
  30. /************************************************************************/
  31. /************************************************************************/
  32. /* DISCLAIMER OF WARRANTIES:                        */
  33. /* -------------------------                        */
  34. /* The following [enclosed] code is sample code    created    by IBM        */
  35. /* Corporation and Prominare Inc.  This    sample code is not part    of any    */
  36. /* standard IBM    product    and is provided    to you solely for the purpose    */
  37. /* of assisting    you in the development of your applications.  The code    */
  38. /* is provided "AS IS",    without    warranty of any    kind.  Neither IBM nor    */
  39. /* Prominare shall be liable for any damages arising out of your    */
  40. /* use of the sample code, even    if they    have been advised of the    */
  41. /* possibility of such damages.                        */
  42. /************************************************************************/
  43. /************************************************************************/
  44. /************************************************************************/
  45. /*               D I S C L A I M E R                */
  46. /* This    code is    provided on an as is basis with    no implied support.    */
  47. /* It should be    considered freeware that cannot    be rebundled as        */
  48. /* part    of a larger "*ware" offering without our consent.        */
  49. /************************************************************************/
  50. /************************************************************************/
  51. /************************************************************************/
  52.  
  53. /* Copyright ╕ International Business Machines Corp., 1996.        */
  54. /* Copyright ╕ 1996  Prominare Inc.  All Rights    Reserved.        */
  55.  
  56. /* --------------------------------------------------------------------    */
  57.  
  58. /************************************************************************/
  59. /*                                    */
  60. /*     External    Data Definitions                    */
  61. /*                                    */
  62. /************************************************************************/
  63.  
  64. extern PSZ pszToolBarClassName;
  65.  
  66. /************************************************************************/
  67. /*                                    */
  68. /*     Module Data Definitions                        */
  69. /*                                    */
  70. /************************************************************************/
  71.  
  72. LONG cyToolBar;               /* Tool Bar Height            */
  73.  
  74. #pragma    subtitle("   Client Window - Client Window Procedure")
  75. #pragma    page( )
  76.  
  77. /* --- PrintDriverWndProc ------------------------------ [ Public ] ---    */
  78. /*                                    */
  79. /*     This function is    used to    process    the messages sent to the    */
  80. /*     applications client window.                    */
  81. /*                                    */
  82. /*     Upon Entry:                            */
  83. /*                                    */
  84. /*     HWND   hWnd; = Window Handle                    */
  85. /*     ULONG  msg;  = PM Message                    */
  86. /*     MPARAM mp1;  = Message Parameter    1                */
  87. /*     MPARAM mp2;  = Message Parameter    2                */
  88. /*                                    */
  89. /*     Upon Exit:                            */
  90. /*                                    */
  91. /*     PrintDriverWndProc = Message Handling Result            */
  92. /*                                    */
  93. /* --------------------------------------------------------------------    */
  94.  
  95. MRESULT    EXPENTRY PrintDriverWndProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  96.  
  97. {
  98. HDC      hdcPrinter;           /* Printer Device Context Handle    */
  99. HPS      hpsPrinter;           /* Presentation Space Handle        */
  100. HPS      hPS;               /* Presentation Space Handle        */
  101. POINTL      ptl;               /* Display Point            */
  102. PPRNDATA  pprni;           /* Print Data Pointer        */
  103. RECTL      rcl;               /* Window Rectangle            */
  104. SIZEL      sizl;               /* Size Structure            */
  105. SIZEL      sizlPage;           /* Page Size    Holder            */
  106. TID      tid;               /* Thread ID                */
  107. ULONG      flCreateFlags;       /* Tool Bar Create Flag        */
  108.  
  109. switch ( msg )
  110.    {
  111.             /* Window being    created, perform window        */
  112.             /* initialization                */
  113.    case    WM_CREATE :
  114.  
  115.        hptrWait     = WinQuerySysPointer(HWND_DESKTOP, SPTR_WAIT,    FALSE);
  116.        hptrArrow = WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW,    FALSE);
  117.  
  118.                /* Get a    temporary presentation space so    that    */
  119.                /* the system's font metrics can be found and    */
  120.                /* the bitmap image used    within the created    */
  121.                /* windows menus    can be used            */
  122.  
  123.        sizl.cx = sizl.cy = 0L;
  124.        hpsPrint    = GpiCreatePS(hAB, WinOpenWindowDC(hWnd), &sizl,
  125.                   PU_TWIPS | GPIF_DEFAULT |    GPIT_MICRO | GPIA_ASSOC);
  126.  
  127.             /************************************************/
  128.             /* PDSGetTemplate is used to allow controls in    */
  129.             /* windows.  Do    not remove this    function if you    */
  130.             /* intend to include controls within the window.*/
  131.             /************************************************/
  132.  
  133.        PDSGetTemplate(hWnd, WIN_PRINTDRIVER);
  134.        ptl.x = 0L;
  135.        ptl.y = 16L;
  136.        WinMapDlgPoints(HWND_DESKTOP, &ptl, 1UL,    TRUE);
  137.        cyToolBar = ptl.y;
  138.                /* Create the toolbar window            */
  139.  
  140.        flCreateFlags = FCF_BORDER | FCF_NOBYTEALIGN;
  141.        if ( !(hwndToolBarFrame = WinCreateStdWindow(hWnd, WS_VISIBLE,
  142.                             &flCreateFlags,
  143.                             pszToolBarClassName, "",
  144.                             0L,    (HMODULE)NULL, ID_TOOLBAR, &hwndToolBar)) )
  145.        return(MRFROMLONG(TRUE));
  146.        break;
  147.  
  148.    case    WM_SIZE    :
  149.                /* Place    the new    legend window in the lower    */
  150.                /* right    hand corner of the display before    */
  151.                /* displaying it                    */
  152.  
  153.        WinQueryWindowRect(hWnd,    &rcl);
  154.  
  155.        WinSetWindowPos(hwndToolBarFrame, HWND_BOTTOM,
  156.                rcl.xLeft - 1L,
  157.                rcl.yTop    - cyToolBar,
  158.                rcl.xRight + 2L,
  159.                cyToolBar,
  160.                SWP_MOVE    | SWP_SIZE | SWP_SHOW);
  161.        break;
  162.             /* Process key press from keyboard        */
  163.    case    WM_CHAR    :
  164.             /************************************************/
  165.             /* PDSKeyProc is used to allow controls    in    */
  166.             /* windows.  Do    not remove this    function if you    */
  167.             /* intend to include controls within the window.*/
  168.             /************************************************/
  169.  
  170.     return(PDSKeyProc(hWnd,    msg, mp1, mp2));
  171.  
  172.             /* Process control selections            */
  173.             /* Process menu    and button selections        */
  174.    case    WM_COMMAND :
  175.        switch (    SHORT1FROMMP(mp1) )
  176.        {
  177.        case    IDM_QUERYDISPLAYFONTS :
  178.            WinDlgBox(HWND_DESKTOP, hwndPrnSetupFrame, (PFNWP)FontMetricsDlgProc,
  179.              (HMODULE)NULL,    DLG_FONTMETRICS, NULL);
  180.            break;
  181.        case    IDM_PRINTPREVIEW :
  182.            if ( !WinDlgBox(HWND_DESKTOP, hwndPrnSetupFrame,    (PFNWP)PrintPreviewDlgProc,
  183.                    (HMODULE)NULL, DLG_PRINTPREVIEW,    NULL) )
  184.            break;
  185.  
  186.        case    IDM_PRINTDISPLAY :
  187.            if ( fQuerySelectedFont(WinWindowFromID(hwndToolBar, CBX_FONT),
  188.                        WinWindowFromID(hwndToolBar, CBX_FONTSIZE),
  189.                        &fsel) )
  190.            {
  191.                /* Allocate memory for the printer information    */
  192.                /* and save the printer information from    the    */
  193.                /* dialogue in the memory            */
  194.  
  195.            DosAllocMem((PPVOID)(PVOID)&pprni, PRNDATASIZE + CCHMAXPATH,
  196.                    PAG_READ    | PAG_WRITE | PAG_COMMIT);
  197.  
  198.            pprni->prn  = prn;
  199.            pprni->fsel = fsel;
  200.            pprni->pags = pags;
  201.            memcpy(pprni->szTitle, "Print Font Example - Display Example", 37);
  202.  
  203.                /* Create a separate thread from    which the    */
  204.                /* printing is performed                */
  205.  
  206.            DosCreateThread(&tid, (PFNTHREAD)PrnDisplay,    (ULONG)pprni,
  207.                    STACK_COMMITTED, 16384UL);
  208.            }
  209.            break;
  210.  
  211.       case IDM_PRINT :
  212.           WinDlgBox(HWND_DESKTOP, hwndPrnSetupFrame, (PFNWP)FilePrintDlgProc,
  213.             (HMODULE)NULL, DLG_FILEPRN, NULL);
  214.           break;
  215.  
  216.        case    IDM_PRINTERSETUP :
  217.            if ( WinDlgBox(HWND_DESKTOP, hwndPrnSetupFrame, (PFNWP)PrnSetupDlgProc,
  218.                   (HMODULE)NULL, DLG_PRNSETUP, (PVOID)&prn)    )
  219.            switch ( lSetFonts(WinWindowFromID(hwndToolBar, CBX_FONT)) )
  220.                {
  221.                /* Error    return:    bad HDC    for printer        */
  222.  
  223.                case 1L :
  224.                WinMessageBox(HWND_DESKTOP, hWnd, "Printer Device Context could not be opened.",
  225.                      "Print Font Example", 0UL, MB_OK | MB_ICONHAND    | MB_MOVEABLE);
  226.                return(MRFROMLONG(TRUE));
  227.  
  228.                /* Error    return:    bad HPS    for printer        */
  229.  
  230.                case 2L :
  231.                WinMessageBox(HWND_DESKTOP, hWnd, "Printer Presentation Space could not be created.",
  232.                      "Print Font Example", 0UL, MB_OK | MB_ICONHAND    | MB_MOVEABLE);
  233.                return(MRFROMLONG(TRUE));
  234.  
  235.                /* Error    return:    no error, fonts    set in combo    */
  236.  
  237.                default :
  238.                break;
  239.                }
  240.            break;
  241.  
  242.        case    IDM_PAGESETUP :
  243.            WinDlgBox(HWND_DESKTOP, hwndPrnSetupFrame, (PFNWP)PageSetupDlgProc,
  244.              (HMODULE)NULL,    DLG_PAGESETUP, NULL);
  245.            break;
  246.        }
  247.        break;
  248.             /* Erase window    background            */
  249.  
  250.    case    WM_ERASEBACKGROUND :
  251.        WinQueryWindowRect(hWnd,    &rcl);
  252.        WinFillRect((HPS)LONGFROMMP(mp1), &rcl, SYSCLR_WINDOW);
  253.        break;
  254.             /* Paint client    window                */
  255.    case    WM_PAINT :
  256.        GpiSetColor(hPS = WinBeginPaint(hWnd, hpsPrint, &rcl), CLR_BLACK);
  257.        WinFillRect(hPS,    &rcl, SYSCLR_WINDOW);
  258.  
  259.        if ( ((hdcPrinter = PrnOpenInfoDC(&prn, "PM_Q_STD")) != (HDC)NULL) )
  260.        {
  261.                /* Create a presentation    space into which the    */
  262.                /* printing will    occur using TWIPS as the unit    */
  263.                /* of measure                    */
  264.  
  265.        sizlPage.cx = sizlPage.cy = 0L;
  266.  
  267.        DrawCommon(hPS, hpsPrinter =    GpiCreatePS(hAB, hdcPrinter, &sizlPage,    PU_TWIPS |
  268.                             GPIF_DEFAULT | GPIT_NORMAL | GPIA_ASSOC),
  269.               &fcache, 90L, 90L, 0L, 0L, NULL, NULL, FALSE);
  270.  
  271.        GpiAssociate(hpsPrinter, (HDC)NULL);
  272.        GpiDestroyPS(hpsPrinter);
  273.        DevCloseDC(hdcPrinter);
  274.  
  275.        DrawText(hPS);
  276.        }
  277.  
  278.        WinEndPaint(hPS);
  279.        break;
  280.             /* Window being    destroyed, perform clean-up    */
  281.             /* operations                    */
  282.    case    WM_DESTROY :
  283.        break;
  284.  
  285.             /* Default message processing            */
  286.    default :
  287.        return(WinDefWindowProc(hWnd, msg, mp1, mp2));
  288.    }
  289. return(0L);
  290. }
  291.