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

📄 listctrlpop.cpp

📁 进销存管理系统介绍了企业的现状以及进销存数据管理系统的特点、功能和使用对象
💻 CPP
字号:
// ListCtrlPop.cpp : implementation file
//

#include "stdafx.h"
#include "a1.h"
#include "ListCtrlPop.h"
#include "BaseList.h"


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

/////////////////////////////////////////////////////////////////////////////
// CListCtrlPop dialog


CListCtrlPop::CListCtrlPop(CWnd* pParent /*=NULL*/)
	: CDialog(CListCtrlPop::IDD, pParent)
{
	//{{AFX_DATA_INIT(CListCtrlPop)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_listctrl=new CListCtrl;
}


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


BEGIN_MESSAGE_MAP(CListCtrlPop, CDialog)
	//{{AFX_MSG_MAP(CListCtrlPop)
	ON_NOTIFY(NM_DBLCLK, ID_POP_LISTCTRL, OnDblclkList1)
	ON_WM_SHOWWINDOW()
	ON_NOTIFY(NM_SETFOCUS, ID_POP_LISTCTRL, OnSetfocusList1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CListCtrlPop message handlers

void CListCtrlPop::OnOK() 
{
	this->SetStrWindowText();
}

void CListCtrlPop::OnCancel() 
{
	if(m_wndStrEdited!=NULL)
	{
		m_wndStrEdited->SetFocus();
		this->m_wndStrEdited->PostMessage(WM_KEYDOWN,27,0);
	}
//	this->ShowWindow(SW_HIDE);
}

bool CListCtrlPop::Create(CWnd* parent)
{
	bool result = CDialog::Create(IDD,parent);
	this->ShowWindow(SW_HIDE);
	this->InitListCtrl();
	this->GetClientRect(&this->m_rectShow);	
	return true;
}
void CListCtrlPop::SetShowPosition(const CRect& rect,CWnd* wndedited)
{	//确定显示位置,要考虑到,显示器的长,宽.
	m_ptPosition.x=rect.left;
	m_ptPosition.y=rect.bottom;

	ASSERT_VALID(wndedited);
	ASSERT_KINDOF(CWnd, wndedited);

	m_wndStrEdited=wndedited;
	int iScreenWidth=::GetSystemMetrics(SM_CXSCREEN);
	int iScreenHeight=::GetSystemMetrics(SM_CYSCREEN);
	if(iScreenWidth<m_ptPosition.x+m_rectShow.Width())
		m_ptPosition.x=iScreenWidth-m_rectShow.Width()-20;
	if(iScreenHeight<m_ptPosition.y+m_rectShow.Height())	
		m_ptPosition.y=m_ptPosition.y-m_rectShow.Height()-rect.Height()-5;

	afxDump<<"\n SetShowPosition=m_ptPosition"<<m_ptPosition;
}

void CListCtrlPop::ClearListCtrlItems()
{
this->m_listctrl->DeleteAllItems();
}

CString CListCtrlPop::GetListCtrlSel(int subitem)
{
int mark=this->m_listctrl->GetSelectionMark();
return m_listctrl->GetItemText(mark,subitem);
}

bool CListCtrlPop::RefreshListCtrlView(int subitem,CString edited)
{
	if(subitem>this->m_iColumns-1)
		return false;

	if(edited=="")
		return this->ShowAllStringList();

	m_iSubItem=subitem;
	m_listctrl->SetRedraw(false);
	m_listctrl->DeleteAllItems();
	int j=0;
	CString str;
	CString s_subitem;

	POSITION pos=this->m_strlist[m_iSubItem].FindIndex(1);
	for(int i=1;pos!=NULL;i++)
	{
		str=m_strlist[m_iSubItem].GetNext(pos);
		if(str.Find(edited)!=-1)
		{
			for(int k=0;k<this->m_iColumns;k++)
			{
				CString value=m_strlist[k].GetAt(m_strlist[k].FindIndex(i));
				if(!k)
				{
					m_listctrl->InsertItem(j,value);
				}
				else
				{
					m_listctrl->SetItemText(j,k,value);
				}
			}
			j++;
		}
	}
	int temp=0;
	for(i=0;i<m_listctrl->GetItemCount();i++)
		if(edited==m_listctrl->GetItemText(i,subitem))
		{
			temp=i;
			break;
		}
	m_listctrl->SetSelectionMark(temp);
	m_listctrl->SetHotItem(temp);
	m_listctrl->SetRedraw(true);
	return true;
}

bool CListCtrlPop::InitListCtrl()
{

//	m_listctrl->Create(WS_CHILD|
//		WS_VISIBLE|//WS_VSCROLL|WS_HSCROLL|
//		LVS_SHOWSELALWAYS|
//		LVS_SINGLESEL|LVS_REPORT,
//		CRect(0,0,0,0),this,ID_POP_LISTCTRL);
	m_listctrl->Create(WS_CHILD|WS_VSCROLL   |WS_VISIBLE|LVS_REPORT|WS_BORDER,
		CRect(0,0,100,100),this,ID_POP_LISTCTRL);

	this->m_listctrl->ModifyStyle(LVS_EDITLABELS, 0L);		//禁止标题编辑
	m_listctrl->ModifyStyle(0L, LVS_REPORT);			//设为Report类型
	m_listctrl->ModifyStyle(0L, LVS_SHOWSELALWAYS);		//始终高亮度被选中的表项
	m_listctrl->ModifyStyle(0L, LVS_NOSORTHEADER);

	m_listctrl->ModifyStyle( LVS_OWNERDRAWFIXED,0L);

	m_listctrl->SetExtendedStyle( LVS_EX_FULLROWSELECT |		//允许整行选中
		LVS_EX_GRIDLINES |	//画出网格线
		LVS_EX_FLATSB				//扁平风格的滚动条	
		);	

	return true;
}

CStringList* CListCtrlPop::SelectStringList(int number,CStringList *newstringlist)
{
	if(number<0) 
	{
		MessageBox("stringlists.number<0");
		return NULL;
	}
	ASSERT(newstringlist!=NULL);

	CStringList* temp=m_strlist;
	m_iColumns=number;
	this->m_strlist=newstringlist;

	this->ClearListAllColumn();		//将上次显示的数据删除;

	int length=0;					//记录总长度	
	CString str;
	int* col_length=new int[m_iColumns];	//记录每列最长的长度
	for(int k=0;k<m_iColumns;k++)
		col_length[k]=8;
	for(int i=0;i<m_iColumns;i++)
	{
		this->m_listctrl->InsertColumn(i,m_strlist[i].GetHead());	
		col_length[i]=max(col_length[i],m_strlist[i].GetHead().GetLength());
		POSITION pos=m_strlist[i].FindIndex(1);
		for(int j=1;pos!=NULL;j++)
		{
			str=m_strlist[i].GetNext(pos);
			col_length[i]=max(col_length[i],str.GetLength());
		}
		m_listctrl->SetColumnWidth(i,col_length[i]*10);//LVSCW_AUTOSIZE_USEHEADER
	}
	for(k=0;k<m_iColumns;k++)
		length=length+col_length[k];
	m_listctrl->MoveWindow(0,0,length*10+18,this->m_rectShow.Height()-7);
	m_rectShow.right=length*10+26;
	delete [] col_length;
	return temp;
}

void CListCtrlPop::ClearListAllColumn()
{
	this->m_listctrl->DeleteAllItems();
	int n=m_listctrl->GetHeaderCtrl()->GetItemCount();
	for(int i=n-1;i>=0;i--)	
	this->m_listctrl->DeleteColumn(i);
}
void CListCtrlPop::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	int mark=m_listctrl->GetSelectionMark();
	POSITION pos=m_listctrl->GetFirstSelectedItemPosition();
	for(;pos!=NULL;)
	{
		if(mark==m_listctrl->GetNextSelectedItem(pos))
			this->SetStrWindowText();
	}
	
	*pResult = 0;
}


