////////////////////////////////////////////////////////////////////////////// //文件: CPrintPageSetup.cpp //主要功能: // //程序编写: 2006-12-07 // // ///////////////////////////////////////////////////////////////////////////// // PrintPageSetup.cpp : 实现文件 // #include "stdafx.h" //#include "DFDrawPro.h" #include "PrintPageSetup.h" // CPrintPageSetup 对话框 IMPLEMENT_DYNAMIC(CPrintPageSetup, CPropertyPage) CPrintPageSetup::CPrintPageSetup() : CPropertyPage(CPrintPageSetup::IDD) , m_bExtendScreen(FALSE) , m_nScreenSel(0) , m_bPartition(FALSE) , m_nPartitionIdea(0) , m_nSuperpositionWidth(10) , m_bMulline(FALSE) , m_nMullineIdea(0) , m_nMullineNum(2) , m_bCenterDocument(FALSE) , m_nMarginTop(0) , m_nMarginBottom(0) , m_nMarginLeft(0) , m_nMarginRight(0) , m_nSideSel(0) , m_nAliginSel(1) , m_nMarginX(0) , m_nMarginY(0) , m_strLabel(_T("1")) , m_bPreview(FALSE) { } CPrintPageSetup::~CPrintPageSetup() { } void CPrintPageSetup::DoDataExchange(CDataExchange* pDX) { CPropertyPage::DoDataExchange(pDX); DDX_Check(pDX, IDC_CHECK_PRINT_PAGE_EXTEND, m_bExtendScreen); DDX_Radio(pDX, IDC_RADIO_PRINT_PAGE_VIEW, m_nScreenSel); DDX_Check(pDX, IDC_CHECK_PRINT_PAGE_PARTITION, m_bPartition); DDX_CBIndex(pDX, IDC_COMBO_PRINT_PAGE_PARTITION_IDEA, m_nPartitionIdea); DDX_Text(pDX, IDC_EDIT_PRINT_PAGE_SUPERPOSITION_WIDTH, m_nSuperpositionWidth); DDX_Check(pDX, IDC_CHECK_PRINT_PAGE_MULLINE, m_bMulline); DDX_CBIndex(pDX, IDC_COMBO_PRINT_PAGE_MULLINE_IDEA, m_nMullineIdea); DDX_Text(pDX, IDC_EDIT_PRINT_PAGE_MULLINE_NUM, m_nMullineNum); DDX_Text(pDX, IDC_EDIT_PRINT_PAGE_TOP, m_nMarginTop); DDX_Text(pDX, IDC_EDIT_PRINT_PAGE_BOTTOM, m_nMarginBottom); DDX_Text(pDX, IDC_EDIT_PRINT_PAGE_LEFT, m_nMarginLeft); DDX_Text(pDX, IDC_EDIT_PRINT_PAGE_RIGHT, m_nMarginRight); DDX_CBIndex(pDX, IDC_COMBO_PRINT_PAGE_PageNumberSide, m_nSideSel); DDX_CBIndex(pDX, IDC_COMBO_PRINT_PAGE_PageNumberIdea, m_nAliginSel); DDX_Text(pDX, IDC_EDIT_PRINT_PAGE_PageFrameX, m_nMarginX); DDX_Text(pDX, IDC_EDIT_PRINT_PAGE_PageFrameY, m_nMarginY); DDX_CBString(pDX, IDC_COMBO_PRINT_PAGE_PageNumber, m_strLabel); DDX_Check(pDX, IDC_CHECK_PRINT_PAGE_CENTER, m_bCenterDocument); } BEGIN_MESSAGE_MAP(CPrintPageSetup, CPropertyPage) ON_BN_CLICKED(IDC_BUTTON_PRINT_PAGE_PageNumberFont, OnBnClickedButtonPrintPagePagenumberfont) ON_BN_CLICKED(IDC_CHECK_PRINT_PAGE_EXTEND, OnBnClickedCheckPrintPageExtend) ON_BN_CLICKED(IDC_CHECK_PRINT_PAGE_PARTITION, OnBnClickedCheckPrintPagePartition) ON_BN_CLICKED(IDC_CHECK_PRINT_PAGE_MULLINE, OnBnClickedCheckPrintPageMulline) ON_CBN_SELCHANGE(IDC_COMBO_PRINT_PAGE_PageNumberSide, OnCbnSelchangeComboPrintPagePagenumberside) ON_BN_CLICKED(IDC_BUTTON_PRINT_PAGE_PREVIEW, OnBnClickedButtonPrintPagePreview) ON_BN_CLICKED(IDC_BUTTON_PRINT_PAGE_SET_DEFAULT, OnBnClickedButtonPrintPageSetDefault) ON_BN_CLICKED(IDC_CHECK_PRINT_PAGE_CENTER, OnBnClickedCheckPrintPageCenterDocument) END_MESSAGE_MAP() // CPrintPageSetup 消息处理程序 BOOL CPrintPageSetup::OnInitDialog() { CPropertyPage::OnInitDialog(); SetSpinRange(IDC_SPIN_PRINT_PAGE_SUPERPOSITION_WIDTH); SetSpinRange(IDC_SPIN_PRINT_PAGE_MULLINE_NUM); SetSpinRange(IDC_SPIN_PRINT_PAGE_TOP); SetSpinRange(IDC_SPIN_PRINT_PAGE_BOTTOM); SetSpinRange(IDC_SPIN_PRINT_PAGE_LEFT); SetSpinRange(IDC_SPIN_PRINT_PAGE_RIGHT); EnableExtend(); EnableMulline(); EnablePartition(); EnablePageNumber(); return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE } void CPrintPageSetup::SetSpinRange(UINT nID) { CSpinButtonCtrl* pSpin=(CSpinButtonCtrl*)GetDlgItem(nID); if(pSpin==NULL) return; pSpin->SetBase(0); pSpin->SetRange(0, 5000); } void CPrintPageSetup::OnBnClickedButtonPrintPagePagenumberfont() { UpdateData(); CFontDialog dlg(&m_lfPageNumberFont); if(dlg.DoModal()!=IDOK) return; dlg.GetCurrentFont(&m_lfPageNumberFont); UpdateData(FALSE); } void CPrintPageSetup::OnBnClickedButtonPrintPagePreview() { UpdateData(); m_bPreview=TRUE; ((CPropertySheet*)GetParent())->EndDialog(IDOK); } void CPrintPageSetup::OnBnClickedButtonPrintPageSetDefault() { UpdateData(); //Write(::GetDrawINI()); } void CPrintPageSetup::OnBnClickedCheckPrintPageExtend() { UpdateData(); EnableExtend(); if(m_bExtendScreen) { m_bCenterDocument=FALSE; m_bPartition=FALSE; m_bMulline=FALSE; EnablePartition(); EnableMulline(); } UpdateData(FALSE); } void CPrintPageSetup::OnBnClickedCheckPrintPagePartition() { UpdateData(); EnablePartition(); if(m_bPartition) { m_bCenterDocument=FALSE; m_bExtendScreen=FALSE; EnableExtend(); } UpdateData(FALSE); } void CPrintPageSetup::OnBnClickedCheckPrintPageCenterDocument() { UpdateData(); if(m_bCenterDocument) { m_bExtendScreen=FALSE; EnableExtend(); m_bPartition=FALSE; m_bMulline=FALSE; EnablePartition(); EnableMulline(); } UpdateData(FALSE); } void CPrintPageSetup::OnBnClickedCheckPrintPageMulline() { UpdateData(); EnableMulline(); if(m_bMulline) { m_bExtendScreen=FALSE; EnableExtend(); } UpdateData(FALSE); } void CPrintPageSetup::OnCbnSelchangeComboPrintPagePagenumberside() { UpdateData(); EnablePageNumber(); } void CPrintPageSetup::EnablePageNumber(void) { BOOL be=FALSE; if(m_nSideSel>0) be=TRUE; GetDlgItem(IDC_COMBO_PRINT_PAGE_PageNumberIdea)->EnableWindow(be); GetDlgItem(IDC_EDIT_PRINT_PAGE_PageFrameX)->EnableWindow(be); GetDlgItem(IDC_EDIT_PRINT_PAGE_PageFrameY)->EnableWindow(be); GetDlgItem(IDC_COMBO_PRINT_PAGE_PageNumber)->EnableWindow(be); GetDlgItem(IDC_BUTTON_PRINT_PAGE_PageNumberFont)->EnableWindow(be); } void CPrintPageSetup::EnableExtend(void) { GetDlgItem(IDC_RADIO_PRINT_PAGE_VIEW)->EnableWindow(m_bExtendScreen); GetDlgItem(IDC_RADIO_PRINT_PAGE_VIEW2)->EnableWindow(m_bExtendScreen); } void CPrintPageSetup::EnablePartition(void) { GetDlgItem(IDC_COMBO_PRINT_PAGE_PARTITION_IDEA)->EnableWindow(m_bPartition); GetDlgItem(IDC_EDIT_PRINT_PAGE_SUPERPOSITION_WIDTH)->EnableWindow(m_bMulline|m_bPartition); GetDlgItem(IDC_SPIN_PRINT_PAGE_SUPERPOSITION_WIDTH)->EnableWindow(m_bMulline|m_bPartition); } void CPrintPageSetup::EnableMulline(void) { GetDlgItem(IDC_COMBO_PRINT_PAGE_MULLINE_IDEA)->EnableWindow(m_bMulline); GetDlgItem(IDC_EDIT_PRINT_PAGE_MULLINE_NUM)->EnableWindow(m_bMulline); GetDlgItem(IDC_SPIN_PRINT_PAGE_MULLINE_NUM)->EnableWindow(m_bMulline); GetDlgItem(IDC_EDIT_PRINT_PAGE_SUPERPOSITION_WIDTH)->EnableWindow(m_bMulline|m_bPartition); GetDlgItem(IDC_SPIN_PRINT_PAGE_SUPERPOSITION_WIDTH)->EnableWindow(m_bMulline|m_bPartition); } void CPrintPageSetup::InitFont(LOGFONT& font) { font.lfHeight=0; font.lfWidth=0; font.lfEscapement=0; font.lfOrientation=0; font.lfWeight=FW_NORMAL;//FW_THIN; font.lfItalic=0; font.lfUnderline=0; font.lfStrikeOut=0; font.lfCharSet=DEFAULT_CHARSET; font.lfOutPrecision=OUT_DEFAULT_PRECIS; font.lfClipPrecision=CLIP_LH_ANGLES; font.lfQuality=DEFAULT_QUALITY; font.lfPitchAndFamily=DEFAULT_PITCH; sprintf(font.lfFaceName, "Times New Roman\0"); } void CPrintPageSetup::Read(LPCTSTR iniFile) { CFileIni ini; ini.SetFileName(iniFile); CString section=_T("PageSetup"); ini.Read(section,"ExtendScreen",m_bExtendScreen); ini.Read(section,"ScreenSel",m_nScreenSel); ini.Read(section,"Partition",m_bPartition); ini.Read(section,"PartitionIdea",m_nPartitionIdea); ini.Read(section,"Superposition",m_nSuperpositionWidth); ini.Read(section,"Mulline",m_bMulline); ini.Read(section,"MullineIdea",m_nMullineIdea); ini.Read(section,"MullineNum",m_nMullineNum); ini.Read(section,"CenterMap",m_bCenterDocument); ini.Read(section,"MarginTop",m_nMarginTop); ini.Read(section,"MarginBottom",m_nMarginBottom); ini.Read(section,"MarginLeft",m_nMarginLeft); ini.Read(section,"MarginRight",m_nMarginRight); ini.Read(section,"Side",m_nSideSel); ini.Read(section,"Aligin",m_nAliginSel); ini.Read(section,"MarginX",m_nMarginX); ini.Read(section,"MarginY",m_nMarginY); ini.Read(section,"Label",m_strLabel); InitFont(m_lfPageNumberFont); LOGFONT &font=m_lfPageNumberFont; CString value; ini.Read(section,"Font",value); sscanf(value, "%ld %ld %ld %ld %ld %hhu %hhu %hhu %hhu %hhu %hhu %hhu %hhu", &font.lfHeight,&font.lfWidth,&font.lfEscapement,&font.lfOrientation,&font.lfWeight,&font.lfItalic,&font.lfUnderline, &font.lfStrikeOut,&font.lfCharSet,&font.lfOutPrecision,&font.lfClipPrecision,&font.lfQuality,&font.lfPitchAndFamily); ini.Read(section,"FontName",value); sprintf(font.lfFaceName, "%s", (LPCSTR)value); } void CPrintPageSetup::Write(LPCTSTR iniFile) { CFileIni ini; ini.SetFileName(iniFile); CString section=_T("PageSetup"); ini.Write(section,"ExtendScreen",m_bExtendScreen); ini.Write(section,"ScreenSel",m_nScreenSel); ini.Write(section,"Partition",m_bPartition); ini.Write(section,"PartitionIdea",m_nPartitionIdea); ini.Write(section,"Superposition",m_nSuperpositionWidth); ini.Write(section,"Mulline",m_bMulline); ini.Write(section,"MullineIdea",m_nMullineIdea); ini.Write(section,"MullineNum",m_nMullineNum); ini.Write(section,"CenterMap",m_bCenterDocument); ini.Write(section,"MarginTop",m_nMarginTop); ini.Write(section,"MarginBottom",m_nMarginBottom); ini.Write(section,"MarginLeft",m_nMarginLeft); ini.Write(section,"MarginRight",m_nMarginRight); ini.Write(section,"Side",m_nSideSel); ini.Write(section,"Aligin",m_nAliginSel); ini.Write(section,"MarginX",m_nMarginX); ini.Write(section,"MarginY",m_nMarginY); ini.Write(section,"Label",m_strLabel); LOGFONT &font=m_lfPageNumberFont; CString sf; sf.Format("%ld %ld %ld %ld %ld %d %d %d %d %d %d %d %d", font.lfHeight,font.lfWidth,font.lfEscapement,font.lfOrientation,font.lfWeight,font.lfItalic,font.lfUnderline, font.lfStrikeOut,font.lfCharSet,font.lfOutPrecision,font.lfClipPrecision,font.lfQuality,font.lfPitchAndFamily); ini.Write(section,"Font",sf); ini.Write(section,"FontName",font.lfFaceName); }