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

📄 pcdmview.cpp

📁 《Windows CE 权威指南》(作者:(美)CHRIS MUENCH
💻 CPP
字号:
// PCDMView.cpp : implementation of the CPCDMView class
//

#include "stdafx.h"
#include "PCDM.h"

#include "PCDMDoc.h"
#include "PCDMView.h"

//<BOOK_ADDON STEP5 Chapter 7.4.4> *********************************
#include "details.h"
#include "finddlg.h"
//</BOOK_ADDON STEP5 Chapter 7.4.4> *********************************

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPCDMView

IMPLEMENT_DYNCREATE(CPCDMView, CFormView)

BEGIN_MESSAGE_MAP(CPCDMView, CFormView)
	//{{AFX_MSG_MAP(CPCDMView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPCDMView construction/destruction

CPCDMView::CPCDMView()
	: CFormView(CPCDMView::IDD)  // <BOOK_ADDON Step2 Chapter 7.1.4/> **********
{
//<BOOK_ADDON STEP5 Chapter 7.4.4> *********************************
	m_LastRow=-1;
	m_SearchString[0]=0;
//</BOOK_ADDON STEP5 Chapter 7.4.4> *********************************
}

CPCDMView::~CPCDMView()
{
}

BOOL CPCDMView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CPCDMView drawing

void CPCDMView::OnDraw(CDC* pDC)
{
	CPCDMDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CPCDMView diagnostics

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

void CPCDMView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CPCDMDoc* CPCDMView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPCDMDoc)));
	return (CPCDMDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CPCDMView message handlers

// <BOOK_ADDON Step2 Chapter 7.1.4> **********************************************
void CPCDMView::DoDataExchange(CDataExchange* pDX) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPCDMView)
	DDX_Control(pDX, IDC_COMMANDER, m_cmdBar);
	DDX_Control(pDX, IDC_PCDMLIST, m_LVC);
	//}}AFX_DATA_MAP
}

BEGIN_EVENTSINK_MAP(CPCDMView, CFormView)
    //{{AFX_EVENTSINK_MAP(CPCDMView)
	ON_EVENT(CPCDMView, IDC_COMMANDER, 1 /* CmdBarAction */, OnCmdBarActionCommander, VTS_I4 VTS_BSTR)
	ON_EVENT(CPCDMView, IDC_PCDMLIST, 1 /* RowSelected */, OnRowSelected, VTS_I4 VTS_I4 VTS_I4)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CPCDMView::OnCmdBarActionCommander(long ID, LPCTSTR text) 
{
//<BOOK_ADDON STEP5 Chapter 7.4.4> *********************************
	switch (ID)
	{
		case 31:
			if (m_LastRow!=-1)
			{
				CDetails *dlg;
				int plat;

		 		plat=LOWORD(((CPCDMApp *)AfxGetApp())->m_CePlatform);
				if (plat>=CEP_PALMPC && plat<CEP_PALMPCEND)
					dlg=new CDetails(IDD_CDDETAILSPALM,m_LastRow);
				else
					dlg=new CDetails(IDD_CDDETAILS,m_LastRow);					
				dlg->DoModal();
				delete dlg;
			}
		  break;
		case 32:
			{
			LONG Result=0,tRes=0;
			LV_FINDINFO FindIt;

				if (m_SearchString[0]==0)
				{
					CFindDlg *dlg;
					dlg=new CFindDlg();
					dlg->DoModal();
					wsprintf(m_SearchString,dlg->m_FindString);
					if (m_SearchString[0]==0)
						break;
				}
				memset(&FindIt,0,sizeof(FindIt));
				FindIt.flags=LVFI_PARTIAL;
				FindIt.psz=m_SearchString;
				Result=m_LVC.SendCommand(LVM_FINDITEM,0,(long)&FindIt);
				if (Result>=0)
				{
					tRes=m_LVC.SendCommand(LVM_ENSUREVISIBLE,Result,FALSE);
					LV_ITEM lvi;
					memset(&lvi,0,sizeof(lvi));
					lvi.stateMask=0x000F;
					lvi.state=LVIS_FOCUSED | LVIS_SELECTED;
					tRes=m_LVC.SendCommand(LVM_SETITEMSTATE ,Result,(long)&lvi);
					tRes=m_LVC.SendCommand(LVM_UPDATE ,Result,0);
					Result=tRes;
				}
			}
		  break;
		case 1007:
			wsprintf(m_SearchString,text);
		  break;
		case IDCLOSE:
			GetParentFrame()->DestroyWindow();
		  break;
		default:
		  break;
	}
//</BOOK_ADDON STEP5 Chapter 7.4.4> *********************************
}

