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

📄 polyline.c

📁 英文版的 想要的话可以下载了 为大家服务
💻 C
📖 第 1 页 / 共 2 页
字号:
               #endif
                }

            //Insure repaint
            InvalidateRect(hWnd, NULL, TRUE);
            UpdateWindow(hWnd);
            break;


        case PLM_POLYLINESET:
            /*
             * Copy the structure in lParam to ppl and repaint to
             * reflect the new point set.  Note that unlike the
             * PLM_RECTSET message, we do no scaling, assuming that
             * the rectangle in the POLYLINE structure is appropriate
             * for the data.
             */
            pplT=(LPPOLYLINE)lParam;
            *ppl=*pplT;

            //Resize this window to fit the data and notify the parent.
            SetWindowPos(hWnd, NULL, ppl->rc.left, ppl->rc.top
                , ppl->rc.right-ppl->rc.left, ppl->rc.bottom-ppl->rc.top
                , SWP_NOMOVE | SWP_NOZORDER);

            if (0!=wParam)
                {
               #ifdef WIN32
                SendMessage(hWndParent, WM_COMMAND
                    , MAKELONG(ID_POLYLINE, PLN_SIZECHANGE), (LPARAM)hWnd);
               #else
                SendMessage(hWndParent, WM_COMMAND
                    , ID_POLYLINE, MAKELONG(hWnd, PLN_SIZECHANGE));
               #endif
                }

            //Insure a repaint.
            InvalidateRect(hWnd, NULL, TRUE);
            UpdateWindow(hWnd);
            break;


        case PLM_POLYLINEGET:
            //Copy the structure in ppl to lParam.  No repaint needed.
            pplT=(LPPOLYLINE)lParam;
            *pplT=*ppl;
            break;


        case PLM_POLYLINENEW:
            //Clean out the POLYLINE structure and repaint the window.
            for (i=0; i< CPOLYLINEPOINTS; i++)
                {
                ppl->rgpt[i].x=0;
                ppl->rgpt[i].y=0;
                }

            ppl->cPoints=0;

            InvalidateRect(hWnd, NULL, TRUE);
            UpdateWindow(hWnd);
            break;


        case PLM_BACKUPUNDO:
            //Decrement the number of active points and repaint.
            if (ppl->cPoints > 0)
                {
                ppl->cPoints--;
                InvalidateRect(hWnd, NULL, TRUE);
                UpdateWindow(hWnd);
                }

            //Notify parent window of the change.
           #ifdef WIN32
            SendMessage(hWndParent, WM_COMMAND
                , MAKELONG(ID_POLYLINE, PLN_POINTCHANGE), (LPARAM)hWnd);
           #else
            SendMessage(hWndParent, WM_COMMAND
                , ID_POLYLINE, MAKELONG(hWnd, PLN_POINTCHANGE));
           #endif
            break;


        case PLM_BITMAPGET:
            /*
             * Create and return a bitmap of the window contents.
             * The bitmap is the size of the POLYLINE edit window.
             */

            hDC=GetDC(hWnd);
            hMemDC=CreateCompatibleDC(hDC);

            GetClientRect(hWnd, &rc);
            hBmp=CreateCompatibleBitmap(hDC, rc.right, rc.bottom);

            if (NULL!=hBmp)
                {
                //Draw the POLYLINE into the bitmap.
                hBmpT=SelectObject(hMemDC, hBmp);

                ppl->fDrawEntire=TRUE;
                PolylineDraw(hWnd, hMemDC, ppl);
                ppl->fDrawEntire=FALSE;

                SelectObject(hMemDC, hBmpT);
                }

            DeleteDC(hMemDC);
            ReleaseDC(hWnd, hDC);

            //Return the created bitmap handle.
            dwRet=(DWORD)(UINT)hBmp;
            break;


        case PLM_METAFILEGET:
            //Create a memory metafile and return its handle.
            hDC=(HDC)CreateMetaFile(NULL);
            hMF=NULL;

            if (NULL!=hDC)
                {
                /*
                 * This is absolutely essential to the metafile so it
                 * can be scaled in the clipboard and any destination
                 * application.
                 */
                fMetaDC=TRUE;
                SetMapMode(hDC, MM_ANISOTROPIC);
                GetClientRect(hWnd, &rc);
                SetWindowOrgEx(hDC, 0, 0, NULL);
                SetWindowExtEx(hDC, rc.right, rc.bottom, NULL);

                ppl->fDrawEntire=TRUE;
                PolylineDraw(hWnd, hDC, ppl);
                ppl->fDrawEntire=FALSE;

                hMF=CloseMetaFile(hDC);
                fMetaDC=FALSE;
                }

            dwRet=(DWORD)(UINT)hMF;
            break;


        case PLM_METAFILEPICTGET:
            /*
             * Create a METAFILEPICT structure for the clipboard.
             * First attempt to get a metafile.
             */
            lParam=SendMessage(hWnd, PLM_METAFILEGET, 0, 0L);
            hMF=(HMETAFILE)(UINT)lParam;

            if (NULL==hMF)
                break;

            //Allocate the METAFILEPICT structure.
            hMem=GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE
                , sizeof(METAFILEPICT));

            if (NULL==hMem)
                {
                DeleteMetaFile(hMF);
                break;
                }

            /*
             * Global lock only fails in PMODE if the selector is invalid
             * (like it was discarded) or references a 0 length segment,
             * neither of which can happen here.
             */
            pMF=(LPMETAFILEPICT)GlobalLock(hMem);

            pMF->hMF=hMF;
            pMF->mm=MM_ANISOTROPIC;             //Required by OLE libraries.

            //Insert the extents in MM_HIMETRIC units.
            GetClientRect(hWnd, &rc);

            RectConvertToHiMetric(hWnd, &rc);     //Found in CLIP.C
            pMF->xExt=rc.right;
            pMF->yExt=rc.bottom;

            GlobalUnlock(hMem);

            dwRet=(DWORD)(UINT)hMem;
            break;


        default:
            break;
        }

    return dwRet;
    }






