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

📄 swadddlg.cpp

📁 API经典入门
💻 CPP
字号:
// swadddlg.cpp : implementation file
//

#include "stdafx.h"
#include "swlister.h"
#include "swadddlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSWAddDlg dialog


CSWAddDlg::CSWAddDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSWAddDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSWAddDlg)
	m_strPhone = "";
	m_fPurchasePrice = 0;
	m_strPublisher = "";
	m_strRegistration = "";
	m_strTitle = "";
	m_bWinCompatible = FALSE;
	m_strPurchaseDate = "";
	//}}AFX_DATA_INIT
	
	m_pSW = NULL;

}

// If you are wondering why the following code is commented out, it is
// because I wrongly put it in here in the first place.  See the errata.txt
// file under chapter 7 for more information.  The errata is found in the 
// same compressed file that this source code was found.

//CSWAddDlg::~CSWAddDlg()
//{
	// empty CStrings
	//m_strPhone.Empty();
	//m_strPublisher.Empty();
	//m_strRegistration.Empty();
	//m_strTitle.Empty();
	//m_strPurchaseDate.Empty();
	
	// empty listboxes
	//while (m_ctlResolution.GetCount())
	//	m_ctlResolution.DeleteString(0);
	//while (m_ctlMedia.GetCount())
	//	m_ctlMedia.DeleteString(0);
	//while (m_ctlCategories.GetCount())
	//	m_ctlCategories.DeleteString(0);

//	CDialog::~CDialog();
//}

void CSWAddDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSWAddDlg)
	DDX_Control(pDX, IDC_Resolution, m_ctlResolution);
	DDX_Control(pDX, IDC_Rating, m_ctlRating);
	DDX_Control(pDX, IDC_Media, m_ctlMedia);
	DDX_Control(pDX, IDC_Categories, m_ctlCategories);
	DDX_Text(pDX, IDC_Phone, m_strPhone);
	DDX_Text(pDX, IDC_PurchasePrice, m_fPurchasePrice);
	DDX_Text(pDX, IDC_SWPublisher, m_strPublisher);
	DDX_Text(pDX, IDC_SWRegistration, m_strRegistration);
	DDX_Text(pDX, IDC_SWTitle, m_strTitle);
	DDX_Check(pDX, IDC_WinCompatible, m_bWinCompatible);
	DDX_Text(pDX, IDC_PurchaseDate, m_strPurchaseDate);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSWAddDlg, CDialog)
	//{{AFX_MSG_MAP(CSWAddDlg)
	ON_WM_VSCROLL()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CSWAddDlg message handlers

