home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / os2tk20 / c / samples / print / prtcreat.c__ / PRTCREAT.C
Encoding:
C/C++ Source or Header  |  1992-07-15  |  8.6 KB  |  237 lines

  1. /****************************************************************************
  2.  * OS/2 Sample Print Application PRTSAMP
  3.  *
  4.  * File name: prtcreat.c
  5.  *
  6.  * Description: Contains code that the application does once at startup.
  7.  *              These functions are called when client window procedure
  8.  *              is called with the WM_CREATE messsage.
  9.  *
  10.  *                This source file contains the following functions:
  11.  *
  12.  *                Create(hwnd)
  13.  *
  14.  * Concepts:   initialization
  15.  *
  16.  * API's:      WinQueryAnchorBlock
  17.  *             WinSetWindowULong
  18.  *             WinQueryWindow
  19.  *             WinWindowFromID
  20.  *             WinSendMsg
  21.  *             WinLoadString
  22.  *             WinSetWindowText
  23.  *             WinEnableMenuItem
  24.  *             WinEnableControl
  25.  *             WinOpenWindowDC
  26.  *             GpiCreatePS
  27.  *             GpiQueryDefaultViewMatrix
  28.  *             WinCheckMenuItem
  29.  *             GpiSetDefaultViewMatrix
  30.  *
  31.  *    Files    :  OS2.H, PRTSAMP.H, PRTSDLG.H, PMASSERT.H
  32.  *
  33.  *  Copyright (C) 1991 IBM Corporation
  34.  *
  35.  *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  36.  *      sample code created by IBM Corporation. This sample code is not
  37.  *      part of any standard or IBM product and is provided to you solely
  38.  *      for  the purpose of assisting you in the development of your
  39.  *      applications.  The code is provided "AS IS", without
  40.  *      warranty of any kind.  IBM shall not be liable for any damages
  41.  *      arising out of your use of the sample code, even if they have been
  42.  *      advised of the possibility of such damages.                                                    *
  43.  ****************************************************************************/
  44.  
  45. /* os2 includes */
  46. #define INCL_WINSTDFILE
  47. #define INCL_WINSTDFONT
  48. #define INCL_WINWINDOWMGR
  49. #define INCL_WINMENUS
  50. #define INCL_WINFRAMEMGR
  51. #define INCL_GPITRANSFORMS
  52. #define INCL_SPL
  53. #define INCL_SPLDOSPRINT
  54. #include <os2.h>
  55.  
  56. /* c language includes */
  57. #include <stdio.h>
  58. #include <stdlib.h>
  59. #include <string.h>
  60. #include <ctype.h>
  61. #include <stddef.h>
  62. #include <process.h>
  63. #include <memory.h>
  64. #include <sys\types.h>
  65. #include <sys\stat.h>
  66.  
  67. /* application includes */
  68. #include "prtsamp.h"
  69. #include "prtsdlg.h"
  70. #include "pmassert.h"
  71.  
  72.  
  73. /**************************************************************************
  74. *
  75. * Name:   Create
  76. *
  77. * Description:  Does the WM_CREATE processing for the client window;
  78. *               allocates memory for the block of main parameters and
  79. *               starts to initialize it; creates thread 2 which operates
  80. *               the object window.
  81. *
  82. * Concepts:     second thread
  83. *
  84.  * API's:      WinQueryAnchorBlock
  85.  *             WinSetWindowULong
  86.  *             WinQueryWindow
  87.  *             WinWindowFromID
  88.  *             WinSendMsg
  89.  *             WinLoadString
  90.  *             WinSetWindowText
  91.  *             WinEnableMenuItem
  92.  *             WinEnableControl
  93.  *             WinOpenWindowDC
  94.  *             GpiCreatePS
  95.  *             GpiQueryDefaultViewMatrix
  96.  *             WinCheckMenuItem
  97.  *             GpiSetDefaultViewMatrix
  98.  *
  99.  * Parameters:   hwnd = client window handle
  100.  *
  101.  * Return:       a pointer to the main block of parameters
  102.  *
  103.  **************************************************************************/
  104. PMAIN_PARM Create( HWND hwnd )
  105. {
  106.    BOOL            bOK;
  107.    CHAR            szWork[ LEN_WORKSTRING ];
  108.    HAB             hab;
  109.    PMAIN_PARM      pmp;
  110.    SEL             sel;
  111.    SIZEL           sizel;
  112.    USHORT          rc;
  113.    int             idThread;
  114.  
  115.    /* query hab */
  116.    hab = WinQueryAnchorBlock( hwnd );
  117.  
  118.    /* allocate main block of parameters. see prtsamp.h */
  119.    pmp = (PMAIN_PARM)calloc( 1, sizeof( MAIN_PARM ));
  120.    pmassert( hab, pmp );
  121.  
  122.    /* set main parmaters pointer into client window words */
  123.    bOK = WinSetWindowULong( hwnd, QWL_USER, (ULONG) pmp );
  124.    pmassert( hab, bOK  );
  125.  
  126.  
  127.    /* store hab and important window handles in the pmp */
  128.    pmp->hab          = hab;
  129.    pmp->hwndClient   = hwnd;
  130.    pmp->hwndFrame    = WinQueryWindow( hwnd, QW_PARENT );
  131.    pmp->hwndTitlebar = WinWindowFromID( pmp->hwndFrame, FID_TITLEBAR );
  132.    pmp->hwndMenubar  = WinWindowFromID( pmp->hwndFrame, FID_MENU );
  133.    pmp->hwndVScroll  = WinWindowFromID( pmp->hwndFrame, FID_VERTSCROLL);
  134.  
  135.    pmassert( hab, pmp->hwndTitlebar );
  136.    pmassert( hab, pmp->hwndMenubar  );
  137.    pmassert( hab, pmp->hwndVScroll  );
  138.  
  139.  
  140.    /* disable client and menubar until application completely initializes. */
  141.    WinSendMsg( hwnd, WM_USER_DISABLE_CLIENT, (MPARAM)0, (MPARAM)0 );
  142.  
  143.    /* set initial mode of operation to be unknown; shall know after file open */
  144.    pmp->ulMode = pmp->ulNextMode = MODE_UNKNOWN;
  145.  
  146.    /* printing options */
  147.    pmp->usCopies = 1;
  148.  
  149.    /* get program title; put in pmp and title bar */
  150.    bOK = WinLoadString( pmp->hab, (HMODULE)NULLHANDLE,
  151.                         PROGRAM_TITLE, LEN_WORKSTRING, szWork );
  152.    pmassert( hab, bOK );
  153.    pmp->pszTitle = strdup( szWork );
  154.    pmassert( hab, pmp->pszTitle );
  155.    bOK = WinSetWindowText( pmp->hwndTitlebar, pmp->pszTitle );
  156.    pmassert( hab, bOK );
  157.  
  158.    /* gray certain menu items (this is a pmwin.h macro) */
  159.    WinEnableMenuItem( pmp->hwndMenubar, IDM_PRINT,    FALSE );
  160.    WinEnableMenuItem( pmp->hwndMenubar, IDM_VIEWFULL, FALSE );
  161.    WinEnableMenuItem( pmp->hwndMenubar, IDM_VIEWHALF, FALSE );
  162.    WinEnableMenuItem( pmp->hwndMenubar, IDM_PAGEDOWN, FALSE );
  163.    WinEnableMenuItem( pmp->hwndMenubar, IDM_SETFONT,  FALSE );
  164.  
  165.    /* disable vertical scroll bar control; enable in text mode */
  166.    WinEnableControl( pmp->hwndFrame, FID_VERTSCROLL, FALSE );
  167.  
  168.    /* store window dc for hwnd */
  169.    pmp->hdcClient = WinOpenWindowDC( hwnd );
  170.    pmassert( hab, pmp->hdcClient );
  171.  
  172.    /* create a normal screen ps for the screen dc in twips */
  173.    /* 1440 twips == 1 inch; 20 twips == 1 point; 72 points per inch */
  174.    sizel.cx = 0;
  175.    sizel.cy = 0;
  176.    pmp->hpsClient = GpiCreatePS(
  177.                         hab,
  178.                         pmp->hdcClient,
  179.                         &sizel,
  180.                         PU_TWIPS | GPIF_LONG | GPIT_NORMAL | GPIA_ASSOC  );
  181.    pmassert( hab, pmp->hpsClient );
  182.  
  183.    /* query default view matrix */
  184.    bOK = GpiQueryDefaultViewMatrix( pmp->hpsClient, 9, &pmp->matlfDefView );
  185.    pmassert( pmp->hab, bOK );
  186.  
  187.    /* the scale of the matrix should be 1-to-1 */
  188.    pmassert( hab, pmp->matlfDefView.fxM11 == MAKEFIXED( 1, 0 ));
  189.    pmassert( hab, pmp->matlfDefView.fxM22 == MAKEFIXED( 1, 0 ));
  190.  
  191.    /* keep a floating point version of current scale in main parameters */
  192.    pmp->floatScale = 1.0;
  193.  
  194.    /* set check on menu item that viewing is 1-to-1 scale */
  195.    WinCheckMenuItem( pmp->hwndMenubar, IDM_VIEWFULL,  TRUE );
  196.  
  197.    /* modify default view matrix to add translation in the x direction */
  198.    pmp->matlfDefView.lM31 = OFFSET_XY_TWIPS;
  199.    bOK = GpiSetDefaultViewMatrix( pmp->hpsClient, 9,
  200.                                   &pmp->matlfDefView, TRANSFORM_REPLACE );
  201.    pmassert( pmp->hab, bOK );
  202.  
  203.    /* set up default sizelPage for letter form 8.5 x 11 portrait in twips */
  204.    /* these values will be overwritten later in initialization if the     */
  205.    /* program can load the printer last used from the profile             */
  206.    pmp->sizelPage.cx  = 11520;     /*  8.0 inches */
  207.    pmp->sizelPage.cy  = 15120;     /* 10.5 inches */
  208.  
  209.    /* prepare the file dialog structure */
  210.    pmp->filedlg.cbSize     = sizeof( FILEDLG );
  211.    pmp->filedlg.fl         = FDS_OPEN_DIALOG | FDS_CENTER | FDS_HELPBUTTON;
  212.    pmp->filedlg.pfnDlgProc = MyFileDlgProc;
  213.    pmp->filedlg.ulUser     = (ULONG)pmp;
  214.  
  215.    /* and the font dialog structure */
  216.    pmp->fontdlg.cbSize            = sizeof( FONTDLG );
  217.    pmp->fontdlg.fl            =
  218.           FNTS_CENTER | FNTS_HELPBUTTON | FNTS_VECTORONLY | FNTS_INITFROMFATTRS;
  219.    pmp->fontdlg.usFamilyBufLen    = sizeof( pmp->szFamilyname );
  220.    pmp->fontdlg.pszFamilyname     = pmp->szFamilyname;
  221.    pmp->fontdlg.pfnDlgProc        = MyFontDlgProc;
  222.    pmp->fontdlg.clrFore           = CLR_BLACK;
  223.    pmp->fontdlg.clrBack           = CLR_WHITE;
  224.    pmp->fontdlg.ulUser            = (ULONG)pmp;
  225.    pmp->fontdlg.hpsScreen     = pmp->hpsClient;
  226.    pmp->fontdlg.usWeight          = 5;                /* normal style */
  227.  
  228.    /* do more initialization on thread 2. See WM_CREATE case in prtobj.c */
  229.    /* create object window which operates on thread 2 */
  230.    /* see prtobj.c for thread 2 code and object window procedure */
  231.    idThread = _beginthread( threadmain, NULL, LEN_STACK, pmp );
  232.    pmassert( hab, idThread != 0 );
  233.  
  234.    return pmp;
  235. }  /* end of Create()  */
  236. /***************************  End of prtcreat.c ****************************/
  237.