208 lines
4.4 KiB
C++
208 lines
4.4 KiB
C++
#include "stdafx.h"
|
|
#include "InsertFrameDlg.h"
|
|
|
|
#ifndef _ttof
|
|
#define _ttof(pszVal) _tcstod((pszVal), NULL)
|
|
#endif
|
|
|
|
IMPLEMENT_DYNAMIC(CInsertFrameDlg, CDialog)
|
|
|
|
CInsertFrameDlg::CInsertFrameDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CInsertFrameDlg::IDD, pParent)
|
|
, m_bPickInsPoint(TRUE)
|
|
, m_bExplode(FALSE)
|
|
{
|
|
m_dScale = 100.0;
|
|
m_bIsModeless = false;
|
|
m_ptSize.x = 0;
|
|
m_ptSize.y = 0;
|
|
m_bisLyoutZT = false;
|
|
}
|
|
|
|
CInsertFrameDlg::~CInsertFrameDlg()
|
|
{
|
|
}
|
|
|
|
void CInsertFrameDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
DDX_Control(pDX, IDC_LISTFRAMES, m_wndListFrames);
|
|
DDX_Check(pDX, IDC_CHECKINSPT, m_bPickInsPoint);
|
|
DDX_Check(pDX, IDC_CHECKEXPLODE, m_bExplode);
|
|
DDX_Control(pDX, IDC_COMBOSCALE, m_wndComboScale);
|
|
DDX_Control(pDX, IDC_STATIC_SCALE, m_wndScaleSt);
|
|
DDX_Control(pDX, IDC_CHECKINSPT, m_wndInsPosBt);
|
|
DDX_Control(pDX, IDC_CHECKEXPLODE, m_wndInsExpbt);
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CInsertFrameDlg, CDialog)
|
|
ON_BN_CLICKED(IDOK, &CInsertFrameDlg::OnBnClickedOk)
|
|
ON_MESSAGE( WM_ACAD_KEEPFOCUS, &CInsertFrameDlg::onAcadKeepFocus )
|
|
ON_NOTIFY(NM_CLICK, IDC_LISTFRAMES, &CInsertFrameDlg::OnNMClickListframes)
|
|
END_MESSAGE_MAP()
|
|
|
|
LONG_PTR CInsertFrameDlg::onAcadKeepFocus( UINT_PTR, LONG_PTR)
|
|
{
|
|
POINT pt;
|
|
::GetCursorPos(&pt);
|
|
CRect rect;
|
|
GetWindowRect(&rect);
|
|
if(!(rect.PtInRect(pt)))
|
|
{
|
|
return FALSE;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CInsertFrameDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
m_wndListFrames.SetExtendedStyle(LVS_EX_FULLROWSELECT);
|
|
m_wndListFrames.InsertColumn(0,_T("图幅"),LVCFMT_LEFT,200,200);
|
|
m_wndListFrames.InsertColumn(1,_T("文件"),LVCFMT_LEFT,0,0);
|
|
|
|
m_ImageList.Create(IDB_BITMAPTK,16,1,RGB(0, 255, 255));
|
|
m_wndListFrames.SetImageList(&m_ImageList, LVSIL_SMALL);
|
|
|
|
ShowRegFrames();
|
|
|
|
CString sScale;
|
|
sScale.Format(_T("1:%d"),(int)(m_dScale + 0.5));
|
|
int nPos = m_wndComboScale.FindString(0,sScale);
|
|
if (nPos != -1)
|
|
{
|
|
m_wndComboScale.SetCurSel(nPos);
|
|
}
|
|
|
|
if (m_bIsModeless)
|
|
{
|
|
GetDlgItem(IDOK)->EnableWindow(FALSE);
|
|
GetDlgItem(IDOK)->ShowWindow(SW_HIDE);
|
|
|
|
GetDlgItem(IDCANCEL)->EnableWindow(FALSE);
|
|
GetDlgItem(IDCANCEL)->ShowWindow(SW_HIDE);
|
|
}
|
|
|
|
if (m_bisLyoutZT)
|
|
{
|
|
m_wndComboScale.ShowWindow(SW_HIDE);
|
|
m_wndScaleSt.ShowWindow(SW_HIDE);
|
|
m_wndInsPosBt.ShowWindow(SW_HIDE);
|
|
m_wndInsExpbt.ShowWindow(SW_HIDE);
|
|
m_wndComboScale.SetCurSel(0);//1:1
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CInsertFrameDlg::ShowRegFrames()
|
|
{
|
|
TCHAR szfileName[MAX_PATH],szFullPath[MAX_PATH];
|
|
GetModuleFileName(_hdllInstance,szfileName,MAX_PATH);
|
|
|
|
TCHAR drive[_MAX_DRIVE] = _T(""),
|
|
dir[_MAX_DIR] = _T(""),
|
|
fname[_MAX_FNAME] = _T(""),
|
|
ext[_MAX_EXT] = _T("");
|
|
|
|
//e:\,program files\autodesk\,myarx,exe
|
|
_tsplitpath(szfileName, drive, dir, fname, ext);
|
|
_tcscpy(szFullPath, drive);
|
|
_tcscat(szFullPath, dir);
|
|
|
|
CString sFullPath = szFullPath;
|
|
sFullPath.TrimRight(_T('\\'));
|
|
|
|
//上一级目录
|
|
int nPos = sFullPath.ReverseFind(_T('\\'));
|
|
CString sPath = sFullPath.Mid(0,nPos + 1);
|
|
|
|
sFullPath = sPath + _T("drawframe\\");
|
|
sFullPath += _T("drawframe.lst");
|
|
|
|
//A0+1x2=CAD_A0.dwg;
|
|
//A0+2=
|
|
//....
|
|
|
|
CString sLine,sAx,sFile;
|
|
CStdioFile file;
|
|
if (file.Open(sFullPath,CFile::modeRead | CFile::typeText))
|
|
{
|
|
while(file.ReadString(sLine))
|
|
{
|
|
nPos = sLine.Find(_T('='));
|
|
if (nPos != -1)
|
|
{
|
|
sAx = sLine.Mid(0,nPos);
|
|
sFile = sLine.Mid(nPos+1);
|
|
|
|
nPos = m_wndListFrames.InsertItem(m_wndListFrames.GetItemCount(),sAx,0);
|
|
m_wndListFrames.SetItemText(nPos,1,sFile);
|
|
}
|
|
}
|
|
file.Close();
|
|
}
|
|
|
|
m_wndListFrames.SetItemState(0,LVIS_SELECTED,LVIS_SELECTED);
|
|
}
|
|
|
|
void CInsertFrameDlg::OnBnClickedOk()
|
|
{
|
|
UpdateData();
|
|
|
|
int nItem = -1;
|
|
POSITION ps = m_wndListFrames.GetFirstSelectedItemPosition();
|
|
if (ps != NULL)
|
|
{
|
|
nItem = m_wndListFrames.GetNextSelectedItem(ps);
|
|
}
|
|
|
|
if (nItem == -1)
|
|
{
|
|
AfxMessageBox(_T("请选择要插入的图幅!"));
|
|
return;
|
|
}
|
|
|
|
m_sBlockName = m_wndListFrames.GetItemText(nItem,0);
|
|
m_sDwgFile = m_wndListFrames.GetItemText(nItem,1);
|
|
|
|
CString sText;
|
|
int nSel = m_wndComboScale.GetCurSel();
|
|
if (nSel != -1)
|
|
{
|
|
m_wndComboScale.GetLBText(nSel,sText);
|
|
}
|
|
else
|
|
{
|
|
m_wndComboScale.GetWindowText(sText);
|
|
}
|
|
|
|
m_dScale = 1.0;
|
|
int nPos = sText.Find(_T(':'));
|
|
if (nPos != -1)
|
|
{
|
|
m_dScale = _ttof(sText.Mid(nPos+1));
|
|
}
|
|
else
|
|
{
|
|
AfxMessageBox(_T("请选择图幅插入比例!"));
|
|
return;
|
|
}
|
|
|
|
OnOK();
|
|
}
|
|
|
|
void CInsertFrameDlg::OnNMClickListframes(NMHDR *pNMHDR, LRESULT *pResult)
|
|
{
|
|
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
|
|
if (pNMItemActivate != NULL)
|
|
{
|
|
if ( pNMItemActivate->iItem != -1)
|
|
{
|
|
|
|
}
|
|
}
|
|
*pResult = 0;
|
|
}
|