// VectorView.cpp : implementation of the CVectorView class // #include "stdafx.h" #include "Vector.h" #include "VecDoc.h" #include "VecView.h" #include "MainFrm.h" #include "GroupDlg.h" #include "ConvertDlg.h" #include "PaletteDlg.h" #include "..\..\..\..\include\lvdlgres.h" #include "VDlgHelp.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define FIT_TO_WINDOW FALSE L_VOID ShowLeadError( L_INT, const L_TCHAR *, const L_TCHAR * ); L_INT ShowMessageBox( L_BOOL, L_UINT, const L_TCHAR *, ... ); ///////////////////////////////////////////////////////////////////////////// // CVectorView IMPLEMENT_DYNCREATE(CVectorView, CView) BEGIN_MESSAGE_MAP(CVectorView, CView) //{{AFX_MSG_MAP(CVectorView) ON_COMMAND(ID_TOOLS_ROTATE, OnToolsRotate) ON_COMMAND(ID_TOOLS_SCALE, OnToolsScale) ON_COMMAND(ID_TOOLS_TRANSLATE, OnToolsTranslate) ON_COMMAND(ID_TOOLS_CAMERA, OnToolsCamera) ON_COMMAND(ID_TOOLS_BINDING_BINDVERTICES, OnToolsBindingBindvertices) ON_COMMAND(ID_TOOLS_BINDING_UNBINDVERTICES, OnToolsBindingUnbindvertices) ON_COMMAND(ID_TOOLS_BACKCOLOR, OnToolsBackcolor) ON_COMMAND(ID_TOOLS_VIEWMODE_FIT, OnToolsViewmodeFit) ON_COMMAND(ID_TOOLS_VIEWMODE_SNAP, OnToolsViewmodeSnap) ON_UPDATE_COMMAND_UI(ID_TOOLS_BINDING_BINDVERTICES, OnUpdateToolsBindingBindvertices) ON_UPDATE_COMMAND_UI(ID_TOOLS_BINDING_UNBINDVERTICES, OnUpdateToolsBindingUnbindvertices) ON_UPDATE_COMMAND_UI(ID_TOOLS_VIEWMODE_FIT, OnUpdateToolsViewmodeFit) ON_UPDATE_COMMAND_UI(ID_TOOLS_VIEWMODE_SNAP, OnUpdateToolsViewmodeSnap) ON_WM_SIZE() ON_WM_CREATE() ON_WM_TIMER() ON_COMMAND(ID_EDIT_SELECTALL, OnEditSelectall) ON_COMMAND(ID_EDIT_UNSELECTALL, OnEditUnselectall) ON_COMMAND(ID_EDIT_DELETE, OnEditDelete) ON_COMMAND(ID_TOOL_NONE, OnToolNone) ON_COMMAND(ID_TOOL_PANIMAGE, OnToolPanimage) ON_COMMAND(ID_TOOL_SELECT, OnToolSelect) ON_UPDATE_COMMAND_UI(ID_TOOL_NONE, OnUpdateToolNone) ON_UPDATE_COMMAND_UI(ID_TOOL_PANIMAGE, OnUpdateToolPanimage) ON_UPDATE_COMMAND_UI(ID_TOOL_SELECT, OnUpdateToolSelect) ON_COMMAND(ID_TOOL_ROTATE, OnToolRotate) ON_UPDATE_COMMAND_UI(ID_TOOL_ROTATE, OnUpdateToolRotate) ON_COMMAND(ID_PREFERENCES_ENABLESCROLLBARS, OnPreferencesEnablescrollbars) ON_UPDATE_COMMAND_UI(ID_PREFERENCES_ENABLESCROLLBARS, OnUpdatePreferencesEnablescrollbars) ON_COMMAND(ID_LAYER_EDIT, OnLayerEdit) ON_COMMAND(ID_OBJECT_PROPERTIES, OnObjectProperties) ON_UPDATE_COMMAND_UI(ID_OBJECT_PROPERTIES, OnUpdateObjectProperties) ON_COMMAND(ID_IMAGE_MODE, OnImageMode) ON_COMMAND(ID_IMAGE_RENDER, OnImageRender) ON_COMMAND(ID_IMAGE_HITTEST, OnImageHittest) ON_WM_SETFOCUS() ON_COMMAND(ID_FILE_PRINT, OnFilePrint) ON_COMMAND(ID_EDIT_UNDO, OnEditUndo) ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo) ON_COMMAND(ID_EDIT_REDO, OnEditRedo) ON_UPDATE_COMMAND_UI(ID_EDIT_REDO, OnUpdateEditRedo) ON_COMMAND(ID_EDIT_PASTE_OBJECTS, OnEditPasteObjects) ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE_OBJECTS, OnUpdateEditPasteObjects) ON_COMMAND(ID_EDIT_PASTE_LAYERS, OnEditPasteLayers) ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE_LAYERS, OnUpdateEditPasteLayers) ON_WM_MOUSEACTIVATE() ON_WM_MDIACTIVATE() ON_COMMAND(ID_EDIT_COPY, OnEditCopy) ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy) ON_COMMAND(ID_EDIT_CUT, OnEditCut) ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCut) ON_UPDATE_COMMAND_UI(ID_EDIT_DELETE, OnUpdateEditDelete) ON_COMMAND(ID_IMAGE_EXTENT, OnImageExtent) ON_UPDATE_COMMAND_UI(ID_EDIT_UNSELECTALL, OnUpdateEditUnselectall) ON_UPDATE_COMMAND_UI(ID_EDIT_SELECTALL, OnUpdateEditSelectall) ON_COMMAND(ID_OBJECT_EDIT, OnObjectEdit) ON_UPDATE_COMMAND_UI(ID_OBJECT_EDIT, OnUpdateObjectEdit) ON_COMMAND(ID_OBJECT_EXPLODE, OnObjectExplode) ON_UPDATE_COMMAND_UI(ID_OBJECT_EXPLODE, OnUpdateObjectExplode) ON_COMMAND(ID_GROUP_EDIT, OnGroupEdit) ON_COMMAND(ID_GROUP_ADDSELECTEDOBJECTTO, OnGroupAddselectedobjectto) ON_UPDATE_COMMAND_UI(ID_GROUP_ADDSELECTEDOBJECTTO, OnUpdateGroupAddselectedobjectto) ON_UPDATE_COMMAND_UI(ID_LAYER_EDIT, OnUpdateLayerEdit) ON_UPDATE_COMMAND_UI(ID_GROUP_EDIT, OnUpdateGroupEdit) ON_COMMAND(ID_FILE_CONVERTFILE_EMF, OnFileConvertfileEmf) ON_COMMAND(ID_FILE_CONVERTFILE_WMF, OnFileConvertfileWmf) ON_COMMAND(ID_PREFERENCES_INVERTCOLORS, OnPreferencesInvertcolors) ON_COMMAND(ID_PREFERENCES_USEPALETTE, OnPreferencesUsepalette) ON_WM_KEYDOWN() //}}AFX_MSG_MAP ON_MESSAGE(WM_HANDLEPALETTE,OnHandlePalette) ON_COMMAND_RANGE(ID_OBJECT_NEW_VERTEX, ID_OBJECT_NEW_HPOLYBEZIER, OnObjectNew) ON_UPDATE_COMMAND_UI_RANGE(ID_OBJECT_NEW_VERTEX, ID_OBJECT_NEW_HPOLYBEZIER , OnUpdateObjectNew) // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) ON_WM_PALETTECHANGED() END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CVectorView construction/destruction CVectorView::CVectorView() { } CVectorView::~CVectorView() { } ///////////////////////////////////////////////////////////////////////////// // CVectorView printing BOOL CVectorView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CVectorView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CVectorView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CVectorView diagnostics #ifdef _DEBUG void CVectorView::AssertValid() const { CView::AssertValid(); } void CVectorView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CVectorDoc* CVectorView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CVectorDoc))); return (CVectorDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CVectorView message handlers void CVectorView::OnToolsRotate() { // TODO: Add your command handler code here CVectorDoc *pDoc; LMyVectorWindow *pVectorWindow; VECTORPOINT rotateAngle; L_BOOL bSelected; pDoc = GetDocument(); pVectorWindow = pDoc->m_pVectorWindow; pVectorWindow->VectorDialog()->EnablePreview(); pVectorWindow->VectorDialog()->EnableAutoProcess(); pVectorWindow->IsObjectSelected(&bSelected); pVectorWindow->VectorDialog()->EnableSelectedOnly(bSelected); pVectorWindow->GetRotation(&rotateAngle); L_INT nRet = pVectorWindow->VectorDialog()->DoModalVectorRotate(m_hWnd, &rotateAngle); if (nRet==SUCCESS) { pDoc->SetModifiedFlag(TRUE); pDoc->UpdateAllViews(NULL); } } void CVectorView::OnToolsScale() { CVectorDoc *pDoc; LMyVectorWindow *pVectorWindow; VECTORPOINT scalePoint; L_BOOL bSelected; pDoc = GetDocument(); pVectorWindow = pDoc->m_pVectorWindow; pVectorWindow->VectorDialog()->EnablePreview(); pVectorWindow->VectorDialog()->EnableAutoProcess(); pVectorWindow->GetScale(&scalePoint); pVectorWindow->IsObjectSelected(&bSelected); pVectorWindow->VectorDialog()->EnableSelectedOnly(bSelected); //pVectorWindow->VectorDialog()->SetScale(&scalePoint); L_INT nRet = pVectorWindow->VectorDialog()->DoModalVectorScale(m_hWnd, &scalePoint); if (nRet==SUCCESS) { pDoc->SetModifiedFlag(TRUE); pDoc->UpdateAllViews(NULL); } } void CVectorView::OnToolsTranslate() { // TODO: Add your command handler code here CVectorDoc *pDoc; LMyVectorWindow *pVectorWindow; VECTORPOINT translatePoint; L_BOOL bSelected; pDoc = GetDocument(); pVectorWindow = pDoc->m_pVectorWindow; pVectorWindow->VectorDialog()->EnablePreview(); pVectorWindow->VectorDialog()->EnableAutoProcess(); pVectorWindow->GetTranslation(&translatePoint); pVectorWindow->IsObjectSelected(&bSelected); pVectorWindow->VectorDialog()->EnableSelectedOnly(bSelected); //pVectorWindow->VectorDialog()->SetTranslation(&translatePoint); L_INT nRet = pVectorWindow->VectorDialog()->DoModalVectorTranslate(m_hWnd, &translatePoint); if (nRet==SUCCESS) { pDoc->SetModifiedFlag(TRUE); pDoc->UpdateAllViews(NULL); } } void CVectorView::OnToolsCamera() { // TODO: Add your command handler code here CVectorDoc *pDoc; LMyVectorWindow *pVectorWindow; pDoc = GetDocument(); pVectorWindow = pDoc->m_pVectorWindow; pVectorWindow->VectorDialog()->EnablePreview(); pVectorWindow->VectorDialog()->EnableAutoProcess(); L_INT nRet = pVectorWindow->VectorDialog()->DoModalVectorCamera(m_hWnd); if (nRet==SUCCESS) { pDoc->SetModifiedFlag(TRUE); pDoc->UpdateAllViews(NULL); } } void CVectorView::OnToolsBindingBindvertices() { // TODO: Add your command handler code here CVectorDoc *pDoc; LMyVectorWindow *pVectorWindow; pDoc = GetDocument(); pVectorWindow = pDoc->m_pVectorWindow; L_INT nRet = pVectorWindow->SetBindVerticesMode(VECTOR_BIND_VERTICES ); if (nRet == SUCCESS) pDoc->m_nBindVerticesMode = VECTOR_BIND_VERTICES; } void CVectorView::OnToolsBindingUnbindvertices() { // TODO: Add your command handler code here CVectorDoc *pDoc; LMyVectorWindow *pVectorWindow; pDoc = GetDocument(); pVectorWindow = pDoc->m_pVectorWindow; L_INT nRet = pVectorWindow->SetBindVerticesMode(VECTOR_UNBIND_VERTICES ); if (nRet == SUCCESS) pDoc->m_nBindVerticesMode = VECTOR_UNBIND_VERTICES; } void CVectorView::OnToolsBackcolor() { // TODO: Add your command handler code here CVectorDoc *pDoc; LMyVectorWindow *pVectorWindow; //CColorDialog ColorDialog; COLORREF BackColor; COLORDLGPARAMS DlgParams; LDialogColor DlgClr; L_INT nRet; pDoc = GetDocument(); pVectorWindow = pDoc->m_pVectorWindow; pVectorWindow->GetBackgroundColor(&BackColor); //CHOOSECOLOR DlgParams.crColor = BackColor; DlgParams.uColorSpace = DLG_COLOR_COLORSPACE_SHOW_RGB; DlgParams.uColorModel = 0; DlgParams.uStructSize = sizeof( COLORDLGPARAMS ); DlgParams.uDlgFlags = (DLG_COLOR_SHOW_OLDCOLOR | DLG_COLOR_SHOW_NEWCOLOR | DLG_COLOR_SHOW_NAME | DLG_COLOR_COLORSPACE_SHOW_HUE | DLG_COLOR_COLORSPACE_SHOW_BRIGHTNESS | DLG_COLOR_COLORSPACE_SHOW_WHEEL | DLG_COLOR_COLORSPACE_SHOW_RGB | DLG_COLOR_COLORSPACE_SHOW_CMY | DLG_COLOR_COLORSPACE_SHOW_CMYK | DLG_COLOR_COLORSPACE_SHOW_LAB | DLG_COLOR_COLORMODEL_SHOW_RGB | DLG_COLOR_COLORMODEL_SHOW_HSB | DLG_COLOR_COLORMODEL_SHOW_HLS | DLG_COLOR_COLORMODEL_SHOW_CMY | DLG_COLOR_COLORMODEL_SHOW_CMYK | DLG_COLOR_COLORMODEL_SHOW_LAB ); DlgClr.SetColorParams (&DlgParams); nRet = DlgClr.DoModalColor (m_hWnd); if(nRet == SUCCESS_DLG_OK) { DlgClr.GetColorParams(&DlgParams,sizeof(COLORDLGPARAMS)); BackColor = DlgParams.crColor ; L_INT nRet = pVectorWindow->SetBackgroundColor(BackColor); if (nRet == SUCCESS) { pDoc->SetModifiedFlag(TRUE); pDoc->UpdateAllViews(NULL); } } } void CVectorView::OnToolsViewmodeFit() { LMyVectorWindow *pVectorWindow; if (GetDocument()->m_nViewMode == VECTOR_VIEWMODE_SNAP) { pVectorWindow = GetDocument()->m_pVectorWindow; L_INT nRet = pVectorWindow->SetViewMode(VECTOR_VIEWMODE_FIT); if (nRet == SUCCESS) { GetDocument()->m_nViewMode = VECTOR_VIEWMODE_FIT; GetDocument()->UpdateAllViews(NULL); } } } void CVectorView::OnToolsViewmodeSnap() { LMyVectorWindow *pVectorWindow; if (GetDocument()->m_nViewMode == VECTOR_VIEWMODE_FIT) { pVectorWindow = GetDocument()->m_pVectorWindow; L_INT nRet = pVectorWindow->SetViewMode(VECTOR_VIEWMODE_SNAP); if (nRet == SUCCESS) { GetDocument()->m_nViewMode = VECTOR_VIEWMODE_SNAP; GetDocument()->UpdateAllViews(NULL); } } } void CVectorView::OnUpdateToolsBindingBindvertices(CCmdUI* pCmdUI) { L_BOOL bChecked = (GetDocument()->m_nBindVerticesMode == VECTOR_BIND_VERTICES); pCmdUI->SetCheck(bChecked); pCmdUI->Enable(!theApp.m_bViewOnly); } void CVectorView::OnUpdateToolsBindingUnbindvertices(CCmdUI* pCmdUI) { L_BOOL bChecked = (GetDocument()->m_nBindVerticesMode == VECTOR_UNBIND_VERTICES); pCmdUI->SetCheck(bChecked); pCmdUI->Enable(!theApp.m_bViewOnly); } void CVectorView::OnUpdateToolsViewmodeFit(CCmdUI* pCmdUI) { L_BOOL bChecked = (GetDocument()->m_nViewMode == VECTOR_VIEWMODE_FIT); pCmdUI->SetCheck(bChecked); } void CVectorView::OnUpdateToolsViewmodeSnap(CCmdUI* pCmdUI) { L_BOOL bChecked = (GetDocument()->m_nViewMode == VECTOR_VIEWMODE_SNAP); pCmdUI->SetCheck(bChecked); } void CVectorView::OnSize(UINT nType, int cx, int cy) { CView::OnSize(nType, cx, cy); CONTAINERMETRICS ContainerMetrics; RECT Rect; SetRect( &Rect, 0, 0, cx, cy ); ContainerMetrics.nSize = sizeof( CONTAINERMETRICS ); ContainerMetrics.dwMask = CMF_LIMITS; CopyRect( &ContainerMetrics.rcLimits, &Rect ); GetDocument()->m_Container.SetMetrics(&ContainerMetrics); //Execute the line below if using LVectorWindow as a control, and you want // the control to fit to the window XXXX if (GetDocument()->m_pVectorWindow->IsControl()) { if (FIT_TO_WINDOW) { GetDocument()->m_pVectorWindow->FitToParent(); } else { //Center the control RECT rect; int iBorder = 0; //border in pixels rect.left = iBorder; rect.top = iBorder; rect.right = cx - iBorder; rect.bottom = cy - iBorder; GetDocument()->m_pVectorWindow->Move(rect, TRUE); } } } int CVectorView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; L_INT nRet = SUCCESS; HWND hWnd =!NULL; L_BOOL bCreateAsControl = ((CMainFrame *)(theApp.GetMainWnd()))->m_bCreateAsControl; //.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.> // // There are two way to use LEAD controls : // 1.As a control: // Enable A and Disable B // 2.As a Window : // Enable B and Disable As // if (!bCreateAsControl) { // A : (LBitmapWindow works as a Window ) hWnd = m_hWnd; nRet = GetDocument()->m_pVectorWindow->SetWndHandle(m_hWnd); } else { // B : (LBitmapWindow works as a Control) //Change the #define FIT_TO_WINDOW to TRUE to make the control fit the window hWnd = GetDocument()->m_pVectorWindow->CreateWnd( m_hWnd,0, WS_VISIBLE|L_BS_PROCESSKEYBOARD, 0,0,300,200); } if(nRet!=SUCCESS||hWnd==NULL) { LBase::DisplayErrorFromList(); return -1; } else { CVectorDoc* pDoc; pDoc = GetDocument(); pDoc->m_pVectorWindow->SetWndHandle(m_hWnd); if (theApp.m_bUseAutomation) { GetDocument()->m_Container.Initialize(); GetDocument()->m_Container.Create(hWnd); theApp.m_Automation.AddContainer( &GetDocument()->m_Container, GetDocument()->m_pVectorWindow->GetHandle() ); theApp.m_Automation.SetActiveContainer(&GetDocument()->m_Container); } } return 0; } void CVectorView::OnTimer(UINT nIDEvent) { /* // TODO: Add your message handler code here and/or call default VECTORPOINT rotation; VECTORPOINT scale; LMyVectorWindow *pVectorWindow; //if( !bAppActive ) return; pVectorWindow = GetDocument()->m_pVectorWindow; pVectorWindow->GetRotation(&rotation); rotation.x += 2.0F; rotation.y += 2.0F; rotation.z += 2.0F; pVectorWindow->GetScale(&scale ); if(GetDocument()->m_bZoomOut ) { scale.x -= 0.01F; GetDocument()->m_bZoomOut = (scale.x >= 0.1F); } else { scale.x += 0.01F; GetDocument()->m_bZoomOut =( scale.x > 1.0F); } scale.y = scale.z = scale.x; L_BOOL bOldAutoPaint = pVectorWindow->EnableAutoPaint(FALSE); pVectorWindow->SetRotation(&rotation, NULL, FALSE ); pVectorWindow->SetScale(&scale, NULL, FALSE ); pVectorWindow->EnableAutoPaint(bOldAutoPaint); */ CView::OnTimer(nIDEvent); } void CVectorView::OnEditSelectall() { if (theApp.m_bUseAutomation) { theApp.m_Automation.Select(AUTOMATION_SELECT_ALL); } else { GetDocument()->m_pVectorWindow->SelectAllObjects(TRUE, NULL ); } } void CVectorView::OnEditUnselectall() { if (theApp.m_bUseAutomation) { theApp.m_Automation.Select(AUTOMATION_SELECT_NONE); } else { GetDocument()->m_pVectorWindow->SelectAllObjects(FALSE, NULL ); } } void CVectorView::OnToolNone() { GetDocument()->m_pVectorWindow->SetToolType(TOOL_VECTOR_USERMODE); } void CVectorView::OnToolPanimage() { GetDocument()->m_pVectorWindow->SetToolType(TOOL_VECTOR_PANIMAGE); } void CVectorView::OnToolSelect() { GetDocument()->m_pVectorWindow->SetToolType(TOOL_VECTOR_SELECT); } void CVectorView::OnUpdateToolNone(CCmdUI* pCmdUI) { if (theApp.m_bUseAutomation) { pCmdUI->Enable(FALSE); } else { pCmdUI->Enable(TRUE); L_UINT uToolType = GetDocument()->m_pVectorWindow->GetToolType(); pCmdUI->SetCheck(uToolType==TOOL_VECTOR_USERMODE); } } void CVectorView::OnUpdateToolPanimage(CCmdUI* pCmdUI) { L_UINT uToolType = GetDocument()->m_pVectorWindow->GetToolType(); L_INT nEngine = GetDocument()->m_pVectorWindow->GetEngine(); L_BOOL bEnable; bEnable = (nEngine == VECTOR_ENGINE_GDI) && (theApp.m_bUseAutomation == FALSE); pCmdUI->Enable(bEnable); pCmdUI->SetCheck(uToolType==TOOL_VECTOR_PANIMAGE); } void CVectorView::OnUpdateToolSelect(CCmdUI* pCmdUI) { L_UINT uToolType = GetDocument()->m_pVectorWindow->GetToolType(); L_INT nEngine = GetDocument()->m_pVectorWindow->GetEngine(); L_BOOL bEnable; bEnable = (nEngine == VECTOR_ENGINE_GDI) && (theApp.m_bUseAutomation == FALSE) && (!theApp.m_bViewOnly); pCmdUI->Enable(bEnable); pCmdUI->SetCheck(uToolType==TOOL_VECTOR_SELECT); } void CVectorView::OnToolRotate() { GetDocument()->m_pVectorWindow->SetToolType(TOOL_VECTOR_ROTATE); } void CVectorView::OnUpdateToolRotate(CCmdUI* pCmdUI) { pCmdUI->Enable(theApp.m_bUseAutomation == FALSE); L_UINT uToolType = GetDocument()->m_pVectorWindow->GetToolType(); pCmdUI->SetCheck(uToolType==TOOL_VECTOR_ROTATE); } void CVectorView::OnPreferencesEnablescrollbars() { GetDocument()->m_pVectorWindow->EnableAutoScroll(!GetDocument()->m_bAutoScroll); GetDocument()->m_bAutoScroll = GetDocument()->m_pVectorWindow->IsAutoScrollEnabled(); } void CVectorView::OnUpdatePreferencesEnablescrollbars(CCmdUI* pCmdUI) { pCmdUI->SetCheck(GetDocument()->m_bAutoScroll); } void CVectorView::OnLayerEdit() { L_INT nRet; nRet = GetDocument()->m_pVectorWindow->VectorDialog( )->DoModalVectorEditAllLayers(m_hWnd); if (nRet==SUCCESS) { GetDocument()->SetModifiedFlag(TRUE); GetDocument()->UpdateAllViews(NULL); } } void CVectorView::OnObjectNew(UINT nID) { L_INT nType, nRet; switch( nID ) { case ID_OBJECT_NEW_VERTEX: nType = VECTOR_VERTEX; break; case ID_OBJECT_NEW_LINE: nType = VECTOR_LINE; break; case ID_OBJECT_NEW_RECTANGLE: nType = VECTOR_RECTANGLE; break; case ID_OBJECT_NEW_POLYLINE: nType = VECTOR_POLYLINE; break; case ID_OBJECT_NEW_POLYBEZIER: nType = VECTOR_POLYBEZIER; break; case ID_OBJECT_NEW_POLYGON: nType = VECTOR_POLYGON; break; case ID_OBJECT_NEW_ELLIPSE: nType = VECTOR_ELLIPSE; break; case ID_OBJECT_NEW_CIRCLE: nType = VECTOR_CIRCLE; break; case ID_OBJECT_NEW_ARC: nType = VECTOR_ARC; break; case ID_OBJECT_NEW_ELLIPTICALARC: nType = VECTOR_ELLIPTICALARC; break; case ID_OBJECT_NEW_TEXT: nType = VECTOR_TEXT; break; case ID_OBJECT_NEW_PIE: nType = VECTOR_PIE; break; case ID_OBJECT_NEW_CHORD: nType = VECTOR_CHORD; break; case ID_OBJECT_NEW_POLYDRAW: nType = VECTOR_POLYDRAW; break; case ID_OBJECT_NEW_RASTER: nType = VECTOR_RASTER; break; case ID_OBJECT_NEW_STOCK: nType = VECTOR_STOCK; break; case ID_OBJECT_NEW_CLONE: nType = VECTOR_CLONE; break; case ID_OBJECT_NEW_SPLINE: nType = VECTOR_SPLINE; break; case ID_OBJECT_NEW_HPOLYBEZIER: nType = VECTOR_HPOLYBEZIER; break; default: return; } CVectorDoc* pDoc = GetDocument(); LVectorDialog VectorDlg(pDoc->m_pVectorWindow); VectorDlg.EnablePreview(); VectorDlg.EnableAutoProcess(); nRet = VectorDlg.DoModalVectorNewObject(m_hWnd, nType, NULL, NULL); if (nRet==SUCCESS) { pDoc->SetModifiedFlag(TRUE); pDoc->UpdateAllViews(NULL); } else ShowLeadError(nRet,NULL,NULL); } void CVectorView::OnUpdateObjectNew(CCmdUI* pCmdUI) { pCmdUI->Enable(!theApp.m_bViewOnly); } void CVectorView::OnObjectProperties() { L_INT nRet; CVectorDoc *pDoc; L_INT nCountSelected; pDoc = GetDocument(); LMyVectorWindow *pVectorWindow = pDoc->m_pVectorWindow; //GetCountSelected places last selected object in m_LastObject nCountSelected = pVectorWindow->GetCountSelectedObject(); LVectorObject MyObject(&pVectorWindow->m_LastObject, pVectorWindow); LVectorDialog VectorDlg(pVectorWindow); VectorDlg.EnablePreview(); VectorDlg.EnableAutoProcess(); nRet = VectorDlg.DoModalVectorEditObject(m_hWnd, &MyObject); if (nRet==SUCCESS) { pDoc->SetModifiedFlag(TRUE); pDoc->UpdateAllViews(NULL); } } void CVectorView::OnUpdateObjectProperties(CCmdUI* pCmdUI) { L_INT nCountSelected; nCountSelected = GetDocument()->m_pVectorWindow->GetCountSelectedObject(); pCmdUI->Enable(nCountSelected == 1 && !theApp.m_bViewOnly); } void CVectorView::OnImageMode() { L_INT nRet; CVectorDoc *pDoc; pDoc = GetDocument(); LMyVectorWindow *pVectorWindow = pDoc->m_pVectorWindow; LVectorDialog VectorDlg(pVectorWindow); VectorDlg.EnablePreview(); VectorDlg.EnableAutoProcess(); nRet = VectorDlg.DoModalVectorViewMode(m_hWnd, &pDoc->m_nViewMode); if (nRet==SUCCESS) { pDoc->SetModifiedFlag(TRUE); pDoc->UpdateAllViews(NULL); } } void CVectorView::OnImageExtent() { CVectorDoc *pDoc; pDoc = GetDocument(); LMyVectorWindow *pVectorWindow = pDoc->m_pVectorWindow; pVectorWindow->Reset(); pDoc->UpdateAllViews(NULL); } void CVectorView::OnImageRender() { L_INT nRet; CVectorDoc *pDoc; pDoc = GetDocument(); LMyVectorWindow *pVectorWindow = pDoc->m_pVectorWindow; LVectorDialog VectorDlg(pVectorWindow); VectorDlg.EnablePreview(); VectorDlg.EnableAutoProcess(); nRet = VectorDlg.DoModalVectorRender(m_hWnd); if (nRet==SUCCESS) { pDoc->SetModifiedFlag(TRUE); pDoc->UpdateAllViews(NULL); } } void CVectorView::OnImageHittest() { L_INT nRet; CVectorDoc *pDoc; pDoc = GetDocument(); LMyVectorWindow *pVectorWindow = pDoc->m_pVectorWindow; LVectorDialog VectorDlg(pVectorWindow); VectorDlg.EnablePreview(); VectorDlg.EnableAutoProcess(); nRet = VectorDlg.DoModalVectorHitTest(m_hWnd); if (nRet==SUCCESS) { pDoc->SetModifiedFlag(TRUE); pDoc->UpdateAllViews(NULL); } } void CVectorView::OnSetFocus(CWnd* pOldWnd) { CView::OnSetFocus(pOldWnd); MyContainer *pContainer = &GetDocument()->m_Container; theApp.m_Automation.SetActiveContainer(pContainer); } void CVectorView::OnFilePrint() { if (theApp.m_bUseAutomation) { theApp.m_Automation.Print(); } else { LowLevelPrint(); } } void CVectorView::OnEditUndo() { RECT Rect; theApp.m_Automation.Undo(); GetClientRect( &Rect ); GetDocument()->m_pVectorWindow->SetViewport( &Rect ); InvalidateRect( NULL ); } void CVectorView::OnUpdateEditUndo(CCmdUI* pCmdUI) { L_BOOL bEnable; L_INT nEngine = GetDocument()->m_pVectorWindow->GetEngine(); bEnable = (theApp.m_bUseAutomation) && (theApp.m_Automation.CanUndo() == TRUE) && (nEngine == VECTOR_ENGINE_GDI); pCmdUI->Enable(bEnable); } void CVectorView::OnEditRedo() { RECT Rect; theApp.m_Automation.Redo(); GetClientRect( &Rect ); GetDocument()->m_pVectorWindow->SetViewport( &Rect ); InvalidateRect( NULL ); } void CVectorView::OnUpdateEditRedo(CCmdUI* pCmdUI) { L_BOOL bEnable; L_INT nEngine = GetDocument()->m_pVectorWindow->GetEngine(); bEnable = (theApp.m_bUseAutomation) && (theApp.m_Automation.CanRedo() == TRUE) && (nEngine == VECTOR_ENGINE_GDI); pCmdUI->Enable(bEnable); } int CVectorView::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message) { //SetFocus(); //theApp.m_Automation.SetActiveContainer(&GetDocument()->m_Container); return CView::OnMouseActivate(pDesktopWnd, nHitTest, message); } void CVectorView::OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd) { CView::OnMDIActivate(bActivate, pActivateWnd, pDeactivateWnd); if (bActivate) { SetFocus(); theApp.m_Automation.SetActiveContainer(&GetDocument()->m_Container); } } void CVectorView::OnEditCut() { if (theApp.m_bUseAutomation) { theApp.m_Automation.Cut(); } else { GetDocument()->m_pVectorWindow->CopyToClipboard(m_hWnd, VECTOR_FLAGS_SELECTED_ONLY); GetDocument()->m_pVectorWindow->DeleteObject(VECTOR_FLAGS_SELECTED_ONLY); } } void CVectorView::OnUpdateEditCut(CCmdUI* pCmdUI) { L_BOOL bSelected = FALSE; GetDocument()->m_pVectorWindow->IsObjectSelected(&bSelected); pCmdUI->Enable(bSelected); } void CVectorView::OnEditCopy() { if (theApp.m_bUseAutomation) { theApp.m_Automation.Copy(); } else { GetDocument()->m_pVectorWindow->CopyToClipboard(m_hWnd, VECTOR_FLAGS_SELECTED_ONLY); } } void CVectorView::OnUpdateEditCopy(CCmdUI* pCmdUI) { L_INT nEngine = GetDocument()->m_pVectorWindow->GetEngine(); L_BOOL bSelected = FALSE; GetDocument()->m_pVectorWindow->IsObjectSelected(&bSelected); bSelected = bSelected && (nEngine == VECTOR_ENGINE_GDI); pCmdUI->Enable(bSelected); } void CVectorView::OnEditPasteObjects() { if (theApp.m_bUseAutomation) { theApp.m_Automation.Paste(VECTOR_FLAGS_COPY_INTO_ACTIVE_LAYER); } else { GetDocument()->m_pVectorWindow->CopyFromClipboard(m_hWnd, VECTOR_FLAGS_COPY_INTO_ACTIVE_LAYER); } } void CVectorView::OnUpdateEditPasteObjects(CCmdUI* pCmdUI) { L_INT nEngine = GetDocument()->m_pVectorWindow->GetEngine(); if (theApp.m_bUseAutomation) { pCmdUI->Enable((theApp.m_Automation.ClipboardDataReady()) && (nEngine == VECTOR_ENGINE_GDI)); } else { pCmdUI->Enable(GetDocument()->m_pVectorWindow->IsClipboardReady() && (nEngine == VECTOR_ENGINE_GDI)); } } void CVectorView::OnEditPasteLayers() { if (theApp.m_bUseAutomation) { theApp.m_Automation.Paste(VECTOR_FLAGS_COPY_LAYERS_ONLY); } else { GetDocument()->m_pVectorWindow->CopyFromClipboard(m_hWnd, VECTOR_FLAGS_COPY_LAYERS_ONLY); } } void CVectorView::OnUpdateEditPasteLayers(CCmdUI* pCmdUI) { L_INT nEngine = GetDocument()->m_pVectorWindow->GetEngine(); if (theApp.m_bUseAutomation) { pCmdUI->Enable((theApp.m_Automation.ClipboardDataReady()) && (nEngine == VECTOR_ENGINE_GDI)); } else { pCmdUI->Enable(GetDocument()->m_pVectorWindow->IsClipboardReady() && (nEngine == VECTOR_ENGINE_GDI)); } } void CVectorView::OnUpdateEditDelete(CCmdUI* pCmdUI) { L_INT nEngine = GetDocument()->m_pVectorWindow->GetEngine(); L_BOOL bSelected = FALSE; GetDocument()->m_pVectorWindow->IsObjectSelected(&bSelected); bSelected = bSelected && (nEngine == VECTOR_ENGINE_GDI); pCmdUI->Enable(bSelected); } void CVectorView::OnEditDelete() { LMyVectorWindow *pVectorWindow; pVectorWindow = GetDocument()->m_pVectorWindow; if (theApp.m_bUseAutomation) { theApp.m_Automation.Delete(); //pVectorWindow->DeleteObject(VECTOR_FLAGS_SELECTED_ONLY); // force redrawing the ocx ::ShowWindow( pVectorWindow->GetVectorWnd( ), SW_HIDE ); ::ShowWindow( pVectorWindow->GetVectorWnd( ), SW_SHOW ); } else { L_BOOL bSelected; pVectorWindow->IsObjectSelected(&bSelected); if( bSelected ) { pVectorWindow->DeleteObject(VECTOR_FLAGS_SELECTED_ONLY); GetDocument()->SetModifiedFlag(TRUE); } } } void CVectorView::OnDraw(CDC* pDC) { // TODO: Add your specialized code here and/or call the base class } L_VOID CVectorView::LowLevelPrint() { L_INT nRet; RECT Rect; DOCINFO DocInfo; CPrintDialog PrintDlg(FALSE, /*PD_RETURNDC | */ PD_NOPAGENUMS | PD_NOSELECTION, this); nRet = PrintDlg.DoModal(); if( nRet == IDOK ) { HDC printDC = PrintDlg.CreatePrinterDC(); //HDC printDC = PrintDlg.GetPrinterDC(); if ( printDC != NULL) { Rect.left = GetDeviceCaps( printDC, PHYSICALOFFSETX ); Rect.top = GetDeviceCaps( printDC, PHYSICALOFFSETY ); Rect.right = GetDeviceCaps( printDC, PHYSICALWIDTH ) - Rect.left * 2; Rect.bottom = GetDeviceCaps( printDC, PHYSICALHEIGHT ) - Rect.top * 2; DocInfo.cbSize = sizeof( DOCINFO ); L_TCHAR szFileName[_MAX_PATH]; L_UINT uSize=_MAX_PATH; GetDocument()->m_pVectorWindow->GetFileName(szFileName, &uSize); DocInfo.lpszDocName = szFileName; DocInfo.lpszOutput = NULL; DocInfo.lpszDatatype = NULL; StartDoc( printDC, &DocInfo ); StartPage( printDC ); SetMapMode( printDC, MM_TEXT ); L_VECPAINTDC( printDC, GetDocument()->m_pVectorWindow->GetHandle(), 1000, 1000, NULL, NULL, &Rect, NULL, 0L ); EndPage( printDC ); EndDoc( printDC ); nRet = SUCCESS; DeleteDC( printDC ); } else nRet = ERROR_NO_MEMORY; } } void CVectorView::OnUpdateEditUnselectall(CCmdUI* pCmdUI) { L_INT nEngine = GetDocument()->m_pVectorWindow->GetEngine(); L_BOOL bEnable = GetDocument()->m_pVectorWindow->GetEngine() == VECTOR_ENGINE_GDI; L_BOOL bSelected; GetDocument()->m_pVectorWindow->IsObjectSelected(&bSelected); pCmdUI->Enable(bEnable && bSelected); } void CVectorView::OnUpdateEditSelectall(CCmdUI* pCmdUI) { L_INT nEngine = GetDocument()->m_pVectorWindow->GetEngine(); L_BOOL bEnable = GetDocument()->m_pVectorWindow->GetEngine() == VECTOR_ENGINE_GDI; pCmdUI->Enable(bEnable); } void CVectorView::OnObjectEdit() { L_INT nRet; CVectorDoc *pDoc; L_INT nCountSelected; pDoc = GetDocument(); LMyVectorWindow *pVectorWindow = pDoc->m_pVectorWindow; //GetCountSelected places last selected object in m_LastObject nCountSelected = pVectorWindow->GetCountSelectedObject(); LVectorObject MyObject(&pVectorWindow->m_LastObject, pVectorWindow); nRet = theApp.m_Automation.EditVectorObject(&MyObject); if (nRet==SUCCESS) { pDoc->SetModifiedFlag(TRUE); pDoc->UpdateAllViews(NULL); } } void CVectorView::OnUpdateObjectEdit(CCmdUI* pCmdUI) { L_INT nCountSelected; L_INT nEngine = GetDocument()->m_pVectorWindow->GetEngine(); nCountSelected = GetDocument()->m_pVectorWindow->GetCountSelectedObject(); pCmdUI->Enable( (nCountSelected == 1) && (theApp.m_bUseAutomation) && (nEngine == VECTOR_ENGINE_GDI) && (!theApp.m_bViewOnly)); } void CVectorView::OnObjectExplode() { L_INT nRet; CVectorDoc *pDoc; pDoc = GetDocument(); LMyVectorWindow *pVectorWindow = pDoc->m_pVectorWindow; nRet = GetDocument()->m_pVectorWindow->ExplodeObject(VECTOR_FLAGS_SELECTED_ONLY); if (nRet==SUCCESS) { pDoc->SetModifiedFlag(TRUE); pDoc->UpdateAllViews(NULL); } } void CVectorView::OnUpdateObjectExplode(CCmdUI* pCmdUI) { L_INT nCountSelected; L_INT nEngine = GetDocument()->m_pVectorWindow->GetEngine(); nCountSelected = GetDocument()->m_pVectorWindow->GetCountSelectedObject(); pCmdUI->Enable( (nCountSelected > 0) && (nEngine == VECTOR_ENGINE_GDI) && (!theApp.m_bViewOnly)); } void CVectorView::OnGroupEdit() { L_INT nRet; CVectorDoc *pDoc; pDoc = GetDocument(); if (theApp.m_bUseAutomation) { pDoc->m_Container.Reset(); } LVectorDialog VectorDlg; VectorDlg.SetVector(GetDocument()->m_pVectorWindow); VectorDlg.EnablePreview(); VectorDlg.EnableAutoProcess(); nRet = VectorDlg.DoModalVectorEditAllGroups(m_hWnd); if( nRet == SUCCESS ) { pDoc->SetModifiedFlag(TRUE); pDoc->UpdateAllViews(NULL); } } void CVectorView::OnGroupAddselectedobjectto() { L_INT nGroupIndex; CVectorDoc *pDoc; pDoc = GetDocument(); if (theApp.m_bUseAutomation) { pDoc->m_Container.Reset(); } CGroupDlg GroupDlg; GroupDlg.m_pVector = GetDocument()->m_pVectorWindow; if (IDOK == GroupDlg.DoModal()) { nGroupIndex = GroupDlg.m_nGroupIndex; LVectorGroup MyGroup; pDoc->m_pVectorWindow->GetGroupByIndex(nGroupIndex, &MyGroup); pDoc->m_pVectorWindow->AddSelectedObjectsToGroup(&MyGroup); } } void CVectorView::OnUpdateGroupAddselectedobjectto(CCmdUI* pCmdUI) { pCmdUI->Enable(GetDocument()->m_pVectorWindow->GetCountSelectedObject() > 0 && !theApp.m_bViewOnly); } void CVectorView::OnUpdateLayerEdit(CCmdUI* pCmdUI) { pCmdUI->Enable(!theApp.m_bViewOnly); } void CVectorView::OnUpdateGroupEdit(CCmdUI* pCmdUI) { pCmdUI->Enable(!theApp.m_bViewOnly); } void CVectorView::OnFileConvertfileEmf() { FileConvert( TRUE ); } void CVectorView::OnFileConvertfileWmf() { FileConvert( FALSE ); } void CVectorView::FileConvert ( L_BOOL bEMF ) { L_INT nRet; CDC *pDC; RECT Rect; HENHMETAFILE hEnhMetaFile = NULL; HMETAFILE hMetaFile = NULL, hMetaFile2 =NULL; CVectorDoc *pDoc; LMyVectorWindow *pVectorWindow; HENHMETAFILE hEnhMetaFile2 = NULL; CConvertDLG ConvertDlg; pDoc = GetDocument( ); pVectorWindow = pDoc->m_pVectorWindow; pDC = GetDC( ); ConvertDlg.m_nDPI = pDC->GetDeviceCaps( LOGPIXELSX ); ConvertDlg.m_szPath = ""; pVectorWindow->GetViewport( &Rect ); ConvertDlg.m_nLeft = Rect.left; ConvertDlg.m_nTop = Rect.top; ConvertDlg.m_nRight = Rect.right; ConvertDlg.m_nBottom = Rect.bottom; ConvertDlg.m_bEmf = bEMF; if( IDOK != ConvertDlg.DoModal( ) ) { ReleaseDC( pDC ); return; } Rect.left = ConvertDlg.m_nLeft; Rect.top = ConvertDlg.m_nTop; Rect.right = ConvertDlg.m_nRight; Rect.bottom = ConvertDlg.m_nBottom; /* ConvertData contains all the information needed */ if( bEMF ) { nRet = pVectorWindow->ConvertToEMF( pDC->m_hDC, &hEnhMetaFile, ConvertDlg.m_nDPI, &Rect ); if( SUCCESS == nRet ) { /* Successful conversion */ hEnhMetaFile2 = CopyEnhMetaFile( hEnhMetaFile, ConvertDlg.m_szPath.LockBuffer( ) ); } } else { nRet = pVectorWindow->ConvertToWMF( pDC->m_hDC, &hMetaFile, ConvertDlg.m_nDPI, &Rect ); if( SUCCESS == nRet ) { /* Successful conversion */ hMetaFile2 = CopyMetaFile( hMetaFile, ConvertDlg.m_szPath.LockBuffer( ) ); } } if ( ((NULL != hEnhMetaFile) && (NULL == hEnhMetaFile2)) || ((NULL != hMetaFile) && (NULL == hMetaFile2)) ) AfxMessageBox( TEXT("Incorrect file path"), MB_OK | MB_ICONEXCLAMATION ); ReleaseDC( pDC ); } void CVectorView::OnPreferencesInvertcolors() { CVectorDoc *pDoc; pDoc = GetDocument( ); pDoc->m_pVectorWindow->InvertColors( ); InvalidateRect( NULL ); } void CVectorView::OnPreferencesUsepalette() { CVectorDoc *pDoc; CPaletteDLG PaletteDlg; pDoc = GetDocument( ); PaletteDlg.m_pVectorWindow = pDoc->m_pVectorWindow; PaletteDlg.DoModal( ); } LRESULT CVectorView::OnHandlePalette(WPARAM wParam,LPARAM lParam) { CVectorDoc *pDoc = GetDocument( ); LMyVectorWindow *pVectorWindow = pDoc->m_pVectorWindow; if(lParam==TRUE) { pVectorWindow->HandlePalette(WM_PALETTECHANGED,wParam,0); pVectorWindow->Repaint(); } else { if(pVectorWindow->HandlePalette(WM_QUERYNEWPALETTE,0,0)==FALSE) pVectorWindow->Repaint(); } return TRUE; } void CVectorView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) { if(bActivate==TRUE) { CVectorDoc *pDoc = GetDocument( ); LMyVectorWindow *pVectorWindow = pDoc->m_pVectorWindow; pVectorWindow->HandlePalette(WM_QUERYNEWPALETTE,0,0); ::SetFocus(m_hWnd); } } void CVectorView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { L_UINT uNewWidth; L_UINT uNewHeight; L_INT nWidthDiff; L_INT nHeightDiff; L_INT nTemp; L_INT nRet; VECTORPOINT ptMin; VECTORPOINT ptMax; CVectorDoc *pDoc = GetDocument( ); LMyVectorWindow *pVectorWindow = pDoc->m_pVectorWindow; if ( (VK_ADD != nChar) && (VK_SUBTRACT != nChar) ) return; if ( VK_ADD == nChar ) { nTemp = 90; } else { nTemp = 110; } nRet = pVectorWindow->GetParallelogram(&ptMin, &ptMax ); if ( SUCCESS != nRet ) return; uNewWidth = MulDiv( (L_INT)( ptMax.x - ptMin.x ), nTemp, 100 ); uNewHeight = MulDiv( (L_INT)( ptMax.y - ptMin.y ), nTemp, 100 ); nWidthDiff = uNewWidth - (L_INT)( ptMax.x - ptMin.x ); nHeightDiff = uNewHeight - (L_INT)( ptMax.y - ptMin.y ); ptMin.x -= nWidthDiff / 2; ptMin.y -= nHeightDiff / 2; ptMax.x += nWidthDiff / 2; ptMax.y += nHeightDiff / 2; pVectorWindow->SetParallelogram(&ptMin, &ptMax ); InvalidateRect( NULL ); CView::OnKeyDown(nChar, nRepCnt, nFlags); } /*---------------------------------------------------------------------------- | | ShowFileError | ---------------------------------------------------------------------------*/ L_VOID ShowLeadError ( L_INT nCode, const L_TCHAR *pszTitle, const L_TCHAR *pszFilename ) { L_TCHAR szErrorBuf[ 80 ]; switch( nCode ) { case ERROR_NO_MEMORY: wsprintf( szErrorBuf, TEXT("Not enough memory available!") ); break; case ERROR_NO_BITMAP: wsprintf( szErrorBuf, TEXT("Invalid bitmap handle!") ); break; case ERROR_MEMORY_TOO_LOW: wsprintf( szErrorBuf, TEXT("Not enough memory available!") ); break; case ERROR_FILE_LSEEK: wsprintf( szErrorBuf, TEXT("Error seeking to position!") ); break; case ERROR_FILE_WRITE: wsprintf( szErrorBuf, TEXT("Error writing file!") ); break; case ERROR_FILE_GONE: wsprintf( szErrorBuf, TEXT("File not present - abort!") ); break; case ERROR_FILE_READ: wsprintf( szErrorBuf, TEXT("Error reading file!") ); break; case ERROR_INV_FILENAME: wsprintf( szErrorBuf, TEXT("Invalid filename specified!") ); break; case ERROR_FILE_FORMAT: wsprintf( szErrorBuf, TEXT("Invalid file format!") ); break; case ERROR_FILENOTFOUND: wsprintf( szErrorBuf, TEXT("File not found!") ); break; case ERROR_INV_RANGE: wsprintf( szErrorBuf, TEXT("Invalid width/height!") ); break; case ERROR_IMAGE_TYPE: wsprintf( szErrorBuf, TEXT("Image format recognized, but sub-type not supported!") ); break; case ERROR_INV_PARAMETER: wsprintf( szErrorBuf, TEXT("Invalid parmameter!") ); break; case ERROR_FILE_OPEN: wsprintf( szErrorBuf, TEXT("Not able to open file!") ); break; case ERROR_UNKNOWN_COMP: wsprintf( szErrorBuf, TEXT("Unknown compression format!") ); break; case ERROR_FEATURE_NOT_SUPPORTED: wsprintf( szErrorBuf, TEXT("Feature not supported!") ); break; case ERROR_NOT_256_COLOR: wsprintf( szErrorBuf, TEXT("VGA card only supports 256 colors (8 bit)!") ); break; case ERROR_PRINTER: wsprintf( szErrorBuf, TEXT("Printer error!") ); break; case ERROR_CRC_CHECK: wsprintf( szErrorBuf, TEXT("Data CRC check error!") ); break; case ERROR_QFACTOR: wsprintf( szErrorBuf, TEXT("Invalid QFactor specified!") ); break; case ERROR_TARGAINSTALL: wsprintf( szErrorBuf, TEXT("TARGA not installed!") ); break; case ERROR_OUTPUTTYPE: wsprintf( szErrorBuf, TEXT("Invalid compression format!") ); break; case ERROR_XORIGIN: wsprintf( szErrorBuf, TEXT("X origin specified invalid!") ); break; case ERROR_YORIGIN: wsprintf( szErrorBuf, TEXT("Y origin specified invalid!") ); break; case ERROR_VIDEOTYPE: wsprintf( szErrorBuf, TEXT("Invalid video mode!") ); break; case ERROR_BITPERPIXEL: wsprintf( szErrorBuf, TEXT("Invalid bits/pixel!") ); break; case ERROR_WINDOWSIZE: wsprintf( szErrorBuf, TEXT("Invalid window size!") ); break; case ERROR_NORMAL_ABORT: wsprintf( szErrorBuf, TEXT("Escape key pressed!") ); break; case ERROR_NO_STAMP: wsprintf( szErrorBuf, TEXT("Stamp not found!") ); break; case ERROR_G3CODE_INVALID: wsprintf( szErrorBuf, TEXT("Invalid group 3 data!") ); break; case ERROR_G3CODE_EOF: case ERROR_G3CODE_EOL: wsprintf( szErrorBuf, TEXT("Group3 code end of code!") ); break; case ERROR_PREMATURE_EOF: wsprintf( szErrorBuf, TEXT("Premature EOF at scanline!") ); break; case ERROR_PREMATURE_EOL: case ERROR_UNCOMP_EOF: case ERROR_ACT_INCOMP: case ERROR_BAD_DECODE_STATE: wsprintf( szErrorBuf, TEXT("Premature end-of-line code!") ); break; case ERROR_VERSION_NUMBER: wsprintf( szErrorBuf, TEXT("Bad version number!") ); break; case ERROR_TWAIN_NODSM: wsprintf( szErrorBuf, TEXT("Source manager not found!") ); break; case ERROR_TWAIN_BUMMER: wsprintf( szErrorBuf, TEXT("Failure due to unknown causes!") ); break; case ERROR_TWAIN_LOWMEMORY: wsprintf( szErrorBuf, TEXT("Not enough memory to perform operation!") ); break; case ERROR_TWAIN_NODS: wsprintf( szErrorBuf, TEXT("No Data Source!") ); break; case ERROR_TWAIN_MAXCONNECTIONS: wsprintf( szErrorBuf, TEXT("DS is connected to max possible apps!") ); break; case ERROR_TWAIN_OPERATIONERROR: wsprintf( szErrorBuf, TEXT("DS or DSM reported error, app shouldn't!") ); break; case ERROR_TWAIN_BADCAP: wsprintf( szErrorBuf, TEXT("Unknown capability!") ); break; case ERROR_TWAIN_BADPROTOCOL: wsprintf( szErrorBuf, TEXT("Unrecognized MSG DG DAT combination!") ); break; case ERROR_TWAIN_BADVALUE: wsprintf( szErrorBuf, TEXT("Data parameter out of range!") ); break; case ERROR_TWAIN_SEQERROR: wsprintf( szErrorBuf, TEXT("DG DAT MSG out of expected sequence!") ); break; case ERROR_TWAIN_BADDEST: wsprintf( szErrorBuf, TEXT("Unknown destination App/Src in DSM_Entry!") ); break; case ERROR_TWAIN_CANCEL: wsprintf( szErrorBuf, TEXT("Operation was cancelled!") ); break; case ERROR_IMAGE_EMPTY: wsprintf( szErrorBuf, TEXT("Image is empty!") ); break; case ERROR_NO_CHANGE: wsprintf( szErrorBuf, TEXT("The image hasn't changed!") ); break; case ERROR_DOCUMENT_NOT_ENABLED: wsprintf( szErrorBuf, TEXT("Document capability is required to use this function!") ); break; case ERROR_FPX_FILE_IN_USE: wsprintf( szErrorBuf, TEXT("Error accessing file. The file is probably already open!") ); break; case ERROR_VECTOR_NOT_ENABLED: wsprintf( szErrorBuf, TEXT("Vector toolkit not enabled!") ); break; case ERROR_VECTOR_IS_LOCKED: wsprintf( szErrorBuf, TEXT("Vector handle is locked!") ); break; case ERROR_VECTOR_IS_EMPTY: wsprintf( szErrorBuf, TEXT("Vector is empty!") ); break; case ERROR_VECTOR_LAYER_NOT_FOUND: wsprintf( szErrorBuf, TEXT("Layer is not found!") ); break; case ERROR_VECTOR_LAYER_IS_LOCKED: wsprintf( szErrorBuf, TEXT("Layer is locked!") ); break; case ERROR_VECTOR_LAYER_ALREADY_EXISTS: wsprintf( szErrorBuf, TEXT("Layer already exists!") ); break; case ERROR_VECTOR_OBJECT_NOT_FOUND: wsprintf( szErrorBuf, TEXT("Object is not found!") ); break; case ERROR_VECTOR_INVALID_OBJECT_TYPE: wsprintf( szErrorBuf, TEXT("Invalid object type!") ); break; case ERROR_VECTOR_PEN_NOT_FOUND: wsprintf( szErrorBuf, TEXT("Pen is not found!") ); break; case ERROR_VECTOR_BRUSH_NOT_FOUND: wsprintf( szErrorBuf, TEXT("Brush is not found!") ); break; case ERROR_VECTOR_FONT_NOT_FOUND: wsprintf( szErrorBuf, TEXT("Font is not found!") ); break; case ERROR_VECTOR_BITMAP_NOT_FOUND: wsprintf( szErrorBuf, TEXT("Bitmap is not found!") ); break; case ERROR_VECTOR_POINT_NOT_FOUND: wsprintf( szErrorBuf, TEXT("Point is not found!") ); break; case ERROR_VECTOR_ENGINE_NOT_FOUND: wsprintf( szErrorBuf, TEXT("Vector engine not found!") ); break; case ERROR_VECTOR_INVALID_ENGINE: wsprintf( szErrorBuf, TEXT("Invalid vector engine!") ); break; case ERROR_VECTOR_CLIPBOARD: wsprintf( szErrorBuf, TEXT("Clipboard error!") ); break; case ERROR_VECTOR_CLIPBOARD_IS_EMPTY: wsprintf( szErrorBuf, TEXT("Clipboard is empty!") ); break; case ERROR_VECTOR_CANT_ADD_TEXT: wsprintf( szErrorBuf, TEXT("Cannot add text!") ); break; case ERROR_VECTOR_CANT_READ_WMF: wsprintf( szErrorBuf, TEXT("Cannot read WMF!") ); break; case ERROR_VECTOR_GROUP_NOT_FOUND: wsprintf( szErrorBuf, TEXT("Group is not found!") ); break; case ERROR_VECTOR_GROUP_ALREADY_EXISTS: wsprintf( szErrorBuf, TEXT("Group already exists!") ); break; case ERROR_USER_ABORT: case SUCCESS_DLG_CANCEL: return; break; default: wsprintf( szErrorBuf, TEXT("Internal or Unrecognized Error!") ); break; } if( pszFilename && pszTitle ) ShowMessageBox( FALSE, MB_ICONEXCLAMATION, TEXT("%s\nFile Name:\n%s\n\nError %d\n%s"), pszTitle, pszFilename, nCode, szErrorBuf ); else ShowMessageBox( FALSE, MB_ICONEXCLAMATION, TEXT("Error %d\n%s"), nCode, szErrorBuf ); } /*---------------------------------------------------------------------------- | | ShowMessageBox | ---------------------------------------------------------------------------*/ L_INT ShowMessageBox ( L_BOOL bLastError, L_UINT uType, const L_TCHAR *pszMessage, ... ) { #define BUF_SIZE (4096) static const L_TCHAR szUnknownError[] = TEXT("Unknown error."); static L_TCHAR szBuffer[ BUF_SIZE ] = TEXT(""); static L_TCHAR szTemp[ BUF_SIZE ] = TEXT(""); L_UINT32 dwLastError; L_TCHAR *pszLastErrorMessage; L_UINT32 cbSize; HWND hWndFocus; L_INT nRet; va_list ap; if( pszMessage ) { va_start( ap, pszMessage ); #ifdef UNICODE vswprintf( szBuffer, pszMessage, ap ); #else vsprintf( szBuffer, pszMessage, ap ); #endif va_end( ap ); } else lstrcpy( szBuffer, TEXT("") ); if( bLastError ) { dwLastError = GetLastError(); pszLastErrorMessage = NULL; cbSize = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwLastError, 0L, (L_TCHAR*) pszLastErrorMessage, BUF_SIZE / 2, NULL ); if( !cbSize ) SetLastError( dwLastError ); if( szBuffer[ 0 ] != '\0' ) { wsprintf( szTemp, TEXT("%s\n\n%s"), szBuffer, pszLastErrorMessage ? pszLastErrorMessage : szUnknownError ); lstrcpy( szBuffer, szTemp ); } else lstrcpy( szBuffer, pszLastErrorMessage ? pszLastErrorMessage : szUnknownError ); if( pszLastErrorMessage ) LocalFree( pszLastErrorMessage ); } hWndFocus = GetFocus(); nRet = MessageBox( NULL, szBuffer, TEXT("Vector Demo"), uType ); if( hWndFocus && IsWindow( hWndFocus ) ) SetFocus( hWndFocus ); return nRet; }