home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / prtsampl.zip / PRTCREAT.C < prev    next >
C/C++ Source or Header  |  1998-04-20  |  9KB  |  254 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-1993 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_DEV
  47. #define INCL_GPITRANSFORMS
  48. #define INCL_SPL
  49. #define INCL_SPLDOSPRINT
  50. #define INCL_WINERRORS
  51. #define INCL_WINFRAMEMGR
  52. #define INCL_WINMENUS
  53. #define INCL_WINSTDFILE
  54. #define INCL_WINSTDFONT
  55. #define INCL_WINWINDOWMGR
  56. #include <os2.h>
  57.  
  58. /* c language includes */
  59. #include <stdio.h>
  60. #include <stdlib.h>
  61. #include <string.h>
  62. #include <ctype.h>
  63. #include <stddef.h>
  64. #include <process.h>
  65. #include <memory.h>
  66. #include <sys\types.h>
  67. #include <sys\stat.h>
  68.  
  69. /* application includes */
  70. #include "prtsamp.h"
  71. #include "prtsdlg.h"
  72. #include "pmassert.h"
  73.  
  74.  
  75. /**************************************************************************
  76. *
  77. * Name:   Create
  78. *
  79. * Description:  Does the WM_CREATE processing for the client window;
  80. *               allocates memory for the block of main parameters and
  81. *               starts to initialize it; creates thread 2 which operates
  82. *               the object window.
  83. *
  84. * Concepts:     second thread
  85. *
  86.  * API's:      WinQueryAnchorBlock
  87.  *             WinSetWindowULong
  88.  *             WinQueryWindow
  89.  *             WinWindowFromID
  90.  *             WinSendMsg
  91.  *             WinLoadString
  92.  *             WinSetWindowText
  93.  *             WinEnableMenuItem
  94.  *             WinEnableControl
  95.  *             WinOpenWindowDC
  96.  *             GpiCreatePS
  97.  *             GpiQueryDefaultViewMatrix
  98.  *             WinCheckMenuItem
  99.  *             GpiSetDefaultViewMatrix
  100.  *
  101.  * Parameters:   hwnd = client window handle
  102.  *
  103.  * Return:       a pointer to the main block of parameters
  104.  *
  105.  **************************************************************************/
  106. PMAIN_PARM Create( HWND hwnd )
  107. {
  108.    BOOL            bOK;
  109.    CHAR            szWork[ LEN_WORKSTRING ];
  110.    HAB             hab;
  111.    PMAIN_PARM      pmp;
  112.    SIZEL           sizel;
  113.  
  114.    /* query hab */
  115.    hab = WinQueryAnchorBlock( hwnd );
  116.  
  117.    /* allocate main block of parameters. see prtsamp.h */
  118.    pmp = (PMAIN_PARM)calloc( 1, sizeof( MAIN_PARM ));
  119.    pmassert( hab, pmp );
  120.  
  121.    /* set main parmaters pointer into client window words */
  122.    bOK = WinSetWindowULong( hwnd, QWL_USER, (ULONG) pmp );
  123.    pmassert( hab, bOK  );
  124.  
  125.  
  126.    /* store hab and important window handles in the pmp */
  127.    pmp->hab          = hab;
  128.    pmp->hwndClient   = hwnd;
  129.    pmp->hwndFrame    = WinQueryWindow( hwnd, QW_PARENT );
  130.    pmp->hwndTitlebar = WinWindowFromID( pmp->hwndFrame, FID_TITLEBAR );
  131.    pmp->hwndMenubar  = WinWindowFromID( pmp->hwndFrame, FID_MENU );
  132.    pmp->hwndVScroll  = WinWindowFromID( pmp->hwndFrame, FID_VERTSCROLL);
  133.    pmp->hwndHScroll  = WinWindowFromID( pmp->hwndFrame, FID_HORZSCROLL);
  134.  
  135.    pmassert( hab, pmp->hwndTitlebar );
  136.    pmassert( hab, pmp->hwndMenubar  );
  137.    pmassert( hab, pmp->hwndVScroll  );
  138.    pmassert( hab, pmp->hwndHScroll  );
  139.  
  140.  
  141.    /* disable client and menubar until application completely initializes. */
  142.    WinSendMsg( hwnd, WM_USER_DISABLE_CLIENT, (MPARAM)0, (MPARAM)0 );
  143.  
  144.    /* set initial mode of operation to be unknown; shall know after file open */
  145.    pmp->ulMode = pmp->ulNextMode = MODE_UNKNOWN;
  146.  
  147.    /* printing options */
  148.    pmp->usCopies = 1;
  149.  
  150.    /* get program title; put in pmp and title bar */
  151.    bOK = WinLoadString( pmp->hab, (HMODULE)NULLHANDLE,
  152.                         PROGRAM_TITLE, LEN_WORKSTRING, szWork );
  153.    pmassert( hab, bOK );
  154.    pmp->pszTitle = strdup( szWork );
  155.    pmassert( hab, pmp->pszTitle );
  156.    bOK = WinSetWindowText( pmp->hwndTitlebar, pmp->pszTitle );
  157.    pmassert( hab, bOK );
  158.  
  159.    /* gray certain menu items (this is a pmwin.h macro) */
  160.    WinEnableMenuItem( pmp->hwndMenubar, IDM_PRINT,    FALSE );
  161.    WinEnableMenuItem( pmp->hwndMenubar, IDM_VIEWFULL, FALSE );
  162.    WinEnableMenuItem( pmp->hwndMenubar, IDM_VIEWHALF, FALSE );
  163.  
  164.    /* disable menu items; this will be enabled for text mode */
  165.    WinEnableMenuItem( pmp->hwndMenubar, IDM_PAGEDOWN, FALSE );
  166.    WinEnableMenuItem( pmp->hwndMenubar, IDM_SETFONT,  FALSE );
  167.  
  168.    /* disable scroll bar controls */
  169.    WinEnableControl( pmp->hwndFrame, FID_HORZSCROLL, FALSE );
  170.    WinEnableControl( pmp->hwndFrame, FID_VERTSCROLL, FALSE );
  171.  
  172.    /* store window dc for hwnd */
  173.    pmp->hdcClient = WinOpenWindowDC( hwnd );
  174.    pmassert( hab, pmp->hdcClient );
  175.  
  176.    /* create a normal screen ps for the screen dc in twips */
  177.    /* 1440 twips == 1 inch; 20 twips == 1 point; 72 points per inch */
  178.    sizel.cx = 0;
  179.    sizel.cy = 0;
  180.    pmp->hpsClient = GpiCreatePS(
  181.                         hab,
  182.                         pmp->hdcClient,
  183.                         &sizel,
  184.                         PU_TWIPS | GPIF_LONG | GPIT_NORMAL | GPIA_ASSOC  );
  185.    pmassert( hab, pmp->hpsClient );
  186.  
  187.  
  188.    /* set up null form, we will choose the default form later */
  189.    strcpy(pmp->form.achFormName, "");
  190.  
  191.    /* set up default margins - 0.5 inch all round */
  192.    pmp->form.fxLeftMargin = MAKEFIXED( 0, 0x8000 );
  193.    pmp->form.fxRightMargin = MAKEFIXED( 0, 0x8000 );
  194.    pmp->form.fxTopMargin = MAKEFIXED( 0, 0x8000 );
  195.    pmp->form.fxBottomMargin = MAKEFIXED( 0, 0x8000 );
  196.  
  197.    /* query default view matrix */
  198.    bOK = GpiQueryDefaultViewMatrix( pmp->hpsClient, 9, &pmp->matlfDefView );
  199.    pmassert( pmp->hab, bOK );
  200.  
  201.    /* the scale of the matrix should be 1-to-1 */
  202.    pmassert( hab, pmp->matlfDefView.fxM11 == MAKEFIXED( 1, 0 ));
  203.    pmassert( hab, pmp->matlfDefView.fxM22 == MAKEFIXED( 1, 0 ));
  204.  
  205.    /* keep a floating point version of current scale in main parameters */
  206.    pmp->floatScale = 1.0;
  207.    /* set check on menu item that viewing is 1-to-1 scale */
  208.    WinCheckMenuItem( pmp->hwndMenubar, IDM_VIEWFULL,  TRUE );
  209.  
  210.    /*
  211.     * Set translations to zero, these will be updated when the window is
  212.     * sized. Set default viewing matrix.
  213.     */
  214.    pmp->matlfDefView.lM31 = 0;
  215.    pmp->matlfDefView.lM32 = 0;
  216.    bOK = GpiSetDefaultViewMatrix( pmp->hpsClient, 9,
  217.                                   &pmp->matlfDefView, TRANSFORM_REPLACE );
  218.    pmassert( pmp->hab, bOK );
  219.  
  220.    /* set print dialog values to default values */
  221.    pmp->usCopies = 1;
  222.    pmp->fPrintAllPages = TRUE;
  223.    pmp->usFirstPage = 1;
  224.    pmp->usLastPage = 1;
  225.  
  226.    /* prepare the file dialog structure */
  227.    pmp->filedlg.cbSize     = sizeof( FILEDLG );
  228.    pmp->filedlg.fl         = FDS_OPEN_DIALOG | FDS_CENTER | FDS_HELPBUTTON;
  229.    pmp->filedlg.pfnDlgProc = MyFileDlgProc;
  230.    pmp->filedlg.ulUser     = (ULONG)pmp;
  231.  
  232.    /* and the font dialog structure */
  233.    pmp->fontdlg.cbSize            = sizeof( FONTDLG );
  234.    pmp->fontdlg.fl            =
  235.           FNTS_CENTER | FNTS_HELPBUTTON | FNTS_VECTORONLY | FNTS_INITFROMFATTRS;
  236.    pmp->fontdlg.usFamilyBufLen    = sizeof( pmp->szFamilyname );
  237.    pmp->fontdlg.pszFamilyname     = pmp->szFamilyname;
  238.    pmp->fontdlg.pfnDlgProc        = MyFontDlgProc;
  239.    pmp->fontdlg.clrFore           = CLR_BLACK;
  240.    pmp->fontdlg.clrBack           = CLR_WHITE;
  241.    pmp->fontdlg.ulUser            = (ULONG)pmp;
  242.    pmp->fontdlg.hpsScreen     = pmp->hpsClient;
  243.    pmp->fontdlg.usWeight          = 5;                /* normal style */
  244.  
  245.    /* do more initialization on thread 2. See WM_CREATE case in prtobj.c */
  246.    /* create object window which operates on thread 2 */
  247.    /* see prtobj.c for thread 2 code and object window procedure */
  248.    pmp->tidObjectThread = (TID)_beginthread( threadmain, NULL, LEN_STACK, pmp );
  249.    pmassert( hab, pmp->tidObjectThread != 0 );
  250.  
  251.    return pmp;
  252. }  /* end of Create()  */
  253. /***************************  End of prtcreat.c ****************************/
  254.