📄 scemfaxctl.cpp
字号:
//PX_UShort(pPX, SC_T_PixelOffsetMode, m_usPixelOffsetMode, SC_AXDFLT_PIXELOFFSETMODE);
SCPX_USHORT(m_usPixelOffsetMode, PixelOffsetMode)
SC_END_PROPEX()
// if (READYSTATE_LOADING==m_lReadyState)
// InternalSetReadyState(READYSTATE_INTERACTIVE);
// PX_DataPath(pPX, SC_T_Src, m_Data);
}
/////////////////////////////////////////////////////////////////////////////
// CSCEMFAxCtrl::OnResetState - Reset control to default state
void CSCEMFAxCtrl::OnResetState()
{
m_Data.ResetData();
COleControl::OnResetState(); // Resets defaults found in DoPropExchange
// Reset any other control state here.
SCCopyStateToControl();
}
/////////////////////////////////////////////////////////////////////////////
// CSCEMFAxCtrl::AboutBox - Display an "About" box to the user
void CSCEMFAxCtrl::AboutBox()
{
CDialog dlgAbout(IDD_ABOUTBOX_SCEMFAX);
dlgAbout.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CSCEMFAxCtrl message handlers
void CSCEMFAxCtrl::InformDlStatus(CSCEMFDataPathProperty::DLState dlState)
{
HEMFVECTOR vectHandles;
HENHMETAFILE hEMF = m_Data.SCDetachEMF();
if (hEMF)
{
vectHandles.push_back(hEMF);
m_EMFDoc.SCCleanup();
m_EMFDoc.SCPasteEMFPages(vectHandles);
if (::IsWindow(m_CtlImage.m_hWnd))
{
m_CtlImage.SCGotoFirstPage();
if (SC_FIT_NONE!=m_usFitMode)
m_fScale = m_CtlImage.SCGetScale();
}
}
if (m_hWnd)
Invalidate(FALSE);
if (dlState == CSCEMFDataPathProperty::DLState::dlDone)
{
InternalSetReadyState(READYSTATE_COMPLETE);
} else
{
InternalSetReadyState(READYSTATE_INTERACTIVE);
}
}
BOOL CSCEMFAxCtrl::PreCreateWindow(CREATESTRUCT& cs)
{
// Add your specialized code here and/or call the base class
cs.style &= ~(WS_HSCROLL|WS_VSCROLL);
return COleControl::PreCreateWindow(cs);
}
BOOL CSCEMFAxCtrl::IsSubclassedControl()
{
return FALSE;
}
LRESULT CSCEMFAxCtrl::OnOcmCommand(WPARAM wParam, LPARAM lParam)
{
#ifdef _WIN32
WORD wNotifyCode = HIWORD(wParam);
#else
WORD wNotifyCode = HIWORD(lParam);
#endif
// TODO: Switch on wNotifyCode here.
return 0;
}
//////////////////////////////////////////////////////////////////////////////////
// Creation/background events
//
int CSCEMFAxCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (COleControl::OnCreate(lpCreateStruct) == -1)
return -1;
// create controls
DWORD dwStyle = WS_CHILD|WS_VISIBLE|/*WS_BORDER|*/WS_CLIPCHILDREN;
if (!m_CtlImage.Create(NULL, _T("EMFCtlImageAx"),
dwStyle,
CRect(10,10,150,50), this, IDC_WND_EMFIMG))
{
SC_SHOW_AXMSG("Could not create EMFCtlImageAx image control");
return -1;
}
// control border
m_CtlImage.SCSetCtlBorder(m_usCtlBorder);
// control color
if (SC_COLOR_TRANSPARENT==m_usCtlColorStyle)
{
m_crCtlColor = AmbientBackColor();
if (SC_IS_SYSCOLOR(m_crCtlColor))
m_crCtlColor = GetSysColor(SC_SYSCOLOR_INDEX(m_crCtlColor));
m_CtlImage.SCSetCtlColorStyle(m_usCtlColorStyle, m_crCtlColor);
}
// Contextual menu
m_CtlImage.SCSetCtlOwner(this);
CMenu menu;
if (menu.LoadMenu(IDR_CTX_MENU))
{
CMenu *pSubMenu = menu.GetSubMenu(MNU_IDX_TRACKPOPUP1);
if (pSubMenu)
{
m_CtlImage.SCSetCtxMenu(pSubMenu->m_hMenu);
}
m_hPopupMenu = menu.Detach();
}
return 0;
}
BOOL CSCEMFAxCtrl::OnEraseBkgnd(CDC* pDC)
{
return TRUE; // do not erase
//return COleControl::OnEraseBkgnd(pDC);
}
void CSCEMFAxCtrl::OnSize(UINT nType, int cx, int cy)
{
COleControl::OnSize(nType, cx, cy);
if (!::IsWindow(m_CtlImage.m_hWnd))
return;
m_CtlImage.MoveWindow(0, 0, cx, cy);
if (0==m_CtlImage.SCGetCurPage() && m_CtlImage.SCGetNumPages())
{// Load image and update image-dependent properties
m_CtlImage.SCGotoFirstPage();
if (SC_FIT_NONE!=m_usFitMode)
m_fScale = m_CtlImage.SCGetScale();
}
}
/////////////////////////////////////////////////////////////////////////////
// I_EMFImageOwner
void CSCEMFAxCtrl::SCSetupCtxMenu(CMenu* pMenu)
{
ASSERT(pMenu);
if (!pMenu)
return;
UINT nCheck = (m_CtlImage.SCGetReverseVideo()) ? MF_CHECKED : MF_UNCHECKED;
pMenu->CheckMenuItem(ID_TBDOC_REVERSE_VIDEO, MF_BYCOMMAND|nCheck);
nCheck = (SC_ENGINE_GDIP==m_CtlImage.SCGetRasEngine()) ? MF_CHECKED : MF_UNCHECKED;
pMenu->CheckMenuItem(ID_TBDOC_USEGDIP, MF_BYCOMMAND|nCheck);
}
CWnd* CSCEMFAxCtrl::SCGetMenuOwner()
{
#if 0
// Does'nt work.
// I would like to have menu messages appearing in the
// container's status bar
HWND hwndParent = MSGetActualParent();
if (hwndParent)
return CWnd::FromHandle(hwndParent);
#endif
return NULL;
}
void CSCEMFAxCtrl::SCOnCtxCommand(WPARAM wParam, LPARAM lParam)
{
switch (GET_WM_COMMAND_ID(wParam, lParam))
{
case ID_FILE_SAVE_AS:
SCFileSaveAs();
break;
case ID_TBDOC_BKCOLOR:
{
PreModalDialog();
CColorDialog dlgColor;
if (IDOK == dlgColor.DoModal())
{// Note: the dialog returns RGB. So we must update color style accordingly.
m_usPaperColorStyle = SC_COLOR_RGBVALUE;
m_crPaperColor = (OLE_COLOR)dlgColor.GetColor();
m_CtlImage.SCSetPaperColorStyle(m_usPaperColorStyle, m_crPaperColor);
SetModifiedFlag();
}
PostModalDialog();
}
break;
case ID_TBDOC_USEGDIP:
m_CtlImage.SCEnableGDIp(!m_CtlImage.SCGetGDIplusEnabled());
SetModifiedFlag();
break;
case ID_TBDOC_REVERSE_VIDEO:
SetReverseVideoMode((SC_REVERSE_VIDEO_NONE==m_usReverseVideoMode)?
SC_REVERSE_VIDEO_FULL :
SC_REVERSE_VIDEO_NONE);
SetModifiedFlag();
break;
case ID_TOOLS_OPTIONS:
SCShowProperties();
break;
default:
SC_SHOW_AXMSG1("Unknown command :%d", GET_WM_COMMAND_ID(wParam, lParam))
break;
}
}
#ifdef SC_FILTERING_PPAGES
// Filtering pages to display
HRESULT CSCEMFAxCtrl::SCGetPropPages(CAUUID *pPPages)
{
ASSERT(pPPages);
#define CPROPPAGES 3
pPPages->cElems = 0;
pPPages->pElems = NULL;
GUID *pGUID = (GUID*)CoTaskMemAlloc(CPROPPAGES * sizeof(GUID));
if (NULL == pGUID)
return ResultFromScode(E_OUTOFMEMORY);
// Fill the array of property pages now
pGUID[0] = CSCEMFAxPropPage::guid;
pGUID[1] = CSCEMFAxGDIpPropPage::guid;
pGUID[2] = CSCEMFAxColorsPropPage::guid;
//Fill the structure and return
pPPages->cElems = CPROPPAGES;
pPPages->pElems = pGUID;
return NOERROR;
}
#endif
void CSCEMFAxCtrl::SCShowProperties()
{
#ifndef SC_FILTERING_PPAGES
// Control location
HWND hWndParent = MSGetActualParent();
if (!hWndParent)
{
hWndParent = m_hWnd;
}
CRect rcBounds;
if (!GetRectInContainer(&rcBounds))
{
GetClientRect(&rcBounds);
::MapWindowPoints(m_hWnd, hWndParent, (LPPOINT)&rcBounds, 2);
}
// Conctruct fake message
MSG msg;
msg.hwnd = m_CtlImage.m_hWnd;
msg.pt.x = (rcBounds.left + rcBounds.right)/2;
msg.pt.y = (rcBounds.top + rcBounds.bottom)/2;
msg.lParam = MAKELPARAM(msg.pt.x, msg.pt.y);
msg.wParam = 0;
msg.message = WM_RBUTTONUP;
msg.time = GetMessageTime(); // of last message
// Ask for our declared property pages
OnProperties(&msg, hWndParent, &rcBounds);
#else
CAUUID cauuids;
if (FAILED(SCGetPropPages(&cauuids)))
{
SC_SHOW_AXMSG("Could not get property pages array.");
return;
}
LPDISPATCH pIDispatch = GetIDispatch(TRUE); // cmdtarget will addref
LCID lcid = 0; // AmbientLocaleID();
CSCEMFAxPropSheet dlgProps(IDS_SCEMFAX, this, lcid);
PreModalDialog(); // doesn't work !? (dialog behaves like modeless)
if (IDOK == dlgProps.SCDoModal(10, 10, pIDispatch, &cauuids, lcid))
{
}
PostModalDialog();
// Clean up
pIDispatch->Release();
CoTaskMemFree((void*)cauuids.pElems);
#endif
}
//////////////////////////////////////////////////////////////////////////////////
// Command handlers
//
void CSCEMFAxCtrl::SCFileSaveAs(BOOL bSaveAll/*=FALSE*/)
{
CString sFilters(SC_EMFMODE_FILTERS_IMG);
CFileDialog dlg(FALSE, NULL, _T("*.emf"),
OFN_HIDEREADONLY|OFN_PATHMUSTEXIST|OFN_OVERWRITEPROMPT,
(LPCTSTR)sFilters);
PreModalDialog();
if (IDOK == dlg.DoModal())
{
CString strPath = dlg.GetPathName();
SCAddPathExtFromFilterIndex(strPath, sFilters, dlg.m_ofn.nFilterIndex);
int iType = SCFileTypeFromFilterIndexImg(dlg.m_ofn.nFilterIndex);
ASSERT(iType != SC_FTYPE_UKN);
m_CtlImage.SCSaveDocument(LPCTSTR(strPath), iType, bSaveAll);
}
PostModalDialog();
}
// (c) Microsoft
// The following code should return the
// actual parent window of the ActiveX control.
HWND CSCEMFAxCtrl::MSGetActualParent()
{
HWND hwndParent = 0;
// Get the window associated with the in-place site object,
// which is connected to this ActiveX control.
if (m_pInPlaceSite != NULL)
m_pInPlaceSite->GetWindow(&hwndParent);
return hwndParent; // Return the in-place site window handle.
}
//
//////////////////////////////////////////////////////////////////////////////////
// Property handlers
//
/// Picture
BSTR CSCEMFAxCtrl::Get_Picture()
{
CString strResult;
// property handler here
strResult = m_Data.GetPath();
return strResult.AllocSysString();
}
void CSCEMFAxCtrl::Set_Picture(LPCTSTR lpszNewValue)
{
InternalSetReadyState(READYSTATE_INTERACTIVE);
// property handler here
Load(lpszNewValue, m_Data);
SetModifiedFlag();
}
/// Control border
short CSCEMFAxCtrl::GetCtlBorder()
{
return m_usCtlBorder;
}
void CSCEMFAxCtrl::SetCtlBorder(short nNewValue)
{
m_CtlImage.SCSetCtlBorder(m_usCtlBorder = nNewValue);
SetModifiedFlag();
}
// Control color style
short CSCEMFAxCtrl::GetCtlColorStyle()
{
return m_usCtlColorStyle;
}
void CSCEMFAxCtrl::SetCtlColorStyle(short nNewValue)
{
// TODO: if (failed) SC_SHOW_AXMSG1("Bad SetCtlColorStyle:%d", nNewValue)
if (SC_COLOR_TRANSPARENT==nNewValue)
m_crCtlColor = AmbientBackColor();
m_CtlImage.SCSetCtlColorStyle(m_usCtlColorStyle = nNewValue, m_crCtlColor);
SetModifiedFlag();
}
// Control color
OLE_COLOR CSCEMFAxCtrl::GetCtlColor()
{
return m_crCtlColor;
}
void CSCEMFAxCtrl::SetCtlColor(OLE_COLOR nNewValue)
{
// TODO: if (failed) return
m_CtlImage.SCSetCtlColor(m_crCtlColor = nNewValue);
SetModifiedFlag();
}
/// Page (Picture) border
BOOL CSCEMFAxCtrl::GetPageBorderVisible()
{
return m_bPageBorderVisible;
}
void CSCEMFAxCtrl::SetPageBorderVisible(BOOL bNewValue)
{
m_CtlImage.SCSetPageBorderVisible(m_bPageBorderVisible = bNewValue);
SetModifiedFlag();
}
// Page (Picture) shadow
BOOL CSCEMFAxCtrl::GetPageShadowVisible()
{
return m_bPageShadowVisible;
}
void CSCEMFAxCtrl::SetPageShadowVisible(BOOL bNewValue)
{
m_CtlImage.SCSetPageShadowVisible(m_bPageShadowVisible = bNewValue);
SetModifiedFlag();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -