home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / winui / comctl / reitp / oleutl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-12  |  22.6 KB  |  664 lines

  1. /*
  2.  * OLEUTL.C
  3.  *
  4.  * Miscellaneous utility functions for OLE 2.0 Applications:
  5.  *
  6.  *  Function                      Purpose
  7.  *  -------------------------------------------------------------------
  8.  *  SetDCToDrawInHimetricRect     Sets up an HIMETRIC mapping mode in a DC.
  9.  *  ResetOrigDC                   Performs the opposite of
  10.  *                                SetDCToDrawInHimetricRect
  11.  *  XformWidthInPixelsToHimetric  Converts an int width into HiMetric units
  12.  *  XformWidthInHimetricToPixels  Converts an int width from HiMetric units
  13.  *  XformHeightInPixelsToHimetric Converts an int height into HiMetric units
  14.  *  XformHeightInHimetricToPixels Converts an int height from HiMetric units
  15.  *  XformRectInPixelsToHimetric   Converts a rect into HiMetric units
  16.  *  XformRectInHimetricToPixels   Converts a rect from HiMetric units
  17.  *  XformSizeInPixelsToHimetric   Converts a SIZEL into HiMetric units
  18.  *  XformSizeInHimetricToPixels   Converts a SIZEL from HiMetric units
  19.  *  AreRectsEqual                 Compares to Rect's
  20.  *
  21.  *  ParseCmdLine                  Determines if -Embedding exists
  22.  *  OpenOrCreateRootStorage       Creates a root docfile for OLE storage
  23.  *  CommitStorage                 Commits all changes in a docfile
  24.  *  CreateChildStorage            Creates child storage in another storage
  25.  *  OpenChildStorage              Opens child storage in another storage
  26.  *
  27.  *
  28.  * Copyright (c)1992-1996 Microsoft Corporation, All Right Reserved
  29.  */
  30.  
  31.  
  32. #define STRICT  1
  33. #include "olestd.h"
  34. #include <stdlib.h>
  35. #include <ctype.h>
  36.  
  37. //Internal function to this module
  38. static LPSTR GetWord(LPSTR lpszSrc, LPSTR lpszDst);
  39.  
  40.  
  41. /*
  42.  * SetDCToAnisotropic
  43.  *
  44.  * Purpose:
  45.  *  Setup the correspondence between the rect in device unit (Viewport) and
  46.  *  the rect in logical unit (Window) so that the proper scaling of
  47.  *  coordinate systems will be calculated. set up both the Viewport and
  48.  *  the window as follows:
  49.  *
  50.  *      1) ------------------ ( 2
  51.  *      |                     |
  52.  *      |                     |
  53.  *      |                     |
  54.  *      |                     |
  55.  *      |                     |
  56.  *      3) ------------------ ( 4
  57.  *
  58.  *      Origin   = P3
  59.  *      X extent = P2x - P3x
  60.  *      Y extent = P2y - P3y
  61.  *
  62.  * Parameters:
  63.  *  hDC             HDC to affect
  64.  *  lprcPhysical    LPRECT containing the physical (device) extents of DC
  65.  *  lprcLogical     LPRECT containing the logical extents
  66.  *  lprcWindowOld   LPRECT in which to preserve the window for ResetOrigDC
  67.  *  lprcViewportOld LPRECT in which to preserver the viewport for ResetOrigDC
  68.  *
  69.  * Return Value:
  70.  *  int             The original mapping mode of the DC.
  71.  */
  72.  
  73. STDAPI_(int) SetDCToAnisotropic(
  74.                 HDC hDC,
  75.                 LPRECT lprcPhysical, LPRECT lprcLogical,
  76.                 LPRECT lprcWindowOld, LPRECT lprcViewportOld)
  77. {
  78.         int     nMapModeOld=SetMapMode(hDC, MM_ANISOTROPIC);
  79.  
  80.         SetWindowOrgEx(hDC, lprcLogical->left, lprcLogical->bottom, (LPPOINT)&lprcWindowOld->left);
  81.         SetWindowExtEx(hDC, (lprcLogical->right-lprcLogical->left), (lprcLogical->top-lprcLogical->bottom), (LPSIZE)&lprcWindowOld->right);
  82.         SetViewportOrgEx(hDC, lprcPhysical->left, lprcPhysical->bottom, (LPPOINT)&lprcViewportOld->left);
  83.         SetViewportExtEx(hDC, (lprcPhysical->right-lprcPhysical->left), (lprcPhysical->top-lprcPhysical->bottom), (LPSIZE)&lprcViewportOld->right);
  84.  
  85.         return nMapModeOld;
  86. }
  87.  
  88.  
  89. /*
  90.  * SetDCToDrawInHimetricRect
  91.  *
  92.  * Purpose:
  93.  *  Setup the correspondence between the rect in pixels (Viewport) and
  94.  *  the rect in HIMETRIC (Window) so that the proper scaling of
  95.  *  coordinate systems will be calculated. set up both the Viewport and
  96.  *  the window as follows:
  97.  *
  98.  *      1) ------------------ ( 2
  99.  *      |                     |
  100.  *      |                     |
  101.  *      |                     |
  102.  *      |                     |
  103.  *      |                     |
  104.  *      3) ------------------ ( 4
  105.  *
  106.  *      Origin   = P3
  107.  *      X extent = P2x - P3x
  108.  *      Y extent = P2y - P3y
  109.  *
  110.  * Parameters:
  111.  *  hDC             HDC to affect
  112.  *  lprcPix         LPRECT containing the pixel extents of DC
  113.  *  lprcHiMetric    LPRECT to receive the himetric extents
  114.  *  lprcWindowOld   LPRECT in which to preserve the window for ResetOrigDC
  115.  *  lprcViewportOld LPRECT in which to preserver the viewport for ResetOrigDC
  116.  *
  117.  * Return Value:
  118.  *  int             The original mapping mode of the DC.
  119.  */
  120. STDAPI_(int) SetDCToDrawInHimetricRect(
  121.         HDC hDC,
  122.         LPRECT lprcPix, LPRECT lprcHiMetric,
  123.         LPRECT lprcWindowOld, LPRECT lprcViewportOld)
  124.         {
  125.         int     nMapModeOld=SetMapMode(hDC, MM_ANISOTROPIC);
  126.         BOOL    fSystemDC  =FALSE;
  127.  
  128.         if (NULL==hDC)
  129.                 {
  130.                 hDC=GetDC(NULL);
  131.                 fSystemDC=TRUE;
  132.                 }
  133.  
  134.         XformRectInPixelsToHimetric(hDC, lprcPix, lprcHiMetric);
  135.  
  136.         SetWindowOrgEx(hDC, lprcHiMetric->left, lprcHiMetric->bottom, (LPPOINT)&lprcWindowOld->left);
  137.         SetWindowExtEx(hDC, (lprcHiMetric->right-lprcHiMetric->left), (lprcHiMetric->top-lprcHiMetric->bottom), (LPSIZE)&lprcWindowOld->right);
  138.         SetViewportOrgEx(hDC, lprcPix->left, lprcPix->bottom, (LPPOINT)&lprcViewportOld->left);
  139.         SetViewportExtEx(hDC, (lprcPix->right-lprcPix->left), (lprcPix->top-lprcPix->bottom), (LPSIZE)&lprcViewportOld->right);
  140.  
  141.         if (fSystemDC)
  142.                 ReleaseDC(NULL, hDC);
  143.  
  144.         return nMapModeOld;
  145.         }
  146.  
  147.  
  148.  
  149. /*
  150.  * ResetOrigDC
  151.  *
  152.  * Purpose:
  153.  *  Restores a DC set to draw in himetric from SetDCToDrawInHimetricRect.
  154.  *
  155.  * Parameters:
  156.  *  hDC             HDC to restore
  157.  *  nMapModeOld     int original mapping mode of hDC
  158.  *  lprcWindowOld   LPRECT filled in SetDCToDrawInHimetricRect
  159.  *  lprcViewportOld LPRECT filled in SetDCToDrawInHimetricRect
  160.  *
  161.  * Return Value:
  162.  *  int             Same as nMapModeOld.
  163.  */
  164.  
  165. STDAPI_(int) ResetOrigDC(
  166.         HDC hDC, int nMapModeOld,
  167.         LPRECT lprcWindowOld, LPRECT lprcViewportOld)
  168.         {
  169.         POINT     pOld;
  170.  
  171.         SetMapMode(hDC, nMapModeOld);
  172.  
  173.         SetWindowOrgEx(hDC,   lprcWindowOld->left,    lprcWindowOld->top,      (LPPOINT)&pOld);
  174.         SetWindowExtEx(hDC,   lprcWindowOld->right,   lprcWindowOld->bottom,   (LPSIZE)&pOld);
  175.         SetViewportOrgEx(hDC, lprcViewportOld->left,  lprcViewportOld->top,    (LPPOINT)&pOld);
  176.         SetViewportExtEx(hDC, lprcViewportOld->right, lprcViewportOld->bottom, (LPSIZE)&pOld);
  177.  
  178.         return nMapModeOld;
  179.         }
  180.  
  181.  
  182.  
  183. /*
  184.  * XformWidthInPixelsToHimetric
  185.  * XformWidthInHimetricToPixels
  186.  * XformHeightInPixelsToHimetric
  187.  * XformHeightInHimetricToPixels
  188.  *
  189.  * Functions to convert an int between a device coordinate system and
  190.  * logical HiMetric units.
  191.  *
  192.  * Parameters:
  193.  *  hDC             HDC providing reference to the pixel mapping.  If
  194.  *                  NULL, a screen DC is used.
  195.  *
  196.  *  Size Functions:
  197.  *  lpSizeSrc       LPSIZEL providing the structure to convert.  This
  198.  *                  contains pixels in XformSizeInPixelsToHimetric and
  199.  *                  logical HiMetric units in the complement function.
  200.  *  lpSizeDst       LPSIZEL providing the structure to receive converted
  201.  *                  units.  This contains pixels in
  202.  *                  XformSizeInPixelsToHimetric and logical HiMetric
  203.  *                  units in the complement function.
  204.  *
  205.  *  Width Functions:
  206.  *  iWidth          int containing the value to convert.
  207.  *
  208.  * Return Value:
  209.  *  Size Functions:     None
  210.  *  Width Functions:    Converted value of the input parameters.
  211.  *
  212.  * NOTE:
  213.  *  When displaying on the screen, Window apps display everything enlarged
  214.  *  from its actual size so that it is easier to read. For example, if an
  215.  *  app wants to display a 1in. horizontal line, that when printed is
  216.  *  actually a 1in. line on the printed page, then it will display the line
  217.  *  on the screen physically larger than 1in. This is described as a line
  218.  *  that is "logically" 1in. along the display width. Windows maintains as
  219.  *  part of the device-specific information about a given display device:
  220.  *      LOGPIXELSX -- no. of pixels per logical in along the display width
  221.  *      LOGPIXELSY -- no. of pixels per logical in along the display height
  222.  *
  223.  *  The following formula converts a distance in pixels into its equivalent
  224.  *  logical HIMETRIC units:
  225.  *
  226.  *      DistInHiMetric = (HIMETRIC_PER_INCH * DistInPix)
  227.  *                       -------------------------------
  228.  *                           PIXELS_PER_LOGICAL_IN
  229.  *
  230.  */
  231. STDAPI_(int) XformWidthInPixelsToHimetric(HDC hDC, int iWidthInPix)
  232.         {
  233.         int     iXppli;     //Pixels per logical inch along width
  234.         int     iWidthInHiMetric;
  235.         BOOL    fSystemDC=FALSE;
  236.  
  237.         if (NULL==hDC)
  238.                 {
  239.                 hDC=GetDC(NULL);
  240.                 fSystemDC=TRUE;
  241.                 }
  242.  
  243.         iXppli = GetDeviceCaps (hDC, LOGPIXELSX);
  244.  
  245.         //We got pixel units, convert them to logical HIMETRIC along the display
  246.         iWidthInHiMetric = MAP_PIX_TO_LOGHIM(iWidthInPix, iXppli);
  247.  
  248.         if (fSystemDC)
  249.                 ReleaseDC(NULL, hDC);
  250.  
  251.         return iWidthInHiMetric;
  252.         }
  253.  
  254.  
  255. STDAPI_(int) XformWidthInHimetricToPixels(HDC hDC, int iWidthInHiMetric)
  256.         {
  257.         int     iXppli;     //Pixels per logical inch along width
  258.         int     iWidthInPix;
  259.         BOOL    fSystemDC=FALSE;
  260.  
  261.         if (NULL==hDC)
  262.                 {
  263.                 hDC=GetDC(NULL);
  264.                 fSystemDC=TRUE;
  265.                 }
  266.  
  267.         iXppli = GetDeviceCaps (hDC, LOGPIXELSX);
  268.  
  269.         //We got logical HIMETRIC along the display, convert them to pixel units
  270.         iWidthInPix = MAP_LOGHIM_TO_PIX(iWidthInHiMetric, iXppli);
  271.  
  272.         if (fSystemDC)
  273.                 ReleaseDC(NULL, hDC);
  274.  
  275.         return iWidthInPix;
  276.         }
  277.  
  278.  
  279. STDAPI_(int) XformHeightInPixelsToHimetric(HDC hDC, int iHeightInPix)
  280.         {
  281.         int     iYppli;     //Pixels per logical inch along height
  282.         int     iHeightInHiMetric;
  283.         BOOL    fSystemDC=FALSE;
  284.  
  285.         if (NULL==hDC)
  286.                 {
  287.                 hDC=GetDC(NULL);
  288.                 fSystemDC=TRUE;
  289.                 }
  290.  
  291.         iYppli = GetDeviceCaps (hDC, LOGPIXELSY);
  292.  
  293.         //* We got pixel units, convert them to logical HIMETRIC along the display
  294.         iHeightInHiMetric = MAP_PIX_TO_LOGHIM(iHeightInPix, iYppli);
  295.  
  296.         if (fSystemDC)
  297.                 ReleaseDC(NULL, hDC);
  298.  
  299.         return iHeightInHiMetric;
  300.         }
  301.  
  302.  
  303. STDAPI_(int) XformHeightInHimetricToPixels(HDC hDC, int iHeightInHiMetric)
  304.         {
  305.         int     iYppli;     //Pixels per logical inch along height
  306.         int     iHeightInPix;
  307.         BOOL    fSystemDC=FALSE;
  308.  
  309.         if (NULL==hDC)
  310.                 {
  311.                 hDC=GetDC(NULL);
  312.                 fSystemDC=TRUE;
  313.                 }
  314.  
  315.         iYppli = GetDeviceCaps (hDC, LOGPIXELSY);
  316.  
  317.         //* We got logical HIMETRIC along the display, convert them to pixel units
  318.         iHeightInPix = MAP_LOGHIM_TO_PIX(iHeightInHiMetric, iYppli);
  319.  
  320.         if (fSystemDC)
  321.                 ReleaseDC(NULL, hDC);
  322.  
  323.         return iHeightInPix;
  324.         }
  325.  
  326.  
  327.  
  328. /*
  329.  * XformRectInPixelsToHimetric
  330.  * XformRectInHimetricToPixels
  331.  *
  332.  * Purpose:
  333.  *  Convert a rectangle between pixels of a given hDC and HIMETRIC units
  334.  *  as manipulated in OLE.  If the hDC is NULL, then a screen DC is used
  335.  *  and assumes the MM_TEXT mapping mode.
  336.  *
  337.  * Parameters:
  338.  *  hDC             HDC providing reference to the pixel mapping.  If
  339.  *                  NULL, a screen DC is used.
  340.  *  lprcSrc         LPRECT providing the rectangle to convert.  This
  341.  *                  contains pixels in XformRectInPixelsToHimetric and
  342.  *                  logical HiMetric units in the complement function.
  343.  *  lprcDst         LPRECT providing the rectangle to receive converted units.
  344.  *                  This contains pixels in XformRectInPixelsToHimetric and
  345.  *                  logical HiMetric units in the complement function.
  346.  *
  347.  * Return Value:
  348.  *  None
  349.  *
  350.  * NOTE:
  351.  *  When displaying on the screen, Window apps display everything enlarged
  352.  *  from its actual size so that it is easier to read. For example, if an
  353.  *  app wants to display a 1in. horizontal line, that when printed is
  354.  *  actually a 1in. line on the printed page, then it will display the line
  355.  *  on the screen physically larger than 1in. This is described as a line
  356.  *  that is "logically" 1in. along the display width. Windows maintains as
  357.  *  part of the device-specific information about a given display device:
  358.  *      LOGPIXELSX -- no. of pixels per logical in along the display width
  359.  *      LOGPIXELSY -- no. of pixels per logical in along the display height
  360.  *
  361.  *  The following formula converts a distance in pixels into its equivalent
  362.  *  logical HIMETRIC units:
  363.  *
  364.  *      DistInHiMetric = (HIMETRIC_PER_INCH * DistInPix)
  365.  *                      -------------------------------
  366.  *                            PIXELS_PER_LOGICAL_IN
  367.  *
  368.  * Rect in Pixels (MM_TEXT):
  369.  *
  370.  *              0---------- X
  371.  *              |
  372.  *              |       1) ------------------ ( 2   P1 = (rc.left, rc.top)
  373.  *              |       |                     |     P2 = (rc.right, rc.top)
  374.  *              |       |                     |     P3 = (rc.left, rc.bottom)
  375.  *              |       |                     |     P4 = (rc.right, rc.bottom)
  376.  *                      |                     |
  377.  *              Y       |                     |
  378.  *                      3) ------------------ ( 4
  379.  *
  380.  *              NOTE:   Origin   = (P1x, P1y)
  381.  *                      X extent = P4x - P1x
  382.  *                      Y extent = P4y - P1y
  383.  *
  384.  *
  385.  * Rect in Himetric (MM_HIMETRIC):
  386.  *
  387.  *
  388.  *                      1) ------------------ ( 2   P1 = (rc.left, rc.top)
  389.  *              Y       |                     |     P2 = (rc.right, rc.top)
  390.  *                      |                     |     P3 = (rc.left, rc.bottom)
  391.  *              |       |                     |     P4 = (rc.right, rc.bottom)
  392.  *              |       |                     |
  393.  *              |       |                     |
  394.  *              |       3) ------------------ ( 4
  395.  *              |
  396.  *              0---------- X
  397.  *
  398.  *              NOTE:   Origin   = (P3x, P3y)
  399.  *                      X extent = P2x - P3x
  400.  *                      Y extent = P2y - P3y
  401.  *
  402.  *
  403.  */
  404.  
  405. STDAPI_(void) XformRectInPixelsToHimetric(
  406.         HDC hDC, LPRECT lprcPix, LPRECT lprcHiMetric)
  407.         {
  408.         int     iXppli;     //Pixels per logical inch along width
  409.         int     iYppli;     //Pixels per logical inch along height
  410.         int     iXextInPix=(lprcPix->right-lprcPix->left);
  411.         int     iYextInPix=(lprcPix->bottom-lprcPix->top);
  412.         BOOL    fSystemDC=FALSE;
  413.  
  414.         if (NULL==hDC ||
  415.             GetDeviceCaps(hDC, TECHNOLOGY) == DT_METAFILE ||
  416.             GetDeviceCaps(hDC, LOGPIXELSX) == 0)
  417.                 {
  418.                 hDC=GetDC(NULL);
  419.                 fSystemDC=TRUE;
  420.                 }
  421.  
  422.         iXppli = GetDeviceCaps (hDC, LOGPIXELSX);
  423.         iYppli = GetDeviceCaps (hDC, LOGPIXELSY);
  424.  
  425.         //We got pixel units, convert them to logical HIMETRIC along the display
  426.         lprcHiMetric->right = MAP_PIX_TO_LOGHIM(iXextInPix, iXppli);
  427.         lprcHiMetric->top   = MAP_PIX_TO_LOGHIM(iYextInPix, iYppli);
  428.  
  429.         lprcHiMetric->left    = 0;
  430.         lprcHiMetric->bottom  = 0;
  431.  
  432.         if (fSystemDC)
  433.                 ReleaseDC(NULL, hDC);
  434.  
  435.         return;
  436.         }
  437.  
  438.  
  439.  
  440. STDAPI_(void) XformRectInHimetricToPixels(
  441.         HDC hDC, LPRECT lprcHiMetric, LPRECT lprcPix)
  442.         {
  443.         int     iXppli;     //Pixels per logical inch along width
  444.         int     iYppli;     //Pixels per logical inch along height
  445.         int     iXextInHiMetric=(lprcHiMetric->right-lprcHiMetric->left);
  446.         int     iYextInHiMetric=(lprcHiMetric->bottom-lprcHiMetric->top);
  447.         BOOL    fSystemDC=FALSE;
  448.  
  449.         if (NULL==hDC ||
  450.             GetDeviceCaps(hDC, TECHNOLOGY) == DT_METAFILE ||
  451.             GetDeviceCaps(hDC, LOGPIXELSX) == 0)
  452.                 {
  453.                 hDC=GetDC(NULL);
  454.                 fSystemDC=TRUE;
  455.                 }
  456.  
  457.         iXppli = GetDeviceCaps (hDC, LOGPIXELSX);
  458.         iYppli = GetDeviceCaps (hDC, LOGPIXELSY);
  459.  
  460.         //We got pixel units, convert them to logical HIMETRIC along the display
  461.         lprcPix->right = MAP_LOGHIM_TO_PIX(iXextInHiMetric, iXppli);
  462.         lprcPix->top   = MAP_LOGHIM_TO_PIX(iYextInHiMetric, iYppli);
  463.  
  464.         lprcPix->left  = 0;
  465.         lprcPix->bottom= 0;
  466.  
  467.         if (fSystemDC)
  468.                 ReleaseDC(NULL, hDC);
  469.  
  470.         return;
  471.         }
  472.  
  473.  
  474.  
  475.  
  476. /*
  477.  * XformSizeInPixelsToHimetric
  478.  * XformSizeInHimetricToPixels
  479.  *
  480.  * Functions to convert a SIZEL structure (Size functions) or
  481.  * an int (Width functions) between a device coordinate system and
  482.  * logical HiMetric units.
  483.  *
  484.  * Parameters:
  485.  *  hDC             HDC providing reference to the pixel mapping.  If
  486.  *                  NULL, a screen DC is used.
  487.  *
  488.  *  Size Functions:
  489.  *  lpSizeSrc       LPSIZEL providing the structure to convert.  This
  490.  *                  contains pixels in XformSizeInPixelsToHimetric and
  491.  *                  logical HiMetric units in the complement function.
  492.  *  lpSizeDst       LPSIZEL providing the structure to receive converted
  493.  *                  units.  This contains pixels in
  494.  *                  XformSizeInPixelsToHimetric and logical HiMetric
  495.  *                  units in the complement function.
  496.  *
  497.  *  Width Functions:
  498.  *  iWidth          int containing the value to convert.
  499.  *
  500.  * Return Value:
  501.  *  Size Functions:     None
  502.  *  Width Functions:    Converted value of the input parameters.
  503.  *
  504.  * NOTE:
  505.  *  When displaying on the screen, Window apps display everything enlarged
  506.  *  from its actual size so that it is easier to read. For example, if an
  507.  *  app wants to display a 1in. horizontal line, that when printed is
  508.  *  actually a 1in. line on the printed page, then it will display the line
  509.  *  on the screen physically larger than 1in. This is described as a line
  510.  *  that is "logically" 1in. along the display width. Windows maintains as
  511.  *  part of the device-specific information about a given display device:
  512.  *      LOGPIXELSX -- no. of pixels per logical in along the display width
  513.  *      LOGPIXELSY -- no. of pixels per logical in along the display height
  514.  *
  515.  *  The following formula converts a distance in pixels into its equivalent
  516.  *  logical HIMETRIC units:
  517.  *
  518.  *      DistInHiMetric = (HIMETRIC_PER_INCH * DistInPix)
  519.  *                       -------------------------------
  520.  *                           PIXELS_PER_LOGICAL_IN
  521.  *
  522.  */
  523.  
  524. STDAPI_(void) XformSizeInPixelsToHimetric(
  525.         HDC hDC, LPSIZEL lpSizeInPix, LPSIZEL lpSizeInHiMetric)
  526.         {
  527.         int     iXppli;     //Pixels per logical inch along width
  528.         int     iYppli;     //Pixels per logical inch along height
  529.         BOOL    fSystemDC=FALSE;
  530.  
  531.         if (NULL==hDC ||
  532.             GetDeviceCaps(hDC, TECHNOLOGY) == DT_METAFILE ||
  533.             GetDeviceCaps(hDC, LOGPIXELSX) == 0)
  534.                 {
  535.                 hDC=GetDC(NULL);
  536.                 fSystemDC=TRUE;
  537.                 }
  538.  
  539.         iXppli = GetDeviceCaps (hDC, LOGPIXELSX);
  540.         iYppli = GetDeviceCaps (hDC, LOGPIXELSY);
  541.  
  542.         //We got pixel units, convert them to logical HIMETRIC along the display
  543.         lpSizeInHiMetric->cx = (long)MAP_PIX_TO_LOGHIM((int)lpSizeInPix->cx, iXppli);
  544.         lpSizeInHiMetric->cy = (long)MAP_PIX_TO_LOGHIM((int)lpSizeInPix->cy, iYppli);
  545.  
  546.         if (fSystemDC)
  547.                 ReleaseDC(NULL, hDC);
  548.  
  549.         return;
  550.         }
  551.  
  552.  
  553. STDAPI_(void) XformSizeInHimetricToPixels(
  554.         HDC hDC, LPSIZEL lpSizeInHiMetric, LPSIZEL lpSizeInPix)
  555.         {
  556.         int     iXppli;     //Pixels per logical inch along width
  557.         int     iYppli;     //Pixels per logical inch along height
  558.         BOOL    fSystemDC=FALSE;
  559.  
  560.         if (NULL==hDC ||
  561.             GetDeviceCaps(hDC, TECHNOLOGY) == DT_METAFILE ||
  562.             GetDeviceCaps(hDC, LOGPIXELSX) == 0)
  563.                 {
  564.                 hDC=GetDC(NULL);
  565.                 fSystemDC=TRUE;
  566.                 }
  567.  
  568.         iXppli = GetDeviceCaps (hDC, LOGPIXELSX);
  569.         iYppli = GetDeviceCaps (hDC, LOGPIXELSY);
  570.  
  571.         //We got logical HIMETRIC along the display, convert them to pixel units
  572.         lpSizeInPix->cx = (long)MAP_LOGHIM_TO_PIX((int)lpSizeInHiMetric->cx, iXppli);
  573.         lpSizeInPix->cy = (long)MAP_LOGHIM_TO_PIX((int)lpSizeInHiMetric->cy, iYppli);
  574.  
  575.         if (fSystemDC)
  576.                 ReleaseDC(NULL, hDC);
  577.  
  578.         return;
  579.         }
  580.  
  581.  
  582. #if defined( OBSOLETE )
  583. // This function has been converted to a macro
  584.  
  585. /* AreRectsEqual
  586. ** -------------
  587. */
  588. STDAPI_(BOOL) AreRectsEqual(LPRECT lprc1, LPRECT lprc2)
  589. {
  590.         if ((lprc1->top == lprc2->top) &&
  591.                 (lprc1->left == lprc2->left) &&
  592.                 (lprc1->right == lprc2->right) &&
  593.                 (lprc1->bottom == lprc2->bottom))
  594.                 return TRUE;
  595.  
  596.         return FALSE;
  597. }
  598. #endif  // OBSOLETE
  599.  
  600.  
  601. /*
  602.  * ParseCmdLine
  603.  *
  604.  * Parses the Windows command line which was passed to WinMain.
  605.  * This function determines if the -Embedding switch has been given.
  606.  *
  607.  */
  608.  
  609. STDAPI_(void) ParseCmdLine(
  610.         LPSTR lpszLine,
  611.         BOOL FAR* lpfEmbedFlag,
  612.         LPSTR szFileName)
  613. {
  614.         int i=0;
  615.         char szBuf[256];
  616.  
  617.         if(lpfEmbedFlag)
  618.                 *lpfEmbedFlag = FALSE;
  619.         szFileName[0]='\0';             // NULL string
  620.  
  621.         // skip blanks
  622.         while(isspace(*lpszLine)) lpszLine++;
  623.  
  624.         if(!*lpszLine)   // No filename or options, so start a fresh document.
  625.                 return;
  626.  
  627.         // Check for "-Embedding" or "/Embedding" and set fEmbedding.
  628.         if(lpfEmbedFlag && (*lpszLine == '-' || *lpszLine == '/')) {
  629.                 lpszLine++;
  630.                 lpszLine = GetWord(lpszLine, szBuf);
  631.                 *lpfEmbedFlag = !lstrcmp(szBuf, EMBEDDINGFLAG);
  632.         }
  633.  
  634.         // skip blanks
  635.         while(isspace(*lpszLine)) lpszLine++;
  636.  
  637.         // set szFileName to argument
  638.         while(lpszLine[i]) {
  639.                 szFileName[i]=lpszLine[i];
  640.                 i++;
  641.         }
  642.         szFileName[i]='\0';
  643. }
  644.  
  645.  
  646. /* GetWord
  647.  * -------
  648.  *
  649.  * LPSTR lpszSrc - Pointer to a source string
  650.  * LPSTR lpszDst - Pointer to destination buffer
  651.  *
  652.  * Will copy one space-terminated or null-terminated word from the source
  653.  * string to the destination buffer.
  654.  * returns: pointer to next character following the word.
  655.  */
  656. static LPSTR GetWord(LPSTR lpszSrc, LPSTR lpszDst)
  657. {
  658.         while (*lpszSrc && !isspace(*lpszSrc))
  659.                 *lpszDst++ = *lpszSrc++;
  660.  
  661.         *lpszDst = '\0';
  662.         return lpszSrc;
  663. }
  664.