/*
 * PolylineDraw
 *
 * Purpose:
 *  Paints the current line in the polyline window.
 *
 * Parameters:
 *  hWnd            HWND of the polyline window.
 *  hDC             HDC to draw on, could be a metafile or printer DC.
 *  ppl            LPPOLYLINE to the polyline structure.
 *
 * Return Value:
 *  none
 */

void PASCAL PolylineDraw(HWND hWnd, HDC hDC, LPPOLYLINE ppl)
    {

    HBRUSH          hBrush, hBrushT;
    HPEN            hPen, hPenT;
    UINT            i, j;
    UINT            nMM;
    POINTS          pt;
    POINT           rgpt[CPOLYLINEPOINTS];
    RECT            rc;
    COLORREF        cr;


    GetClientRect(hWnd, &rc);

    //Get the line color.
    cr=GetSysColor(COLOR_WINDOWTEXT);

    //Make a 32-bit working copy of the point array for DPtoLP.
    for (i=0; i < ppl->cPoints; i++)
        {
        rgpt[i].x=ppl->rgpt[i].x;
        rgpt[i].y=ppl->rgpt[i].y;
        }

    /*
     * If the mapping mode is not MM_TEXT, convert the points to
     * whatever mapping mode in in effect before drawing.
     * This specifically supports metafiles in MM_ANISOTROPIC.
     */
    nMM=fMetaDC ? MM_TEXT : GetMapMode(hDC);

    if (MM_TEXT!=nMM)
        DPtoLP(hDC, rgpt, ppl->cPoints);

    hPen=CreatePen(PS_SOLID, 1, cr);
    hPenT=SelectObject(hDC, hPen);

    hBrush=CreateSolidBrush(GetSysColor(COLOR_WINDOW));
    hBrushT=SelectObject(hDC, hBrush);

    /*
     * Either draw the entire figure or just a single point.  The
     * entire figure also includes erasing the background completely,
     * since hDC may be a metafile DC.  Drawing a single point just
     * updates the figure for that new point.
     */
    if (ppl->fDrawEntire)
        {
        //Erase the background for bitmaps and metafiles.
        SelectObject(hDC, GetStockObject(NULL_PEN));
        Rectangle(hDC, rc.left, rc.top, rc.right+1, rc.bottom+1);
        SelectObject(hDC, hPen);


        /*
         * If we are drawing the entire figure, then loop through each
         * point drawing a line to each successive point.
         */

        for (i=0; i < ppl->cPoints; i++)
            {
            for (j=i; j < ppl->cPoints; j++)
                {
                MoveToEx(hDC, rgpt[i].x, rgpt[i].y, NULL);
                LineTo(hDC, rgpt[j].x, rgpt[j].y);
                }
            }
        }
    else
        {
        /*
         * If we are only drawing the last point, just cycle once
         * through previous points.
         */

        //Get the last point entered in the array.
        j=ppl->cPoints-1;
        pt.x=(short)rgpt[j].x;
        pt.y=(short)rgpt[j].y;

        for (i=0; i < j; i++)
            {
            MoveToEx(hDC, pt.x, pt.y, NULL);
            LineTo(hDC, rgpt[i].x, rgpt[i].y);
            }
        }

    //If we only had one point, draw a dot to indicate it's position.
    if (1==ppl->cPoints)
        SetPixel(hDC, rgpt[0].x, rgpt[0].y, cr);


    SelectObject(hDC, hPenT);
    SelectObject(hDC, hBrushT);
    DeleteObject(hBrush);
    DeleteObject(hPen);
    return;
    }

⌨️ 快捷键说明

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