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

📄 splistviewctrl.cpp

📁 Windows Mobile 手机短信订购软件源程序
💻 CPP
字号:
#include "stdafx.h"
#include "SPListViewCtrl.h"
#include <winuserm.h>
#include "StringList.h"
#include "mail.h"
#include "EditSmsDlg.h"

CMail mymail;

extern  int m_offset;
extern	CStringList m_slCodeList;
extern  int ItemEntry[8];
extern  int ItemCity[9];
extern  CString  MailTo;
int m_layer=0;
int m_item=0;
int m_index=0;

int m_index1=0;
int m_index0=0;
int m_index2=0;
int m_index3=0;
int m_index4=0;
int m_index5=0;

CEditSMSDlg dlg;

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CSPListViewCtrl::CSPListViewCtrl()
{
	m_hFont = NULL;
	m_nFontSize = 11;
}

CSPListViewCtrl::~CSPListViewCtrl()
{

}

HWND CSPListViewCtrl::Create(HWND hParent, _U_RECT rc)
{
	RECT rect = *rc.m_lpRect;
	HWND hWnd = CWindowImpl<CSPListViewCtrl, CListViewCtrl>::Create(hParent, rect, NULL, 
		WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_NOCOLUMNHEADER | LVS_SINGLESEL | WS_TABSTOP);

	InitControl();

	return hWnd;	
}

void CSPListViewCtrl::CreateItemFont()
{
	LOGFONT lf;
	memset(&lf, 0, sizeof(LOGFONT));
	HDC hdc = ::GetDC(NULL);
	lf.lfHeight = -m_nFontSize * ::GetDeviceCaps(hdc, LOGPIXELSY) / 72;
	::ReleaseDC(NULL, hdc);
	lf.lfWeight = FW_SEMIBOLD;
	m_hFont = ::CreateFontIndirect(&lf);
}

void CSPListViewCtrl::AddItem(LPCTSTR lpszText)
{
	int iIndex;
	iIndex = InsertItem( GetItemCount(), lpszText);
	if(GetItemCount() == 10)
	{
		CRect rcClient;
		::GetClientRect(GetParent(),rcClient);
		SetColumnWidth(1,rcClient.Width() - 6);
	}

}

void CSPListViewCtrl::DeleteItem(int nIndex)
{
	if (nIndex >= 0 && nIndex < GetItemCount()) {
		CWindowImpl<CSPListViewCtrl, CListViewCtrl>::DeleteItem(nIndex);
	
	}
}


void CSPListViewCtrl::InitControl()
{
	ATLASSERT(m_hFont == NULL);	// should be called only once

	CreateItemFont();
	SetFont(m_hFont);
	/*
    CRect rc;
	GetClientRect(&rc);
	InsertColumn(0, L"Name", LVCFMT_LEFT,0, 0);	// invisible column with default icon
*/
	SetExtendedListViewStyle(LVS_EX_SUBITEMIMAGES | LVS_EX_FULLROWSELECT);
	CRect rcClient;
	HWND hwnd;
	hwnd = GetParent();

	::GetClientRect(hwnd,&rcClient);

	LVCOLUMN lvcol;
	lvcol.mask = LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
	lvcol.cx =  rcClient.Width()-6 ;
	
	//::LoadString(_Module.GetResourceInstance(),IDS_NAME,szTemp,20);
	//_tcscpy(lvcol.pszText,szTemp);// = L"Name";
	lvcol.pszText = L"Name";
	lvcol.iSubItem = 1;
	InsertColumn(1,&lvcol);
}

void CSPListViewCtrl::SetFontSize(int nFontSize)
{
	m_nFontSize = nFontSize;
}

BOOL CSPListViewCtrl::SendSMS(int index)
{	
	HRESULT         hr ;
	POSITION pos;
    LPWSTR      MailBody; 
	CString S1("ABIRD");
    CString msg;
	if(index>183)
		return 0;
    if(index==183){
    	hr=mymail.MailSend(MailTo.GetBuffer(sizeof(MailTo)),L"",NULL,L"0000");
/*		if (FAILED(hr)){ 
			 MessageBox(L"Send SMS Faild",L"",MB_OK | MB_ICONWARNING);
			return 0;
		}else{
	            MessageBox(L"Send SMS Success",L"",MB_OK | MB_ICONWARNING);
			 return 1;
		}
*/
		return 1;
	}

    pos=m_slCodeList.FindIndex(index);
	msg=m_slCodeList.GetAt(pos);

    if(index==81||index==82||index==146||index==148||index==150){
    	CString S2(S1+L" "+msg+L" "+dlg.m_szMessage);
		MailBody=S2.GetBuffer(sizeof(S2));
		hr=mymail.MailSend(MailTo.GetBuffer(sizeof(MailTo)),L"",NULL,MailBody);
	
	}else{
	    CString S3(S1+L" "+msg);
		MailBody=S3.GetBuffer(sizeof(S3));
		hr=mymail.MailSend(MailTo.GetBuffer(sizeof(MailTo)),L"",NULL,MailBody);

	}
	::SendMessage(GetParent(), WM_KEYUP, VK_TBACK,0 );
	return TRUE;
}

BOOL CSPListViewCtrl::DeleteAllItems()
{
	int nCount = GetItemCount();
	int i=0;
	for(i=nCount-1;i>=0;i--)
	{
		SetItemData(i,NULL);
	}
	return CListViewCtrl::DeleteAllItems();
}

void CSPListViewCtrl::ScrollToIndex(int nIndex)
{
	if(nIndex<0 || nIndex>=GetItemCount()) return;
	
	int nSelIndex = GetNextItem(-1,LVNI_SELECTED);
	if(nSelIndex < 0) nSelIndex=GetTopIndex();
	
	//if(nTopIndex==1 && wParam == VK_LEFT)
	//if(GetItemCount()-nTopIndex<10 && wParam == VK_RIGHT)
	SetItemState(nSelIndex,~LVIS_SELECTED,LVIS_SELECTED);
	SetItemState(nSelIndex,~LVNI_FOCUSED,LVNI_FOCUSED);   

	CRect rcItem;
	GetItemRect(nIndex,rcItem,LVIR_BOUNDS);
	SIZE size;
	size.cx=0;
	int nIdx1;
	if(nSelIndex >= GetTopIndex() + GetCountPerPage()) 
		nIdx1 = GetTopIndex() + GetCountPerPage()-1;
	else if(nSelIndex < GetTopIndex())
		nIdx1 = GetTopIndex();
	else 
		nIdx1 = nSelIndex;

	size.cy= (nIndex - nIdx1) *rcItem.Height();
	Scroll(size);
	
	SetItemState(nIndex,LVNI_FOCUSED,LVNI_FOCUSED);
	SetItemState(nIndex,LVIS_SELECTED,LVIS_SELECTED);
	
}
void CSPListViewCtrl::LoadNameList(int layer,int item)
{
	int curnum=0;
	int tempnum=0;
	int i,j;

	CString tempstr=L"";
	CString Compstr=L"";

	switch(layer)
	{
	  case 0:
      	for(i=0;i<8;i++)
		{
    		tempstr.LoadString(IDS_OLAYITEM1+i+m_offset);
            AddItem(tempstr);
		}
		  break;
	  case 1:
		  if(item==0){
		    tempnum=ItemEntry[item];	
			for(i=0;i<tempnum;i++)
			{
    			tempstr.LoadString(IDS_TLAYITEM1+i+m_offset);
			    AddItem(tempstr);
			}
		  }else{
		    tempnum=ItemEntry[item];
			for(j=0;j<=item;j++)
			{       
			  curnum +=ItemEntry[j];
			}
			for(i=curnum-tempnum;i<curnum;i++)
			{
    			tempstr.LoadString(IDS_TLAYITEM1+i+m_offset);
			    AddItem(tempstr);
			}
		  }
		  break;
	  case 2:
		switch(m_index)
		{
		case ITEM1:
		    tempnum=ItemCity[item];
			for(j=0;j<=item;j++)
			{       
			  curnum +=ItemCity[j];
			}
			for(i=curnum-tempnum;i<curnum;i++)
			{
    			tempstr.LoadString(IDS_THLAYITEM1+i+m_offset);
			    AddItem(tempstr);
			}		
			break;
		case ITEM2:
			if(item==5)
			{			
				for(i=0;i<12;i++)
				{
    				tempstr.LoadString(IDS_THLAYITEM50+i+m_offset);
					AddItem(tempstr);
				}
   			    	tempstr.LoadString(IDS_LASTZF+m_offset);
					AddItem(tempstr);
			}else{
				for(i=0;i<3;i++)
				{
    				tempstr.LoadString(IDS_LASTDB+i+m_offset);
					AddItem(tempstr);
				}
			}
			break;
		case ITEM3:
			for(i=0;i<3;i++)
			{
    			tempstr.LoadString(IDS_LASTDB+i+m_offset);
			    AddItem(tempstr);
			}
			break;
		case ITEM4:
			if(item<2){
					tempstr.LoadString(IDS_LASTDY+m_offset);
					AddItem(tempstr);
					tempstr.LoadString(IDS_LASTZF+m_offset);
					AddItem(tempstr);
			}else if(item<5){
					tempstr.LoadString(IDS_LASTGPTM+m_offset);
					AddItem(tempstr);
					tempstr.LoadString(IDS_LASTZF+m_offset);
					AddItem(tempstr);
			}else{
					for(i=0;i<3;i++)
					{
    					tempstr.LoadString(IDS_LASTDB+i+m_offset);
						AddItem(tempstr);
					}
			}
			break;
		case ITEM5:
				tempstr.LoadString(IDS_LASTDB+m_offset);
				AddItem(tempstr);
				tempstr.LoadString(IDS_LASTZF+m_offset);
				AddItem(tempstr);
			
			break;
		case ITEM6:
				tempstr.LoadString(IDS_LASTDY+m_offset);
				AddItem(tempstr);
				tempstr.LoadString(IDS_LASTZF+m_offset);
				AddItem(tempstr);
			break;
		case ITEM7:
	    	for(i=0;i<3;i++)
			{
    			tempstr.LoadString(IDS_LASTDB+i+m_offset);
			    AddItem(tempstr);
			}


			break;


		}
		  break;
		case 3:
		switch(m_index)
		{
		case ITEM1:
			if(m_index1<6){
				for(i=0;i<2;i++)
				{
    			tempstr.LoadString(IDS_LASTDB+i+m_offset);
				AddItem(tempstr);
				}
			}
			break;
		case ITEM2:
            if(m_index0==5){
			for(i=0;i<2;i++)
				{
    				tempstr.LoadString(IDS_LASTDB+i+m_offset);
					AddItem(tempstr);
				}
			}
			break;
		}
	}



	HCURSOR hOldCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));

	ScrollToIndex(0);
	
	SetCursor(hOldCursor);
	if(GetItemCount() > 10)
	{
		CRect rcClient;
		::GetClientRect(GetParent(),rcClient);
		SetColumnWidth(0,rcClient.Width()-6);
	} else 
	{
		CRect rcClient;
		::GetClientRect(GetParent(),rcClient);
		SetColumnWidth(0,rcClient.Width());
	}

}
	

LRESULT CSPListViewCtrl::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	CString tempstr=L"";
	CString Compstr=L"";
	CString sLabel;
	int tempnum=0;
	int curnum=0;
	int j;
	if(wParam == VK_TACTION)
	{

			if(m_layer<4){
			int nSelIndex = GetNextItem(-1,LVNI_SELECTED);
			if(nSelIndex<0) 
				return 0;
			switch(m_layer)
			{
			case 0:	
			   if(nSelIndex==7)
			   {
				SendSMS(183);
				 return 0;
			   }else{
				m_index=nSelIndex;
				m_item=nSelIndex;		
				m_layer++;
				DeleteAllItems();
				LoadNameList(m_layer,m_item);
				return 0;
			   }
			break;
			case 1:
				if(m_index==0){
					m_index1=nSelIndex;
				}else if(m_index==1){
					m_index0=nSelIndex;
				}else if(m_index==3){
					m_index2=nSelIndex;
				}
				m_index3=nSelIndex;
				m_item=nSelIndex;		
				m_layer++;
				DeleteAllItems();
				LoadNameList(m_layer,m_item);
			break;

			case 2:
				switch(m_index){
					case 0:
						if(m_index1<6)
						{
							m_index4=nSelIndex;
							m_item=nSelIndex;		
							m_layer++;
							DeleteAllItems();
							LoadNameList(m_layer,m_item);	
						}
						if(m_index1==8){
							 SendSMS(83);
						}else if(m_index1==7){
							 dlg.title.LoadString(IDS_THLAYITEM42+m_offset);
							if(dlg.DoModal()==IDOK)
							{
								SendSMS(82);
							}
						}else if(m_index1==6){
							 dlg.title.LoadString(IDS_THLAYITEM41+m_offset);
							if(dlg.DoModal()==IDOK)
							{
								SendSMS(81);
							}

						}
						break;

					case 1:

						if(m_index0<5)
						{
						 curnum+=m_index0;
						 curnum*=3;
						 curnum+=84;
	                     SendSMS(curnum+nSelIndex);
						}else if(m_index0>5){
							 curnum+=m_index0-6;
							 curnum*=3;
							 curnum+=124;
							 SendSMS(curnum+nSelIndex);
						}else if(m_index0==5&&nSelIndex==12)
						{				       
							SendSMS(123);
						}else{
							m_index5=nSelIndex;
							m_item=nSelIndex;		
							m_layer++;
							DeleteAllItems();
							LoadNameList(m_layer,m_item);	
						}
						break;
					case 2:
						 curnum+=m_item;
						 curnum*=3;
						 curnum+=130;
						 SendSMS(curnum+nSelIndex);
						 break;
					case 3:
						if(m_index2<2){
						 curnum+=m_item;
						 curnum*=2;
						 curnum+=146;
						 SendSMS(curnum+nSelIndex);
						}else if(m_index2<5)
						{
							 dlg.title.LoadString(IDS_LASTGPTM+m_offset);
								if(m_index2=2)
								{
						      			if(nSelIndex==0)
										{
											if(dlg.DoModal()==IDOK)		
											{
												SendSMS(146);
													
											}
										}else{
											   SendSMS(147);
										}
								}else if(m_index2=3)
								{
						      			if(nSelIndex==0)
										{
										if(dlg.DoModal()==IDOK)
											{
												SendSMS(148);
											}
										}else{
                                                SendSMS(149);
										}
								}else
								{ 
						      			if(nSelIndex==0)
										{
											if(dlg.DoModal()==IDOK)		
											{
													SendSMS(150);
											}
										}else{
                                                SendSMS(151);
										}
								}

						}else
						{
						 SendSMS(152+nSelIndex);
						}


						break;
					case 4:
						 curnum+=m_item;
						 curnum*=2;
						 curnum+=155;
						 SendSMS(curnum+nSelIndex);
						break;
					case 5:
						 curnum+=m_item;
						 curnum*=2;
						 curnum+=163;
						 SendSMS(curnum+nSelIndex);
						break;
					case 6:
						if(m_item==4){
						 curnum=181;
						 SendSMS(curnum+nSelIndex);
						}else{
						 curnum+=m_item;
						 curnum*=3;
						 curnum+=169;
						 SendSMS(curnum+nSelIndex);
						}
						break;

					}

			   return 0;
			break;
			case 3:
				if(m_index==0){
					for(j=0;j<m_index1;j++)
					{       
					  curnum +=ItemCity[j];
					}  
					curnum+=m_item;
					curnum*=2;
				    SendSMS(curnum+nSelIndex);
				}else if(m_index==1&&m_index0==5)
					 curnum+=m_item;
				     curnum*=2;
                     curnum+=99;
				     SendSMS(curnum+nSelIndex);
				   return 0;
			break;
			}

		}
				
	}
	else if(wParam == VK_LEFT || wParam == VK_RIGHT) 
	{
		int nCntPerPage = GetCountPerPage();
		int nTopIndex = GetTopIndex();
		int nSelIndex = GetNextItem(-1,LVNI_SELECTED);
		//if(nTopIndex==1 && wParam == VK_LEFT)
		//if(GetItemCount()-nTopIndex<10 && wParam == VK_RIGHT)
		SetItemState(nSelIndex,~LVIS_SELECTED,LVIS_SELECTED);
		SetItemState(nSelIndex,~LVNI_FOCUSED,LVNI_FOCUSED);   

		CRect rcItem;
		GetItemRect(nTopIndex,rcItem,LVIR_BOUNDS);
		SIZE size;
		size.cx=0;
		if(wParam == VK_LEFT)
			size.cy= - nCntPerPage*rcItem.Height();
		else 
			size.cy=nCntPerPage*rcItem.Height();
		Scroll(size);
		
		if(nSelIndex < 10 && wParam == VK_LEFT) 
		{
			SetItemState(0,LVNI_FOCUSED,LVNI_FOCUSED);
			SetItemState(0,LVIS_SELECTED,LVIS_SELECTED);
			
			//如果已经在第一页了
		} else if(nTopIndex + nCntPerPage > GetItemCount()-1 && wParam == VK_RIGHT)  
		{
			SetItemState(GetItemCount()-1,LVNI_FOCUSED,LVNI_FOCUSED);
			SetItemState(GetItemCount()-1,LVIS_SELECTED,LVIS_SELECTED);
			
		} else if(nSelIndex>nTopIndex) {
			SetItemState(GetTopIndex()+nSelIndex-nTopIndex,LVNI_FOCUSED,LVNI_FOCUSED);
			SetItemState(GetTopIndex()+nSelIndex-nTopIndex,LVIS_SELECTED,LVIS_SELECTED);
		} else {
			SetItemState(GetTopIndex(),LVNI_FOCUSED,LVNI_FOCUSED);
			SetItemState(GetTopIndex(),LVIS_SELECTED,LVIS_SELECTED);
		}
	} else {
		return DefWindowProc(uMsg,wParam,lParam);
	}
    	bHandled = FALSE;
	return 0;
}


⌨️ 快捷键说明

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