void CListCtrlPop::SetStrWindowText()
{
	::PostMessage(m_wndStrEdited->GetSafeHwnd(),WM_KEYDOWN,13,0);
	PostMessage(WM_SHOWWINDOW,0,0);
}

bool CListCtrlPop::RefreshListCtrlView(int subitem, CString edited, CString sCankao,int cankao_subitem)
{

	this->RefreshListCtrlView(subitem,edited);
	int temp=-1;
	int temp2=-1;

	for(int i=0;i<m_listctrl->GetItemCount();i++)
	{	
		if(sCankao==m_listctrl->GetItemText(i,cankao_subitem))
		{
			temp2=i;
			break;
		}
		if(edited==m_listctrl->GetItemText(i,subitem))
		{
			if(temp==-1)
				temp=i;
		}
	}
	if(temp2!=-1)
		temp=temp2;
	if(temp==-1)
		temp=0;

	m_listctrl->SetSelectionMark(temp);
	m_listctrl->SetHotItem(temp);

	return true;
}

void CListCtrlPop::OnShowWindow(BOOL bShow, UINT nStatus) 
{
	CDialog::OnShowWindow(bShow, nStatus);
/*	TRACE("OnShowWindow\n");
	if(bShow&&this->m_wndStrEdited!=NULL)	
		if(this->m_wndStrEdited->GetSafeHwnd()!=NULL)
		{
			::PostMessage(m_wndStrEdited->GetSafeHwnd(),WM_ACTIVATE ,WA_CLICKACTIVE,0);
			TRACE("m_wndStrEdited->GetSafeHwnd(),WM_SETFOCUS,\n");
		}
*/
}

void CListCtrlPop::ShowListPop()
{	
	TRACE("void CListCtrlPop::ShowListPop()\n");

	afxDump<<"\n Show Position="<<m_ptPosition;
	this->MoveWindow(this->m_ptPosition.x,this->m_ptPosition.y,
	this->m_rectShow.Width(),this->m_rectShow.Height());      
	this->ShowWindow(SW_SHOWNOACTIVATE);//SW_SHOW
}

void CListCtrlPop::SendTheUDNPMessage(UINT KEY)
{
	::SendMessage(this->m_listctrl->GetSafeHwnd(),WM_KEYDOWN,KEY,0);
		m_listctrl->SetHotItem(m_listctrl->GetSelectionMark());
}



void CListCtrlPop::OnSetfocusList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	ASSERT_VALID(this->m_wndStrEdited);
	ASSERT_KINDOF(CWnd, m_wndStrEdited);
	this->m_wndStrEdited->ShowWindow(SW_SHOW);
	this->m_listctrl->SetHotItem(-1);
	*pResult = 0;
}

CWnd* CListCtrlPop::GetCurEditWnd()
{	
	ASSERT_VALID(this->m_wndStrEdited);
	ASSERT_KINDOF(CWnd, m_wndStrEdited);
	return this->m_wndStrEdited;
}

BOOL CListCtrlPop::DestroyWindow() 
{
	if(m_listctrl->m_hWnd!=NULL)
		m_listctrl->DestroyWindow();

	return CDialog::DestroyWindow();
}

int CListCtrlPop::GetSelectedMark()
{
return m_listctrl->GetSelectionMark();
}

