📄 polywin.cpp
字号:
void CPolyline::PointScale(LPRECT pRect, LPPOINTS ppt
, BOOL fScaleToWindow)
{
DWORD cx, cy;
//Window size
cx=(DWORD)(pRect->right-pRect->left);
cy=(DWORD)(pRect->bottom-pRect->top);
//Prevent crashes
if (0L==cx) cx=1;
if (0L==cy) cy=1;
//Must use DWORD to insure proper scaling.
/*
* As an in-proc server we may not have a rectangle where the
* top left was (0,0) which was always true when we drew to
* a Polyline window. But this may be a container's hDC in
* which case we'd better place the points in the container's
* rectangle. That is, we have to add/subtract pRect->left
* and ->top in these calculations.
*/
if (fScaleToWindow)
{
ppt->x=pRect->left+(UINT)(((DWORD)ppt->x*cx) >> 15);
ppt->y=pRect->top+(UINT)(((DWORD)ppt->y*cy) >> 15);
}
else
{
ppt->x=(UINT)(((DWORD)(ppt->x - pRect->left) << 15)/cx);
ppt->y=(UINT)(((DWORD)(ppt->y - pRect->top) << 15)/cy);
}
return;
}
/*
* PolyDlgProc
*
* Purpose:
* Dialog procedure for a window in which to display the Polyline
* for editing. This pretty much handles all editing functionality
* for the embedded object.
*/
BOOL APIENTRY PolyDlgProc(HWND hDlg, UINT iMsg
, WPARAM wParam, LPARAM lParam)
{
PCPolyline ppl=NULL;
RECT rc;
UINT uID, uTemp;
UINT cx, cy;
#ifdef WIN32
ppl=(PCPolyline)GetProp(hDlg, PROP_POINTER);
#else
WORD w1, w2;
w1=(WORD)GetProp(hDlg, PROP_SELECTOR);
w2=(WORD)GetProp(hDlg, PROP_OFFSET);
ppl=(PCPolyline)MAKELP(w1, w2);
#endif
switch (iMsg)
{
case WM_INITDIALOG:
ppl=(PCPolyline)lParam;
ppl->m_hDlg=hDlg;
#ifdef WIN32
//Properties are 32-bits in Win32
SetProp(hDlg, PROP_POINTER, (HANDLE)ppl);
#else
SetProp(hDlg, PROP_SELECTOR, (HANDLE)SELECTOROF(ppl));
SetProp(hDlg, PROP_OFFSET, (HANDLE)OFFSETOF(ppl));
#endif
//Get the rectangle that Polyline occupies
CalcPolyRectInDialog(hDlg, &rc);
//Try to create the window.
ppl->m_pImpIPolyline->Init(hDlg, &rc, WS_CHILD | WS_VISIBLE
, ID_POLYLINE);
//Set the initial line style radiobutton.
ppl->m_pImpIPolyline->LineStyleGet(&uTemp);
CheckRadioButton(hDlg, ID_LINESOLID, ID_LINEDASHDOTDOT
, uTemp+ID_LINEMIN);
return FALSE;
case WM_SHOWWINDOW:
if (LOWORD(wParam))
{
//Center the dialog on the screen
cx=GetSystemMetrics(SM_CXSCREEN);
cy=GetSystemMetrics(SM_CYSCREEN);
GetWindowRect(hDlg, &rc);
SetWindowPos(hDlg, NULL, (cx-(rc.right-rc.left))/2
, (cy-(rc.bottom-rc.top))/2, 0, 0, SWP_NOZORDER
| SWP_NOSIZE);
//We didn't SetFocus from WM_INITDIALOG. Do it now.
SetFocus(GetDlgItem(hDlg, IDOK));
}
break;
case WM_COMMAND:
uID=LOWORD(wParam);
switch (uID)
{
case IDOK:
//Close the dialog, but save first.
if (NULL!=ppl)
{
HRESULT hr;
/*
* Instead of just closing, see if we can
* activate in-place again--we know we're an
* inside out object and want to be activated
* when we can be. If we can't activate
* in-place, then close like we normally
* would. Note that this makes sense only
* with an inside-out supporting container,
* which we determine from whether it ever
* used OLEIVERB_INPLACEACTIVATE.
*/
hr=ResultFromScode(E_FAIL);
if (ppl->m_fContainerKnowsInsideOut)
{
hr=ppl->InPlaceActivate
(ppl->m_pIOleClientSite, FALSE);
}
if (FAILED(hr))
{
ppl->m_pImpIOleObject->Close
(OLECLOSE_SAVEIFDIRTY);
}
}
break;
case ID_UNDO:
if (NULL!=ppl)
ppl->m_pImpIPolyline->Undo();
break;
case ID_COLORLINE:
case ID_COLORBACK:
if (NULL!=ppl)
{
UINT i;
COLORREF rgColors[16];
CHOOSECOLOR cc;
//Invoke the color chooser for either color
uTemp=(ID_COLORBACK==uID)
? POLYLINECOLOR_BACKGROUND
: POLYLINECOLOR_LINE;
for (i=0; i<16; i++)
rgColors[i]=RGB(0, 0, i*16);
memset(&cc, 0, sizeof(CHOOSECOLOR));
cc.lStructSize=sizeof(CHOOSECOLOR);
cc.lpCustColors=rgColors;
cc.hwndOwner=hDlg;
cc.Flags=CC_RGBINIT;
ppl->m_pImpIPolyline->ColorGet(uTemp
, &cc.rgbResult);
if (ChooseColor(&cc))
{
//rgColor is just some COLORREF pointer
ppl->m_pImpIPolyline->ColorSet(uTemp
, cc.rgbResult, rgColors);
}
}
break;
case ID_LINESOLID:
case ID_LINEDASH:
case ID_LINEDOT:
case ID_LINEDASHDOT:
case ID_LINEDASHDOTDOT:
if (NULL!=ppl)
{
ppl->m_pImpIPolyline
->LineStyleSet(uID-ID_LINEMIN, &uTemp);
}
break;
}
break;
case WM_DESTROY:
#ifdef WIN32
RemoveProp(hDlg, PROP_POINTER);
#else
RemoveProp(hDlg, PROP_SELECTOR);
RemoveProp(hDlg, PROP_OFFSET);
#endif
break;
case WM_CLOSE:
//This will do the IDOK handling, then send POLYM_CLOSE
SendCommand(hDlg, IDOK, 0, NULL);
break;
case POLYM_CLOSE:
ShowWindow(hDlg, SW_HIDE);
ppl->SendAdvise(OBJECTCODE_HIDEWINDOW);
break;
}
return FALSE;
}
/*
* CalcPolyRectInDialog
*
* Purpose:
* Calculates the rectangle that the Polyline should occupy in the
* dialog box. This is separated for in-place handling because
* when we open the dialog from an in-place active situation we
* have to move the Polyline window from the container into the
* dialog and position it properly.
*
* Parameters:
* hDlg HWND of the dialog.
* prc LPRECT in which to store the rectangle.
*
* Return Value:
* None
*/
void CalcPolyRectInDialog(HWND hDlg, LPRECT prc)
{
HWND hWnd;
POINT pt;
hWnd=GetDlgItem(hDlg, ID_POLYLINERECT);
GetWindowRect(hWnd, prc);
SETPOINT(pt, prc->left, prc->top);
ScreenToClient(hDlg, &pt);
//Set the polyline just within the black frame
SetRect(prc, pt.x, pt.y, pt.x+(prc->right-prc->left)
, pt.y+(prc->bottom-prc->top));
InflateRect(prc, -1, -1);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -