⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formvw1.cpp

📁 mfc internals 源码 mfc internals 源码
💻 CPP
字号:
// formvw1.cpp : implementation file
//

// This is a part of the Objective Grid C++ Library.
// Copyright (C) 1995 ClassWorks, Stefan Hoenig.
// All rights reserved.
//
// This source code is only intended as a supplement to
// the Objective Grid Classes Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding
// the Objective Grid product.
//

#include "stdafx.h"
#include "gridapp.h"
#include "formvw1.h"

#include "gridsdoc.h"

#ifndef _GXCTRL_H_
#include "gxctrl.h"
#endif

#ifndef _GXPRPDLG_H_
#include "gxprpdlg.h"
#endif

#ifndef _GXVW_H_
#include "gxvw.h"
#endif


#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSample1FormGridWnd grid control

// validation routine

BOOL CSample1FormGridWnd::OnValidateCell(ROWCOL nRow, ROWCOL nCol)
{
	CString s;

	// retrieve text from current cell
	CGXControl* pControl = GetControl(nRow, nCol);
	pControl->GetCurrentText(s);

	if (atol(s) < 0 || atol(s) > 100)
	{
		char sz[255];
		sprintf(sz, "Please enter a value between 0 and 100!");
		SetWarningText(sz);
		return FALSE;
	}

	return TRUE;
}

void CSample1FormGridWnd::OnInitialUpdate()
{
	CGXGridWnd::OnInitialUpdate();  // Creates all objects and links them to the grid

	GetParam()->EnableUndo(FALSE);

	SetRowCount(256);
	SetColCount(52);

	SetStyleRange(CGXRange(2, 2), CGXStyle()
			.SetControl(GX_IDS_CTRL_TEXTFIT)
			.SetChoiceList("one\ntwo\nthree\nfour\nfive\nsix\nseven\neight")
		);

	GetParam()->EnableUndo(TRUE);
}

BEGIN_MESSAGE_MAP(CSample1FormGridWnd, CGXGridWnd)
	//{{AFX_MSG_MAP(CSample1FormGridWnd)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSample1FormView

IMPLEMENT_DYNCREATE(CSample1FormView, CFormView)

CSample1FormView::CSample1FormView()
	: CFormView(CSample1FormView::IDD)
{
	//{{AFX_DATA_INIT(CSample1FormView)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

CSample1FormView::~CSample1FormView()
{
}

void CSample1FormView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSample1FormView)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP

	// validation routine for CGXGridWnd controls
	DDV_GXGridWnd(pDX, &m_wndGrid);
}


BEGIN_MESSAGE_MAP(CSample1FormView, CFormView)
	//{{AFX_MSG_MAP(CSample1FormView)
	ON_COMMAND(ID_FILE_HEADERFOOTER, OnFileHeaderfooter)
	ON_COMMAND(ID_FILE_PAGE_SETUP, OnFilePageSetup)
	ON_COMMAND(ID_VIEW_PROPERTIES, OnViewProperties)
	//}}AFX_MSG_MAP
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()



/////////////////////////////////////////////////////////////////////////////
// CSample1FormView diagnostics

#ifdef _DEBUG
void CSample1FormView::AssertValid() const
{
	CFormView::AssertValid();
}

void CSample1FormView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSample1FormView message handlers

void CSample1FormView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();

	m_wndGrid.SubclassDlgItem(IDC_FORMVW1_GRIDWND, this);

	m_wndGrid.Initialize();

	m_wndGrid.SetFocus();
}

BOOL CSample1FormView::OnPreparePrinting(CPrintInfo* pInfo)
{
	pInfo->SetMaxPage(0xffff);

	pInfo->m_pPD->m_pd.Flags &= ~PD_NOSELECTION;
	pInfo->m_pPD->m_pd.hInstance = AfxGetInstanceHandle();

	// default preparation
	return DoPreparePrinting(pInfo);
}

void CSample1FormView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	m_wndGrid.OnBeginPrinting(pDC, pInfo);
}

void CSample1FormView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	m_wndGrid.OnEndPrinting(pDC, pInfo);
}

void CSample1FormView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
	m_wndGrid.OnPrint(pDC, pInfo);
}


void CSample1FormView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo /* = NULL */)
{
	if (pInfo)
	{
		// Adjust printer DC
		pDC->SetMapMode(MM_ANISOTROPIC);
		pDC->SetWindowExt(96, 96);

		int nlogx = pDC->GetDeviceCaps(LOGPIXELSX);
		int nlogy = pDC->GetDeviceCaps(LOGPIXELSY);

		pDC->SetViewportExt(nlogx, nlogy);

		// Mapping: 72 pixels/unit (like MM_TEXT)
	}
}

/////////////////////////////////////////////////////////////////////////////
// View menu handlers

void CSample1FormView::OnViewProperties()
{
	BOOL bSaveDefault = FALSE;

	CGXProperties* pPropertyObj = m_wndGrid.GetParam()->GetProperties();
	ASSERT(pPropertyObj->IsKindOf(RUNTIME_CLASS(CGXProperties)));

	CGXProperties* pNewSettings = new CGXProperties;
	*pNewSettings = *pPropertyObj;

	CGXDisplayPropertiesDialog dlg(pNewSettings, m_wndGrid.GetParam()->GetStylesMap(), &bSaveDefault, FALSE);

	int result = dlg.DoModal();
	if (result == IDOK)
	{
		*pPropertyObj = *pNewSettings;
		if (bSaveDefault)
			pPropertyObj->WriteProfile();

		// SetModifiedFlag();
		m_wndGrid.Redraw();
	}

	delete pNewSettings;
}

/////////////////////////////////////////////////////////////////////////////
// File menu handlers

void CSample1FormView::OnFilePageSetup()
{
	BOOL bSaveDefault = FALSE;

	CGXProperties* pPropertyObj = m_wndGrid.GetParam()->GetProperties();
	ASSERT(pPropertyObj->IsKindOf(RUNTIME_CLASS(CGXProperties)));

	CGXProperties* pNewSettings = new CGXProperties;
	*pNewSettings = *pPropertyObj;

	CGXPrintPropertiesDialog  dlg(pNewSettings, m_wndGrid.GetParam()->GetStylesMap(), &bSaveDefault, FALSE);

	int result = dlg.DoModal();
	if (result == IDOK)
	{
		*pPropertyObj = *pNewSettings;
		if (bSaveDefault)
			pPropertyObj->WriteProfile();

		// SetModifiedFlag();
	}

	delete pNewSettings;
}

void CSample1FormView::OnFileHeaderfooter()
{
	BOOL bSaveDefault = FALSE;

	CGXProperties* pPropertyObj = m_wndGrid.GetParam()->GetProperties();
	ASSERT(pPropertyObj->IsKindOf(RUNTIME_CLASS(CGXProperties)));

	CGXProperties* pNewSettings = new CGXProperties;
	*pNewSettings = *pPropertyObj;

	CGXHeaderFooterDialog dlg(pNewSettings, &bSaveDefault);

	int result = dlg.DoModal();
	if (result == IDOK)
	{
		*pPropertyObj = *pNewSettings;
		if (bSaveDefault)
			pPropertyObj->WriteProfile();

		// SetModifiedFlag();
	}

	delete pNewSettings;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -