www.pudn.com > Multilines_demo.zip > multilinesDlg.cpp


// multilinesDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "multilines.h" 
#include "multilinesDlg.h" 
#include ".\multilinesdlg.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#endif 
 
 
// CmultilinesDlg dialog 
 
 
 
CmultilinesDlg::CmultilinesDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CmultilinesDlg::IDD, pParent) 
{ 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
} 
 
void CmultilinesDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	DDX_Control(pDX, IDC_LIST_DEFAULT, m_list_default); 
	DDX_Control(pDX, IDC_LIST_MULTI, m_list_multi); 
	DDX_Control(pDX, IDC_EDIT, m_edit); 
	DDX_Control(pDX, IDC_ROW, m_row); 
	DDX_Control(pDX, IDC_COL, m_col); 
	DDX_Control(pDX, IDC_SC_ROW, m_sc_row); 
	DDX_Control(pDX, IDC_SC_COL, m_sc_col); 
} 
 
BEGIN_MESSAGE_MAP(CmultilinesDlg, CDialog) 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	//}}AFX_MSG_MAP 
	ON_BN_CLICKED(IDC_PREV, OnBnClickedPrev) 
	ON_BN_CLICKED(IDC_NEXT, OnBnClickedNext) 
	ON_BN_CLICKED(IDC_INSERT, OnBnClickedInsert) 
	ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SC_COL, OnNMReleasedcaptureScCol) 
	ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SC_ROW, OnNMReleasedcaptureScRow) 
END_MESSAGE_MAP() 
 
 
// CmultilinesDlg message handlers 
 
BOOL CmultilinesDlg::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
 
	// Set the icon for this dialog.  The framework does this automatically 
	//  when the application's main window is not a dialog 
	SetIcon(m_hIcon, TRUE);			// Set big icon 
	SetIcon(m_hIcon, FALSE);		// Set small icon 
 
	// TODO: Add extra initialization here 
	int i; 
	CString str; 
	m_default = true; 
	m_sc_col.SetRange(0,2); 
	m_sc_row.SetRange(0,9); 
	m_list_default.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT); 
	m_list_default.SetBkColor(RGB(236,233,216)); 
	m_list_multi.SetExtendedStyle(LVS_EX_FULLROWSELECT); 
	m_list_multi.ShowWindow(false); 
	m_list_multi.SetBkColor(RGB(236,233,216)); 
	for (i=0; i<3; i++) { 
		str.Format("Column %d",i); 
		m_list_default.InsertColumn(i,str,LVCFMT_LEFT,100); 
		m_list_multi.InsertColumn(i,str,LVCFMT_LEFT,100); 
	} 
	for (i=0; i<10; i++) { 
        m_list_default.InsertItem(i,""); 
		m_list_multi.InsertItem(i,""); 
	} 
	m_list_default.SetItemText(0,0,"Test1"); 
	m_list_multi.SetItemText(0,0,"Test1"); 
	m_list_default.SetItemText(0,1,"Test1\r\nTest2"); 
	m_list_multi.SetItemText(0,1,"Test1\r\nTest2"); 
	m_list_default.SetItemText(0,2,"Test1\r\nTest2\r\nTest3"); 
	m_list_multi.SetItemText(0,2,"Test1\r\nTest2\r\nTest3"); 
	m_sc_row.SetPos(1); 
	m_row.SetWindowText("1"); 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
// If you add a minimize button to your dialog, you will need the code below 
//  to draw the icon.  For MFC applications using the document/view model, 
//  this is automatically done for you by the framework. 
 
void CmultilinesDlg::OnPaint()  
{ 
	if (IsIconic()) 
	{ 
		CPaintDC dc(this); // device context for painting 
 
		SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); 
 
		// Center icon in client rectangle 
		int cxIcon = GetSystemMetrics(SM_CXICON); 
		int cyIcon = GetSystemMetrics(SM_CYICON); 
		CRect rect; 
		GetClientRect(&rect); 
		int x = (rect.Width() - cxIcon + 1) / 2; 
		int y = (rect.Height() - cyIcon + 1) / 2; 
 
		// Draw the icon 
		dc.DrawIcon(x, y, m_hIcon); 
	} 
	else 
	{ 
		CDialog::OnPaint(); 
	} 
} 
 
// The system calls this function to obtain the cursor to display while the user drags 
//  the minimized window. 
HCURSOR CmultilinesDlg::OnQueryDragIcon() 
{ 
	return static_cast(m_hIcon); 
} 
 
void CmultilinesDlg::OnBnClickedPrev() 
{ 
	// TODO: Add your control notification handler code here 
	m_list_default.ShowWindow(true); 
	m_list_multi.ShowWindow(false); 
	m_default = true; 
} 
 
void CmultilinesDlg::OnBnClickedNext() 
{ 
	// TODO: Add your control notification handler code here 
	m_list_multi.ShowWindow(true); 
	m_list_default.ShowWindow(false); 
	m_default = false; 
} 
 
void CmultilinesDlg::OnBnClickedInsert() 
{ 
	// TODO: Add your control notification handler code here 
	CString str; 
	m_list_multi.CloseAll(); 
	m_edit.GetWindowText(str); 
	m_list_default.SetItemText(m_sc_row.GetPos(),m_sc_col.GetPos(),str); 
	m_list_multi.SetItemText(m_sc_row.GetPos(),m_sc_col.GetPos(),str); 
	if (m_sc_col.GetPos()==m_sc_col.GetRangeMax()) { 
		m_sc_col.SetPos(0); 
		if (m_sc_row.GetPos()==m_sc_row.GetRangeMax()) 
			m_sc_row.SetPos(0); 
		else 
			m_sc_row.SetPos(m_sc_row.GetPos()+1); 
	} 
	else 
		m_sc_col.SetPos(m_sc_col.GetPos()+1); 
 
	str.Format("%d",m_sc_col.GetPos()); 
	m_col.SetWindowText(str); 
	str.Format("%d",m_sc_row.GetPos()); 
	m_row.SetWindowText(str); 
 
	m_edit.SetWindowText(""); 
	m_edit.SetFocus(); 
	Invalidate(); 
} 
 
void CmultilinesDlg::OnNMReleasedcaptureScCol(NMHDR *pNMHDR, LRESULT *pResult) 
{ 
	// TODO: Add your control notification handler code here 
	CString str; 
	str.Format("%d",m_sc_col.GetPos()); 
	m_col.SetWindowText(str); 
	*pResult = 0; 
} 
 
void CmultilinesDlg::OnNMReleasedcaptureScRow(NMHDR *pNMHDR, LRESULT *pResult) 
{ 
	// TODO: Add your control notification handler code here 
	CString str; 
	str.Format("%d",m_sc_row.GetPos()); 
	m_row.SetWindowText(str); 
	*pResult = 0; 
}