void CPCDMView::OnInitialUpdate() 
{
	CFormView::OnInitialUpdate();
	
// Sizes the IDD_MAINFORM Dialog to the size of the Mainframe
	CRect myRect;
	GetParentFrame()->GetClientRect(&myRect);
	SetWindowPos(NULL,myRect.left,myRect.top,
                 myRect.right,myRect.bottom,SWP_NOZORDER);
//<BOOK_ADDON STEP5 Chapter 7.4.4> *********************************
	if (LOWORD(((CPCDMApp *)AfxGetApp())->m_CePlatform)==CEP_PALMPCV3)
		m_cmdBar.SetWindowPos(NULL,myRect.top,myRect.left,
                            myRect.right,1,SWP_NOZORDER);
	else  
//</BOOK_ADDON STEP5 Chapter 7.4.4> *********************************
		m_cmdBar.SetWindowPos(NULL,myRect.top,myRect.left,
                            myRect.right,25,SWP_NOZORDER);

	// Creates our Command-Bar
//<BOOK_ADDON STEP3 Chapter 7.2.4> *********************************
	m_cmdBar.SetCmdBarType(1);
	m_cmdBar.CreateBar(1,0);
//</BOOK_ADDON STEP3 Chapter 7.2.4> *********************************

	// Inserts Menus
	m_cmdBar.InsertMenu(TEXT("File"),0);
	m_cmdBar.InsertMenuItem(TEXT("Send to..")	,0,0,30);
	m_cmdBar.InsertMenuItem(TEXT("Receive..")	,0,1,36);	
	m_cmdBar.InsertMenuItem(TEXT("Show Details"),0,2,31);
	m_cmdBar.InsertMenuItem(TEXT("")			,0,3,0);
	m_cmdBar.InsertMenuItem(TEXT("Help")		,0,4,34);
	m_cmdBar.InsertMenuItem(TEXT("About")		,0,5,35);
	m_cmdBar.InsertMenuItem(TEXT("")			,0,6,0);
	m_cmdBar.InsertMenuItem(TEXT("Exit")		,0,7,IDCLOSE);

//<BOOK_ADDON STEP3 Chapter 7.2.4> *********************************
	m_cmdBar.CreateBar(101,RBBS_FIXEDBMP);
	// <BOOK_ADDON STEP4 Chapter 7.3.4/>
	if (LOWORD(((CPCDMApp *)AfxGetApp())->m_CePlatform)!=CEP_PALMPCV3)
// </BOOK_ADDON STEP4 Chapter 7.3.4/>
		m_cmdBar.InsertButton(SBM_SEP,TBSTATE_ENABLED,	0,0, TEXT(""));
//</BOOK_ADDON STEP3 Chapter 7.2.4> *********************************
	// Inserts Toolbar Buttons
	m_cmdBar.InsertButton(SBM_SEND,TBSTATE_ENABLED,	1,30,
                            TEXT("Send Entry to other Device"));
	m_cmdBar.InsertButton(SBM_OPEN,TBSTATE_ENABLED, 2,31,
                            TEXT("Show Details"));
	m_cmdBar.InsertButton(SBM_SEP,TBSTATE_ENABLED,	3,0, 
                            TEXT(""));
	m_cmdBar.InsertButton(SBM_FIND,TBSTATE_ENABLED,	4,32,
                            TEXT("Search for CD"));
	m_cmdBar.InsertButton(SBM_SEP,TBSTATE_ENABLED, 5,0, 
                            TEXT(""));
	m_cmdBar.InsertButton(SBM_HELP,TBSTATE_ENABLED,6,34,
                            TEXT("Help"));
	m_cmdBar.InsertButton(SBM_PROP,TBSTATE_ENABLED,7,35,
                            TEXT("About"));	

	// Inserts the Search Combo Box
	m_cmdBar.InsertComboBox(100,4,1007);	
	m_cmdBar.AddStringToComboBox(1007,TEXT("Madonna"));
//</BOOK_ADDON STEP3 Chapter 7.2.4> *********************************

	// Adds the Close Button
	m_cmdBar.SetAdornments(0);			
// </BOOK_ADDON Step2 Chapter 7.1.4> **********************************************

//<BOOK_ADDON STEP5 Chapter 7.4.4> *********************************
	if (LOWORD(((CPCDMApp *)AfxGetApp())->m_CePlatform)==CEP_PALMPCV3)
		m_LVC.SetWindowPos(NULL,5,0,myRect.right-10,
							myRect.bottom-5,SWP_NOZORDER);
	else
		m_LVC.SetWindowPos(NULL,5,30,myRect.right-10,
							myRect.bottom-35,SWP_NOZORDER);
	// Column for Author (Half the screen )
	m_LVC.AddColumn((myRect.right/2),TEXT("Artist/Author")); 
	// Column for Title (Half the screen)
	m_LVC.AddColumn((myRect.right/2)-14,TEXT("Title"));
//</BOOK_ADDON STEP5 Chapter 7.4.4> *********************************
}

//<BOOK_ADDON STEP5 Chapter 7.4.4> *********************************
void CPCDMView::OnRowSelected(long Row, long Column, long lParam) 
{
CDetails *dlg;
int plat;

	if (lParam==m_LastRow)
	{
	    plat=LOWORD(((CPCDMApp *)AfxGetApp())->m_CePlatform);
		if (plat>=CEP_PALMPC && plat<CEP_PALMPCEND)
			dlg=new CDetails(IDD_CDDETAILSPALM, lParam);
		else
			dlg=new CDetails(IDD_CDDETAILS, lParam);
		dlg->DoModal();	
	}
	m_LastRow=lParam;
}
//</BOOK_ADDON STEP5 Chapter 7.4.4> *********************************

⌨️ 快捷键说明

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