BOOL CSWAddDlg::OnInitDialog()
{
	if (m_pSW == NULL)
	{
		TRACE0("Dialog Aborting! Dialog's software product pointer is NULL!\n");
		EndDialog(IDCANCEL);
		return TRUE;
	}
	
	// initialize strings
	m_strTitle = m_pSW->m_strTitle;
	m_strPublisher = m_pSW->m_strPublisher;
	m_strRegistration = m_pSW->m_strRegistration;
	m_strPurchaseDate = m_pSW->m_strPurchaseDate;
	m_strPhone = m_pSW->m_strPhone;
	
	// initialize numbers
	m_fPurchasePrice = m_pSW->m_fPurchasePrice;
	m_bWinCompatible = m_pSW->m_bWinCompatible;
	
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here

	// multiple selection listbox initialization
	m_ctlMedia.AddString("3.5 inch HD disks");
	m_ctlMedia.AddString("3.5 inch DD disks");
	m_ctlMedia.AddString("5.25 inch HD disks");
	m_ctlMedia.AddString("5.25 inch DD disks");
	m_ctlMedia.AddString("CD ROM");
	
	POSITION Pos = m_pSW->m_lstMedia.GetHeadPosition();
	int nSelection;
	CString S;
	while (Pos != NULL)
	{
		S = m_pSW->m_lstMedia.GetNext(Pos);
		nSelection = m_ctlMedia.FindString(-1, S);
		if (nSelection != LB_ERR)
			m_ctlMedia.SetSel(nSelection);
	}
	
	// single selection listbox initialization
	m_ctlResolution.AddString("CGA");
	m_ctlResolution.AddString("EGA");
	m_ctlResolution.AddString("VGA");
	m_ctlResolution.AddString("Super VGA");
	m_ctlResolution.SelectString(-1, m_pSW->m_strResolution);
	
	// combo box selection initialization
	if (m_ctlCategories.SelectString(-1, m_pSW->m_strCategory) == CB_ERR)
	{
		int index = m_ctlCategories.AddString(m_pSW->m_strCategory);
		m_ctlCategories.SetCurSel (index);
	}

	// initialize scroll bar
	m_ctlRating.SetScrollRange(RATING_MIN, RATING_MAX);
	m_ctlRating.SetScrollPos(m_pSW->m_wRating);
	
	// initialize radio buttons
	int nRadioSel;
	switch (m_pSW->m_nJoystick)
	{
		case JRequired:
		nRadioSel = IDC_JoystickRequired;
		break;
		
		case JSupported:
		nRadioSel = IDC_JoystickSupported;
		break;
		
		default:
		nRadioSel = IDC_JoystickNotUsed;
		break;
	}
	
	CheckRadioButton(IDC_JoystickRequired, IDC_JoystickNotUsed, nRadioSel);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CSWAddDlg::OnOK()
{
	CString Temp;

	// retrieve scroll bar data
	m_pSW->m_wRating = m_ctlRating.GetScrollPos();
	
	// retrieve combo/list box data
	if (m_ctlResolution.GetCurSel() != LB_ERR)
		m_ctlResolution.GetText(m_ctlResolution.GetCurSel(), 
								m_pSW->m_strResolution);
	if (m_ctlCategories.GetCurSel() != CB_ERR)
		m_ctlCategories.GetLBText(m_ctlCategories.GetCurSel(),
								  m_pSW->m_strCategory);

	m_pSW->m_lstMedia.RemoveAll();
	for (int i = 0; i < m_ctlMedia.GetCount(); i++)
	{
		if (m_ctlMedia.GetSel(i) > 0)
		{
			m_ctlMedia.GetText(i, Temp);
			m_pSW->m_lstMedia.AddHead(Temp);
		}
			
	}
	
	CDialog::OnOK();
	
	// retrieve strings
	m_pSW->m_strTitle = m_strTitle;
	m_pSW->m_strPublisher = m_strPublisher;
	m_pSW->m_strRegistration = m_strRegistration;
	m_pSW->m_strPurchaseDate = m_strPurchaseDate;
	m_pSW->m_strPhone = m_strPhone;
	
	// retrieve numbers
	m_pSW->m_fPurchasePrice = m_fPurchasePrice;
	m_pSW->m_bWinCompatible = m_bWinCompatible;

	// retrieve & translate radio selection
	int nJS = GetCheckedRadioButton(IDC_JoystickRequired,
									IDC_JoystickNotUsed);
	switch(nJS)
	{
		case IDC_JoystickRequired:
		m_pSW->m_nJoystick = JRequired;
		break;
		
		case IDC_JoystickSupported:
		m_pSW->m_nJoystick = JSupported;
		break;  
		
		default:
		case IDC_JoystickNotUsed:
		m_pSW->m_nJoystick = JNot_Used;
		break;
	}
	
}

void CSWAddDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
	// TODO: Add your message handler code here and/or call default
	
	// if pScrollBar is NULL then its the window's scroll bar,
	// not a control per se.
	if (!pScrollBar)
		return;
	
	int nMin, nMax, nCurPos;
	pScrollBar->GetScrollRange(&nMin, &nMax);
	nCurPos = pScrollBar->GetScrollPos();
	
	switch (nSBCode)
	{
		case SB_LINEDOWN:
		case SB_PAGEDOWN:
		if (nCurPos < nMax)
			pScrollBar->SetScrollPos(nCurPos + 1);
		break;
		
		case SB_LINEUP:
		case SB_PAGEUP:
		if (nCurPos > nMin)
			pScrollBar->SetScrollPos(nCurPos - 1);
		break;
		
		case SB_THUMBPOSITION:
		TRACE0("THUMBPOSITION message\n");
		pScrollBar->SetScrollPos(nPos);
		break;
		
		case SB_THUMBTRACK:
		TRACE0("THUMBTRACK message\n");
		return;

		case SB_TOP:
		TRACE0("TOP message\n");
		return;

		case SB_BOTTOM:
		TRACE0("BOTTOM message\n");
		return;
		
		case SB_ENDSCROLL:
		TRACE0("ENDSCROLL message\n");
		return;
		
		default:
		TRACE0("other message\n");
		return;
	}
	
	TRACE("Min = %i; Max = %i; Current = %i.\n", nMin, nMax, nCurPos);
	
	CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}

⌨️ 快捷键说明

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