⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oleutl.c

📁 文本编辑器
💻 C
📖 第 1 页 / 共 2 页
字号:
 *  Convert a rectangle between pixels of a given hDC and HIMETRIC units
 *  as manipulated in OLE.  If the hDC is NULL, then a screen DC is used
 *  and assumes the MM_TEXT mapping mode.
 *
 * Parameters:
 *  hDC             HDC providing reference to the pixel mapping.  If
 *                  NULL, a screen DC is used.
 *  lprcSrc         LPRECT providing the rectangle to convert.  This
 *                  contains pixels in XformRectInPixelsToHimetric and
 *                  logical HiMetric units in the complement function.
 *  lprcDst         LPRECT providing the rectangle to receive converted units.
 *                  This contains pixels in XformRectInPixelsToHimetric and
 *                  logical HiMetric units in the complement function.
 *
 * Return Value:
 *  None
 *
 * NOTE:
 *  When displaying on the screen, Window apps display everything enlarged
 *  from its actual size so that it is easier to read. For example, if an
 *  app wants to display a 1in. horizontal line, that when printed is
 *  actually a 1in. line on the printed page, then it will display the line
 *  on the screen physically larger than 1in. This is described as a line
 *  that is "logically" 1in. along the display width. Windows maintains as
 *  part of the device-specific information about a given display device:
 *      LOGPIXELSX -- no. of pixels per logical in along the display width
 *      LOGPIXELSY -- no. of pixels per logical in along the display height
 *
 *  The following formula converts a distance in pixels into its equivalent
 *  logical HIMETRIC units:
 *
 *      DistInHiMetric = (HIMETRIC_PER_INCH * DistInPix)
 *                      -------------------------------
 *                            PIXELS_PER_LOGICAL_IN
 *
 * Rect in Pixels (MM_TEXT):
 *
 *              0---------- X
 *              |
 *              |       1) ------------------ ( 2   P1 = (rc.left, rc.top)
 *              |       |                     |     P2 = (rc.right, rc.top)
 *              |       |                     |     P3 = (rc.left, rc.bottom)
 *              |       |                     |     P4 = (rc.right, rc.bottom)
 *                      |                     |
 *              Y       |                     |
 *                      3) ------------------ ( 4
 *
 *              NOTE:   Origin   = (P1x, P1y)
 *                      X extent = P4x - P1x
 *                      Y extent = P4y - P1y
 *
 *
 * Rect in Himetric (MM_HIMETRIC):
 *
 *
 *                      1) ------------------ ( 2   P1 = (rc.left, rc.top)
 *              Y       |                     |     P2 = (rc.right, rc.top)
 *                      |                     |     P3 = (rc.left, rc.bottom)
 *              |       |                     |     P4 = (rc.right, rc.bottom)
 *              |       |                     |
 *              |       |                     |
 *              |       3) ------------------ ( 4
 *              |
 *              0---------- X
 *
 *              NOTE:   Origin   = (P3x, P3y)
 *                      X extent = P2x - P3x
 *                      Y extent = P2y - P3y
 *
 *
 */

STDAPI_(void) XformRectInPixelsToHimetric(
        HDC hDC, LPRECT lprcPix, LPRECT lprcHiMetric)
        {
        int     iXppli;     //Pixels per logical inch along width
        int     iYppli;     //Pixels per logical inch along height
        int     iXextInPix=(lprcPix->right-lprcPix->left);
        int     iYextInPix=(lprcPix->bottom-lprcPix->top);
        BOOL    fSystemDC=FALSE;

        if (NULL==hDC ||
            GetDeviceCaps(hDC, TECHNOLOGY) == DT_METAFILE ||
            GetDeviceCaps(hDC, LOGPIXELSX) == 0)
                {
                hDC=GetDC(NULL);
                fSystemDC=TRUE;
                }

        iXppli = GetDeviceCaps (hDC, LOGPIXELSX);
        iYppli = GetDeviceCaps (hDC, LOGPIXELSY);

        //We got pixel units, convert them to logical HIMETRIC along the display
        lprcHiMetric->right = MAP_PIX_TO_LOGHIM(iXextInPix, iXppli);
        lprcHiMetric->top   = MAP_PIX_TO_LOGHIM(iYextInPix, iYppli);

        lprcHiMetric->left    = 0;
        lprcHiMetric->bottom  = 0;

        if (fSystemDC)
                ReleaseDC(NULL, hDC);

        return;
        }



STDAPI_(void) XformRectInHimetricToPixels(
        HDC hDC, LPRECT lprcHiMetric, LPRECT lprcPix)
        {
        int     iXppli;     //Pixels per logical inch along width
        int     iYppli;     //Pixels per logical inch along height
        int     iXextInHiMetric=(lprcHiMetric->right-lprcHiMetric->left);
        int     iYextInHiMetric=(lprcHiMetric->bottom-lprcHiMetric->top);
        BOOL    fSystemDC=FALSE;

        if (NULL==hDC ||
            GetDeviceCaps(hDC, TECHNOLOGY) == DT_METAFILE ||
            GetDeviceCaps(hDC, LOGPIXELSX) == 0)
                {
                hDC=GetDC(NULL);
                fSystemDC=TRUE;
                }

        iXppli = GetDeviceCaps (hDC, LOGPIXELSX);
        iYppli = GetDeviceCaps (hDC, LOGPIXELSY);

        //We got pixel units, convert them to logical HIMETRIC along the display
        lprcPix->right = MAP_LOGHIM_TO_PIX(iXextInHiMetric, iXppli);
        lprcPix->top   = MAP_LOGHIM_TO_PIX(iYextInHiMetric, iYppli);

        lprcPix->left  = 0;
        lprcPix->bottom= 0;

        if (fSystemDC)
                ReleaseDC(NULL, hDC);

        return;
        }




/*
 * XformSizeInPixelsToHimetric
 * XformSizeInHimetricToPixels
 *
 * Functions to convert a SIZEL structure (Size functions) or
 * an int (Width functions) between a device coordinate system and
 * logical HiMetric units.
 *
 * Parameters:
 *  hDC             HDC providing reference to the pixel mapping.  If
 *                  NULL, a screen DC is used.
 *
 *  Size Functions:
 *  lpSizeSrc       LPSIZEL providing the structure to convert.  This
 *                  contains pixels in XformSizeInPixelsToHimetric and
 *                  logical HiMetric units in the complement function.
 *  lpSizeDst       LPSIZEL providing the structure to receive converted
 *                  units.  This contains pixels in
 *                  XformSizeInPixelsToHimetric and logical HiMetric
 *                  units in the complement function.
 *
 *  Width Functions:
 *  iWidth          int containing the value to convert.
 *
 * Return Value:
 *  Size Functions:     None
 *  Width Functions:    Converted value of the input parameters.
 *
 * NOTE:
 *  When displaying on the screen, Window apps display everything enlarged
 *  from its actual size so that it is easier to read. For example, if an
 *  app wants to display a 1in. horizontal line, that when printed is
 *  actually a 1in. line on the printed page, then it will display the line
 *  on the screen physically larger than 1in. This is described as a line
 *  that is "logically" 1in. along the display width. Windows maintains as
 *  part of the device-specific information about a given display device:
 *      LOGPIXELSX -- no. of pixels per logical in along the display width
 *      LOGPIXELSY -- no. of pixels per logical in along the display height
 *
 *  The following formula converts a distance in pixels into its equivalent
 *  logical HIMETRIC units:
 *
 *      DistInHiMetric = (HIMETRIC_PER_INCH * DistInPix)
 *                       -------------------------------
 *                           PIXELS_PER_LOGICAL_IN
 *
 */

STDAPI_(void) XformSizeInPixelsToHimetric(
        HDC hDC, LPSIZEL lpSizeInPix, LPSIZEL lpSizeInHiMetric)
        {
        int     iXppli;     //Pixels per logical inch along width
        int     iYppli;     //Pixels per logical inch along height
        BOOL    fSystemDC=FALSE;

        if (NULL==hDC ||
            GetDeviceCaps(hDC, TECHNOLOGY) == DT_METAFILE ||
            GetDeviceCaps(hDC, LOGPIXELSX) == 0)
                {
                hDC=GetDC(NULL);
                fSystemDC=TRUE;
                }

        iXppli = GetDeviceCaps (hDC, LOGPIXELSX);
        iYppli = GetDeviceCaps (hDC, LOGPIXELSY);

        //We got pixel units, convert them to logical HIMETRIC along the display
        lpSizeInHiMetric->cx = (long)MAP_PIX_TO_LOGHIM((int)lpSizeInPix->cx, iXppli);
        lpSizeInHiMetric->cy = (long)MAP_PIX_TO_LOGHIM((int)lpSizeInPix->cy, iYppli);

        if (fSystemDC)
                ReleaseDC(NULL, hDC);

        return;
        }


STDAPI_(void) XformSizeInHimetricToPixels(
        HDC hDC, LPSIZEL lpSizeInHiMetric, LPSIZEL lpSizeInPix)
        {
        int     iXppli;     //Pixels per logical inch along width
        int     iYppli;     //Pixels per logical inch along height
        BOOL    fSystemDC=FALSE;

        if (NULL==hDC ||
            GetDeviceCaps(hDC, TECHNOLOGY) == DT_METAFILE ||
            GetDeviceCaps(hDC, LOGPIXELSX) == 0)
                {
                hDC=GetDC(NULL);
                fSystemDC=TRUE;
                }

        iXppli = GetDeviceCaps (hDC, LOGPIXELSX);
        iYppli = GetDeviceCaps (hDC, LOGPIXELSY);

        //We got logical HIMETRIC along the display, convert them to pixel units
        lpSizeInPix->cx = (long)MAP_LOGHIM_TO_PIX((int)lpSizeInHiMetric->cx, iXppli);
        lpSizeInPix->cy = (long)MAP_LOGHIM_TO_PIX((int)lpSizeInHiMetric->cy, iYppli);

        if (fSystemDC)
                ReleaseDC(NULL, hDC);

        return;
        }


#if defined( OBSOLETE )
// This function has been converted to a macro

/* AreRectsEqual
** -------------
*/
STDAPI_(BOOL) AreRectsEqual(LPRECT lprc1, LPRECT lprc2)
{
        if ((lprc1->top == lprc2->top) &&
                (lprc1->left == lprc2->left) &&
                (lprc1->right == lprc2->right) &&
                (lprc1->bottom == lprc2->bottom))
                return TRUE;

        return FALSE;
}
#endif  // OBSOLETE


/*
 * ParseCmdLine
 *
 * Parses the Windows command line which was passed to WinMain.
 * This function determines if the -Embedding switch has been given.
 *
 */

STDAPI_(void) ParseCmdLine(
        LPSTR lpszLine,
        BOOL FAR* lpfEmbedFlag,
        LPSTR szFileName)
{
        int i=0;
        char szBuf[256];

        if(lpfEmbedFlag)
                *lpfEmbedFlag = FALSE;
        szFileName[0]='\0';             // NULL string

        // skip blanks
        while(isspace(*lpszLine)) lpszLine++;

        if(!*lpszLine)   // No filename or options, so start a fresh document.
                return;

        // Check for "-Embedding" or "/Embedding" and set fEmbedding.
        if(lpfEmbedFlag && (*lpszLine == '-' || *lpszLine == '/')) {
                lpszLine++;
                lpszLine = GetWord(lpszLine, szBuf);
                *lpfEmbedFlag = !lstrcmp(szBuf, EMBEDDINGFLAG);
        }

        // skip blanks
        while(isspace(*lpszLine)) lpszLine++;

        // set szFileName to argument
        while(lpszLine[i]) {
                szFileName[i]=lpszLine[i];
                i++;
        }
        szFileName[i]='\0';
}


/* GetWord
 * -------
 *
 * LPSTR lpszSrc - Pointer to a source string
 * LPSTR lpszDst - Pointer to destination buffer
 *
 * Will copy one space-terminated or null-terminated word from the source
 * string to the destination buffer.
 * returns: pointer to next character following the word.
 */
static LPSTR GetWord(LPSTR lpszSrc, LPSTR lpszDst)
{
        while (*lpszSrc && !isspace(*lpszSrc))
                *lpszDst++ = *lpszSrc++;

        *lpszDst = '\0';
        return lpszSrc;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -