📄 polyline.cpp
字号:
*
* Parameters:
* pRect LPRECT in which to return the size. The right
* and bottom fields will contain the dimensions.
*
* Return Value:
* None
*/
void CPolyline::SizeGet(LPRECT pRect)
{
RectGet(pRect);
return;
}
/*
* CPolyline::RectSet
*
* Purpose:
* Sets a new rectangle for the Polyline which sizes to fit.
*
* Parameters:
* pRect LPRECT containing the new rectangle.
* fNotify BOOL indicating if we're to notify anyone of
* the change.
*
* Return Value:
* None
*/
void CPolyline::RectSet(LPRECT pRect, BOOL fNotify)
{
UINT cx, cy;
RECT rc;
//Scale the points from our current size to the new size
cx=pRect->right-pRect->left;
cy=pRect->bottom-pRect->top;
SetWindowPos(m_hWnd, NULL, pRect->left, pRect->top
, cx, cy, SWP_NOZORDER);
SetRect(&rc, 0, 0, cx, cy);
RECTTORECTS(rc, m_pl.rc);
if (fNotify && NULL!=m_pAdv)
m_pAdv->OnSizeChange();
InvalidateRect(m_hWnd, NULL, TRUE);
return;
}
/*
* CPolyline::SizeSet
*
* Purpose:
* Sets a new size for the Polyline which sizes to fit.
*
* Parameters:
* pRect LPRECT containing the new rectangle.
* fNotify BOOL indicating if we're to notify anyone of
* the change.
*
* Return Value:
* None
*/
void CPolyline::SizeSet(LPRECT pRect, BOOL fNotify)
{
UINT cx, cy;
//Scale the points from our current size to the new size
cx=pRect->right-pRect->left;
cy=pRect->bottom-pRect->top;
SetWindowPos(m_hWnd, NULL, 0, 0, (UINT)cx, (UINT)cy
, SWP_NOMOVE | SWP_NOZORDER);
if (fNotify && NULL!=m_pAdv)
m_pAdv->OnSizeChange();
InvalidateRect(m_hWnd, NULL, TRUE);
return;
}
/*
* CPolyline::ColorSet
*
* Purpose:
* Changes for background or line color in the Polyline
*
* Parameters:
* iColor UINT index of the color to change.
* cr COLORREF new color to use.
*
* Return Value:
* COLORREF Previous color for the index iColor.
*/
COLORREF CPolyline::ColorSet(UINT iColor, COLORREF cr)
{
COLORREF crRet;
switch (iColor)
{
case POLYLINECOLOR_BACKGROUND:
crRet=m_pl.rgbBackground;
m_pl.rgbBackground=cr;
break;
case POLYLINECOLOR_LINE:
crRet=m_pl.rgbLine;
m_pl.rgbLine=cr;
break;
}
//If the color changed, repaint
if (crRet!=cr)
{
if (NULL!=m_pAdv)
m_pAdv->OnColorChange();
InvalidateRect(m_hWnd, NULL, TRUE);
UpdateWindow(m_hWnd);
}
return crRet;
}
/*
* CPolyline::ColorGet
*
* Purpose:
* Retrieves one of the colors currently in use by the Polyline.
*
* Parameters:
* iColor UINT identifying the color of interest.
*
* Return Value:
* COLORREF Current color for iColor.
*/
COLORREF CPolyline::ColorGet(UINT iColor)
{
COLORREF crRet;
crRet=(POLYLINECOLOR_BACKGROUND==iColor)
? m_pl.rgbBackground : m_pl.rgbLine;
return crRet;
}
/*
* CPolyline::LineStyleSet
*
* Purpose:
* Changes the line style in use by the Polyline
*
* Parameters:
* iStyle UINT style of the line to use.
*
* Return Value:
* UINT Previous style.
*/
UINT CPolyline::LineStyleSet(UINT iStyle)
{
UINT uRet=(UINT)m_pl.iLineStyle;
//Validate the line style
if (PS_SOLID==iStyle || PS_DASH==iStyle || PS_DOT==iStyle
|| PS_DASHDOT==iStyle || PS_DASHDOTDOT==iStyle)
{
m_pl.iLineStyle=iStyle;
if (uRet!=(UINT)m_pl.iLineStyle)
{
if (NULL!=m_pAdv)
m_pAdv->OnLineStyleChange();
InvalidateRect(m_hWnd, NULL, TRUE);
UpdateWindow(m_hWnd);
}
}
return uRet;
}
/*
* CPolyline::LineStyleGet
*
* Purpose:
* Retrieves the current line style in use in the Polyline
*
* Parameters:
* None
*
* Return Value:
* UINT Current line style.
*/
UINT CPolyline::LineStyleGet(void)
{
return m_pl.iLineStyle;
}
/*
* CPolyline::RenderBitmap
*
* Purpose:
* Creates a bitmap image of the current Polyline.
*
* Parameters:
* None
*
* Return Value:
* HBITMAP Handle to the newly rendered bitmap.
*/
HBITMAP CPolyline::RenderBitmap(void)
{
HDC hDC;
HDC hMemDC;
HBITMAP hBmp;
RECT rc;
HGDIOBJ hObj;
//Render a bitmap the size of the current rectangle.
hDC=GetDC(m_hWnd);
hMemDC=CreateCompatibleDC(hDC);
GetClientRect(m_hWnd, &rc);
hBmp=CreateCompatibleBitmap(hDC, rc.right, rc.bottom);
if (NULL!=hBmp)
{
//Draw the POLYLINEDATA into the bitmap.
hObj=SelectObject(hMemDC, hBmp);
Draw(hMemDC, FALSE, TRUE);
SelectObject(hMemDC, hObj);
}
DeleteDC(hMemDC);
ReleaseDC(m_hWnd, hDC);
return hBmp;
}
/*
* CPolyline::RenderMetafile
*
* Purpose:
* Renders the current image of the Polyline into a metafile.
*
* Parameters:
* None
*
* Return Value:
* HMETAFILE Handle to the newly created metafile.
*/
HMETAFILE CPolyline::RenderMetafile(void)
{
HDC hDC;
HMETAFILE hMF;
RECT rc;
//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.
*/
SetMapMode(hDC, MM_ANISOTROPIC);
GetClientRect(m_hWnd, &rc);
SetWindowOrgEx(hDC, 0, 0, NULL);
SetWindowExtEx(hDC, rc.right, rc.bottom, NULL);
Draw(hDC, TRUE, TRUE);
hMF=CloseMetaFile(hDC);
}
return hMF;
}
/*
* CPolyline::RenderMetafilePict
*
* Purpose:
* Renders the current Polyline into a METAFILEPICT structure in
* global memory.
*
* Parameters:
* None
*
* Return Value:
* HGLOBAL Memory containing the METAFILEPICT structure.
*/
HGLOBAL CPolyline::RenderMetafilePict(void)
{
HGLOBAL hMem;
HMETAFILE hMF;
LPMETAFILEPICT pMF;
RECT rc;
//Get the metafile
hMF=RenderMetafile();
if (NULL==hMF)
return NULL;
//Allocate the METAFILEPICT structure.
hMem=GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE
, sizeof(METAFILEPICT));
if (NULL==hMem)
{
DeleteMetaFile(hMF);
return NULL;
}
/*
* 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;
//Insert the extents in MM_HIMETRIC units.
GetClientRect(m_hWnd, &rc);
RectConvertMappings(&rc, FALSE);
pMF->xExt=rc.right;
pMF->yExt=rc.bottom;
GlobalUnlock(hMem);
return hMem;
}
/*
* CPolyline::RectConvertMappings
*
* Purpose:
* Converts the contents of a rectangle from device (MM_TEXT) or
* HIMETRIC to the other.
*
* Parameters:
* pRect LPRECT containing the rectangle to convert.
* fToDevice BOOL TRUE to convert from HIMETRIC to device,
* FALSE to convert device to HIMETRIC.
*
* Return Value:
* None
*/
void CPolyline::RectConvertMappings(LPRECT pRect, BOOL fToDevice)
{
HDC hDC;
int iLpx, iLpy;
if (NULL==pRect)
return;
hDC=GetDC(NULL);
iLpx=GetDeviceCaps(hDC, LOGPIXELSX);
iLpy=GetDeviceCaps(hDC, LOGPIXELSY);
ReleaseDC(NULL, hDC);
if (fToDevice)
{
pRect->left=MulDiv(iLpx, pRect->left, HIMETRIC_PER_INCH);
pRect->top =MulDiv(iLpy, pRect->top , HIMETRIC_PER_INCH);
pRect->right=MulDiv(iLpx, pRect->right, HIMETRIC_PER_INCH);
pRect->bottom=MulDiv(iLpy, pRect->bottom,HIMETRIC_PER_INCH);
#ifdef NEVER
/*
* In this conversion we may get situations where the top
* coordinate is larger than the bottom, which messes us up.
*/
if (pRect->bottom < pRect->top)
{
iLpy=pRect->top;
pRect->top=pRect->bottom;
pRect->bottom=iLpy;
}
#endif
}
else
{
pRect->left=MulDiv(pRect->left, HIMETRIC_PER_INCH, iLpx);
pRect->top =MulDiv(pRect->top , HIMETRIC_PER_INCH, iLpy);
pRect->right =MulDiv(pRect->right, HIMETRIC_PER_INCH, iLpx);
pRect->bottom=MulDiv(pRect->bottom,HIMETRIC_PER_INCH, iLpy);
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -