MyNewDlg.cpp
上传用户:netltd
上传日期:2013-02-12
资源大小:7234k
文件大小:11k
- // MyNewDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "resource.h"
- #include "MyNewDlg.h"
- #include "ChooseDirDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////
- // CMyNewSheet
- IMPLEMENT_DYNAMIC(CMyNewSheet, CPropertySheet)
- CMyNewSheet::CMyNewSheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
- :CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
- {
- //增加属性页
- AddPage(&m_NewFileDlg);
- AddPage(&m_NewComponentDlg);
- //不显示"应用"按钮
- m_psh.dwFlags |= PSH_NOAPPLYNOW;
- }
- CMyNewSheet::CMyNewSheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
- :CPropertySheet(pszCaption, pParentWnd, iSelectPage)
- {
- //增加属性页
- AddPage(&m_NewFileDlg);
- AddPage(&m_NewComponentDlg);
- //不显示"应用"按钮
- m_psh.dwFlags |= PSH_NOAPPLYNOW;
- }
- CMyNewSheet::~CMyNewSheet()
- {
-
- }
- BEGIN_MESSAGE_MAP(CMyNewSheet, CPropertySheet)
- //{{AFX_MSG_MAP(CMyNewSheet)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMyNewSheet message handlers
- /////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////
- // CMyNewFileDlg property page
- IMPLEMENT_DYNCREATE(CMyNewFileDlg, CPropertyPage)
- CMyNewFileDlg::CMyNewFileDlg() : CPropertyPage(CMyNewFileDlg::IDD)
- {
- //{{AFX_DATA_INIT(CMyNewFileDlg)
- m_Name = _T("");
- m_FilePath = _T("");
- m_FileName = _T("");
- m_Size = -1;
- //}}AFX_DATA_INIT
- }
- CMyNewFileDlg::~CMyNewFileDlg()
- {
- }
- void CMyNewFileDlg::DoDataExchange(CDataExchange* pDX)
- {
- pApp = (CMiniCADApp*)AfxGetApp();
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMyNewFileDlg)
- DDX_Text(pDX, IDC_DOCUMENT_NAME, m_Name);
- DDX_Text(pDX, IDC_DOCUMENT_PATH, m_FilePath);
- DDX_Text(pDX, IDC_DOCUMENT_FILENAME, m_FileName);
- DDX_Radio(pDX, IDC_RADIO0, m_Size);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CMyNewFileDlg, CPropertyPage)
- //{{AFX_MSG_MAP(CMyNewFileDlg)
- ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
- ON_WM_SHOWWINDOW()
- ON_BN_CLICKED(IDC_TEMPLATECHECK, OnTemplatecheck)
- ON_EN_CHANGE(IDC_DOCUMENT_PATH, OnChangeDocumentPath)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMyNewFileDlg message handlers
- BOOL CMyNewFileDlg::OnInitDialog()
- {
- CPropertyPage::OnInitDialog();
-
- m_Size = A4_SIZE_INDEX;
- //显示当前路径
- m_FilePath = pApp->CADInfo.FilePath;
- UpdateData(FALSE);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CMyNewFileDlg::OnBrowse()
- {
- CChooseDirDlg m_ChooseDirDlg;
- m_FilePath = m_ChooseDirDlg.GetDirectory(m_FilePath);
- UpdateData(FALSE);
- }
- void CMyNewFileDlg::OnShowWindow(BOOL bShow, UINT nStatus)
- {
- CPropertyPage::OnShowWindow(bShow, nStatus);
- if(bShow == TRUE)
- pApp->CADInfo.KindofNew = NEW_FILE;
- }
- void CMyNewFileDlg::OnTemplatecheck()
- {
- CButton* button = (CButton*)GetDlgItem(IDC_OPENTEMPLATE);
- CButton* check = (CButton*)GetDlgItem(IDC_TEMPLATECHECK);
- //使“打开”按钮生效或失效
- button->EnableWindow(check->GetCheck());
- }
- void CMyNewFileDlg::OnChangeDocumentPath()
- {
- UpdateData(TRUE);
- }
- void CMyNewFileDlg::OnCancel()
- {
- //取消新建
- pApp->CADInfo.KindofNew = NEW_NONE;
- CPropertyPage::OnCancel();
- }
- BOOL CMyNewFileDlg::OnApply()
- {
- WIN32_FIND_DATA fd;
- if(pApp->CADInfo.KindofNew ==NEW_FILE)
- {
- //提示输入图纸名
- if(m_Name.IsEmpty() == TRUE
- || m_FileName.IsEmpty() == TRUE)
- {
- MessageBox("请输入图纸名及相应文件名",
- "提示", MB_OK | MB_ICONINFORMATION);
- return FALSE;
- }
- if(FindFirstFile(m_FilePath + "\" + m_FileName,
- &fd) != INVALID_HANDLE_VALUE )
- {
- MessageBox("指定目录下已有相同文件名的文件存在",
- "错误", MB_OK | MB_ICONERROR);
- return FALSE;
- }
- pApp->CADInfo.FilePath = m_FilePath;
-
- //对FileInfo成员赋值
- //FileInfo.Name = m_Name;
- //FileInfo.FileName = m_FileName;
- //FileInfo.FilePath = m_FilePath;
- }
- return CPropertyPage::OnApply();
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMyNewComponentDlg property page
- IMPLEMENT_DYNCREATE(CMyNewComponentDlg, CPropertyPage)
- CMyNewComponentDlg::CMyNewComponentDlg() : CPropertyPage(CMyNewComponentDlg::IDD)
- {
- //{{AFX_DATA_INIT(CMyNewComponentDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
- CMyNewComponentDlg::~CMyNewComponentDlg()
- {
- }
- void CMyNewComponentDlg::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMyNewComponentDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CMyNewComponentDlg, CPropertyPage)
- //{{AFX_MSG_MAP(CMyNewComponentDlg)
- // NOTE: the ClassWizard will add message map macros here
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMyNewComponentDlg message handlers
- /////////////////////////////////////////////////////////////////////////////////
- // CMyNewProjectDlg
- CMyNewProjectDlg::CMyNewProjectDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CMyNewProjectDlg::IDD, pParent)
- {
- pApp = (CMiniCADApp*)AfxGetApp();
- //{{AFX_DATA_INIT(CMyNewProjectDlg)
- m_ProjectName = _T("");
- m_ProjectPath = _T("");
- m_ProjectFileName = _T("");
- //}}AFX_DATA_INIT
- }
- CMyNewProjectDlg::~CMyNewProjectDlg()
- {
- }
- void CMyNewProjectDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMyNewProjectDlg)
- DDX_Text(pDX, IDC_PROJECT_NAME, m_ProjectName);
- DDX_Text(pDX, IDC_PROJECT_PATH, m_ProjectPath);
- DDX_Text(pDX, IDC_PROJECT_FILENAME, m_ProjectFileName);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CMyNewProjectDlg, CDialog)
- //{{AFX_MSG_MAP(CMyNewProjectDlg)
- ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
- ON_EN_CHANGE(IDC_PROJECT_PATH, OnChangeProjectPath)
- ON_EN_CHANGE(IDC_PROJECT_NAME, OnChangeProjectName)
- ON_EN_CHANGE(IDC_PROJECT_FILENAME, OnChangeProjectFilename)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMyNewProjectDlg message handlers
- BOOL CMyNewProjectDlg::NewProject(CProjectInfo* pInfo)
- {
- flag = TRUE;
- pProjectInfo = pInfo;
- DoModal();
- return flag;
- }
- BOOL CMyNewProjectDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- //显示当前路径
- m_ProjectPath = pApp->CADInfo.ProjectPath;
- UpdateData(FALSE);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CMyNewProjectDlg::OnOK()
- {
- WIN32_FIND_DATA fd;
- UpdateData(TRUE);
- //提示输入项目名
- if(m_ProjectName.IsEmpty() == TRUE
- || m_ProjectFileName.IsEmpty() == TRUE)
- {
- MessageBox("请输入项目名及相应文件名",
- "提示", MB_OK | MB_ICONINFORMATION);
- return;
- }
- if(FindFirstFile(m_ProjectPath + "\" + m_ProjectFileName,
- &fd) != INVALID_HANDLE_VALUE )
- {
- MessageBox("指定目录下已有相同文件名的文件存在",
- "错误", MB_OK | MB_ICONERROR);
- return;
- }
- //改变项目的缺省路径
- pApp->CADInfo.ProjectPath = m_ProjectPath;
-
- //对MyProjectInfo成员赋值
- pProjectInfo->Name = m_ProjectName;
- pProjectInfo->FileName = m_ProjectFileName + ".PROJECT_POSTFIX";
- pProjectInfo->FilePath = m_ProjectPath;
- flag = TRUE;
- CDialog::OnOK();
- }
- void CMyNewProjectDlg::OnBrowse()
- {
- CChooseDirDlg m_ChooseDirDlg;
- m_ProjectPath = m_ChooseDirDlg.GetDirectory(m_ProjectPath);
-
- UpdateData(FALSE);
- }
- void CMyNewProjectDlg::OnChangeProjectName()
- {
- UpdateData(TRUE);
- }
- void CMyNewProjectDlg::OnChangeProjectFilename()
- {
- UpdateData(TRUE);
- }
- void CMyNewProjectDlg::OnChangeProjectPath()
- {
- UpdateData(TRUE);
- }
- void CMyNewProjectDlg::OnCancel()
- {
- //取消新建
- flag = FALSE;
- CDialog::OnCancel();
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMyAddFileDlg dialog
- CMyAddFileDlg::CMyAddFileDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CMyAddFileDlg::IDD, pParent)
- {
- pApp = (CMiniCADApp*)AfxGetApp();
- //{{AFX_DATA_INIT(CMyAddFileDlg)
- m_Name = _T("");
- m_FileName = _T("");
- m_SizeIndex = -1;
- m_FilePath = _T("");
- //}}AFX_DATA_INIT
- }
- void CMyAddFileDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMyAddFileDlg)
- DDX_Text(pDX, IDC_NAME, m_Name);
- DDX_Text(pDX, IDC_FILENAME, m_FileName);
- DDX_Radio(pDX, IDC_RADIO0, m_SizeIndex);
- DDX_Text(pDX, IDC_FILEPATH, m_FilePath);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CMyAddFileDlg, CDialog)
- //{{AFX_MSG_MAP(CMyAddFileDlg)
- ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
- ON_EN_CHANGE(IDC_FILEPATH, OnChangeFilepath)
- ON_EN_CHANGE(IDC_NAME, OnChangeName)
- ON_WM_SHOWWINDOW()
- ON_EN_CHANGE(IDC_FILENAME, OnChangeFilename)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- BOOL CMyAddFileDlg::AddFile(CFileInfo* pInfo)
- {
- flag = TRUE;
- pFileInfo = pInfo;
- DoModal();
- return flag;
- }
- // CMyAddFileDlg message handlers
- BOOL CMyAddFileDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- //设置省缺图纸大小
- m_SizeIndex = A3_SIZE_INDEX;
- //缺省路径和项目路径一样
- m_FilePath = pApp->CADInfo.ProjectPath;
- UpdateData(FALSE);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CMyAddFileDlg::OnOK()
- {
- WIN32_FIND_DATA fd;
- UpdateData(TRUE);
- //提示输入图纸名
- if(m_Name.IsEmpty() == TRUE
- || m_FileName.IsEmpty() == TRUE)
- {
- MessageBox("请输入图纸名及相应文件名",
- "提示", MB_OK | MB_ICONINFORMATION);
- return;
- }
- if(FindFirstFile(m_FilePath + "\" + m_FileName,
- &fd) != INVALID_HANDLE_VALUE )
- {
- MessageBox("项目文件所在目录下已有相同文件名的文件存在",
- "错误", MB_OK | MB_ICONERROR);
- return;
- }
- //改变文件的缺省路径
- pApp->CADInfo.FilePath = m_FilePath;
- pFileInfo->m_Name = m_Name;
- pFileInfo->m_FileName = m_FileName + ".DRAWING_POSTFIX";
- pFileInfo->m_FilePath = m_FilePath;
- SIZE size[5] = {1189, 841,
- 841, 594,
- 594, 420,
- 420, 297,
- 210, 297};
- pFileInfo->m_Size.cx = size[m_SizeIndex].cx;
- pFileInfo->m_Size.cy = size[m_SizeIndex].cy;
- CDialog::OnOK();
- }
- void CMyAddFileDlg::OnCancel()
- {
- //增加新图纸失败
- flag = FALSE;
- CDialog::OnCancel();
- }
- void CMyAddFileDlg::OnBrowse()
- {
- CChooseDirDlg m_ChooseDirDlg;
- m_FilePath = m_ChooseDirDlg.GetDirectory(m_FilePath);
-
- //重新显示当前路径
- UpdateData(FALSE);
-
- }
- void CMyAddFileDlg::OnChangeName()
- {
- UpdateData(TRUE);
- }
- void CMyAddFileDlg::OnChangeFilename()
- {
- UpdateData(TRUE);
- }
- void CMyAddFileDlg::OnChangeFilepath()
- {
- UpdateData(TRUE);
- }