bool CListCtrlPop::RefreshListCtrlView(
	int conditionsubitem, CString scondition, int subitem, CString edited)
{

	if(scondition=="")return this->RefreshListCtrlView(subitem,edited);

	if(subitem>this->m_iColumns-1)
		return false;

	m_listctrl->SetRedraw(false);
	m_iSubItem=subitem;
	m_listctrl->DeleteAllItems();

	int j=0;
	int temp=0;		//确定CListCtrlPop选中哪条纪录!
	bool btemp=false;
	CString str;
	CString str_constdition;
	POSITION pos=this->m_strlist[m_iSubItem].FindIndex(1);
	POSITION pos_constdition=this->m_strlist[conditionsubitem].FindIndex(1);
	for(int i=1;pos!=NULL;i++)
	{
		str=m_strlist[m_iSubItem].GetNext(pos);
		str_constdition=m_strlist[conditionsubitem].GetNext(pos_constdition);
		if(str_constdition!=scondition) 
			continue;
		if(str.Find(edited)!=-1)
		{
			for(int k=0;k<this->m_iColumns;k++)
			{
				CString value=m_strlist[k].GetAt(m_strlist[k].FindIndex(i));
				if(!k)
				{
				m_listctrl->InsertItem(j,value);
				}
				else
				{
				m_listctrl->SetItemText(j,k,value);
				}
			}
			if(!btemp&&edited==str)
			{
				temp=j;
				btemp=true;
			}
			j++;
		}
	}
	
	m_listctrl->SetSelectionMark(temp);
	m_listctrl->SetHotItem(temp);
	m_listctrl->SetRedraw(true);
	m_listctrl->Invalidate();
	return true;
}

bool CListCtrlPop::RefreshListCtrlView(int conditionsubitem, CString scondition, int inothis, CString snothis, int subitem, CString edited)
{
	if(scondition=="")return this->RefreshListCtrlView(subitem,edited);

	if(subitem>this->m_iColumns-1)
		return false;
	m_listctrl->SetRedraw(false);
	m_iSubItem=subitem;
	m_listctrl->DeleteAllItems();

	int j=0;
	int temp=0;		//确定CListCtrlPop选中哪条纪录!
	bool btemp=false;	

	CString str;
	CString str_constdition;
	CString str_nothis;	

	POSITION pos=this->m_strlist[m_iSubItem].FindIndex(1);
	POSITION pos_constdition=this->m_strlist[conditionsubitem].FindIndex(1);
	POSITION pos_nothis=this->m_strlist[inothis].FindIndex(1);

	for(int i=1;pos!=NULL;i++)
	{
		str=m_strlist[m_iSubItem].GetNext(pos);
		str_constdition=m_strlist[conditionsubitem].GetNext(pos_constdition);
		str_nothis=m_strlist[inothis].GetNext(pos_nothis);
		if(str_nothis==snothis||str_constdition!=scondition) 
			continue;
		if(str.Find(edited)!=-1)
		{

			for(int k=0;k<this->m_iColumns;k++)
			{
				CString value=m_strlist[k].GetAt(m_strlist[k].FindIndex(i));
				if(!k)
				{
				m_listctrl->InsertItem(j,value);
				}
				else
				{
				m_listctrl->SetItemText(j,k,value);
				}
			}
			if(!btemp&&edited==str)
			{
				temp=j;
				btemp=true;
			}
			j++;
		}
	}
	m_listctrl->SetSelectionMark(temp);
	m_listctrl->SetHotItem(temp);
	m_listctrl->SetRedraw(true);
	this->Invalidate();
	return true;
}

bool CListCtrlPop::ShowAllStringList()
{
	m_listctrl->SetRedraw(false);
	m_listctrl->DeleteAllItems();
	POSITION* pos=new POSITION[this->m_iColumns];
	try{
	for(int i=0;i<this->m_iColumns;i++)
		pos[i]=this->m_strlist[i].FindIndex(1);
	//插入第一列
	for(i=0;pos[0]!=NULL;i++)
	{
		m_listctrl->InsertItem(i,m_strlist[0].GetNext(pos[0]));
	}
	//插入其余各列
	for(i=1;i<this->m_iColumns;i++)
		for(int j=0;pos[i]!=NULL;j++)
		{
			m_listctrl->SetItemText(j,i,m_strlist[i].GetNext(pos[i]));		
		}
	}
	catch(...)
	{
		MessageBox("some wrong about m_strlist","wrong!");
		return false;
	}
	delete [] pos;
	m_listctrl->SetSelectionMark(0);
	m_listctrl->SetHotItem(0);
	m_listctrl->SetRedraw(true);
	return true;
}

CListCtrlPop::~CListCtrlPop()
{
	delete m_listctrl;	
	m_listctrl=NULL;
}

⌨️ 快捷键说明

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