www.pudn.com > CirMMI.rar > DlgBook.cpp
// DlgBook.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h"
#include "DlgBook.h"
#include "cirmmidlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgBook dialog
CDlgBook::CDlgBook(CWnd* pParent /*=NULL*/)
: CDialog(CDlgBook::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgBook)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
//
this->m_nTotal= 0;
this->m_nCurrentIndex= 0;
this->m_iLayer= 0;
//初始化通讯录的记录
this->AppendRecord(0xf1, _T("车长"), _T("13920001000"));
this->m_nTotal++;
this->AppendRecord(0xf1, _T("车长"), _T("13920001001"));
this->m_nTotal++;
this->AppendRecord(0xf1, _T("车长"), _T("13920001002"));
this->m_nTotal++;
this->AppendRecord(0xf1, _T("车长"), _T("13920001003"));
this->m_nTotal++;
this->AppendRecord(0xf1, _T("前方调度"), _T("13920001004"));
this->m_nTotal++;
//十个路局的代号,自己定义为1-10,电话类型为0xf?
this->AppendRecord(5, 0xf1, _T("郑州铁路局"), _T("机务调度"), _T("10001"));
this->AppendRecord(5, 0xf1, _T("郑州铁路局"), _T("电务调度"), _T("10002"));
this->AppendRecord(5, 0xf1, _T("郑州铁路局"), _T("维修中心"), _T("10003"));
this->AppendRecord(5, 0xf1, _T("郑州铁路局"), _T("XXX1调度"), _T("10004"));//使用全角,是为了显示对齐而已
this->AppendRecord(5, 0xf1, _T("郑州铁路局"), _T("XXX2调度"), _T("10005"));
//
this->m_staticHeader.SetText(_T(""));
//设置提示文本的字体大小:在PreSubclassDlgItem()前就行
this->m_staticTopic.SetColorOfText(RGB(255, 255, 255));
this->m_staticTopic.SetWeightOfFont(700);//FW_BOLD
this->m_staticHeader.SetSizeOfFont(-14);
//自定义字体:给CListBox用
LOGFONT lf;
::memset(&lf, 0x00, sizeof(lf));
lf.lfEscapement= 0;
lf.lfOrientation= 0;
lf.lfItalic= FALSE;
lf.lfUnderline= FALSE;
lf.lfStrikeOut= FALSE;
lf.lfOutPrecision= 3;
lf.lfClipPrecision= 2;
lf.lfQuality= 0;
lf.lfPitchAndFamily= 49;
lf.lfHeight= -14;//小四 (小二:-24);
lf.lfWidth= 0;
lf.lfWeight= 400;
lf.lfCharSet= GB2312_CHARSET;
//lf.lfCharSet= DEFAULT_CHARSET;
wcscpy(lf.lfFaceName, _T("新宋体"));
if(this->m_fontOfList.m_hObject)
{
this->m_fontOfList.DeleteObject();
}
BOOL bTemp= this->m_fontOfList.CreateFontIndirect(&lf);
}
void CDlgBook::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgBook)
DDX_Control(pDX, IDC_LIST2, m_listboxView);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgBook, CDialog)
//{{AFX_MSG_MAP(CDlgBook)
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
INIT_EXIT_MAP(InitWnd,ExitWnd)
MY_KEY_MAP(OnKeyProc)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgBook message handlers
BOOL CDlgBook::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
//获得父窗口
this->m_pFrmWnd= this->GetParent();
//控件子类化
this->m_staticTopic.SubclassDlgItem(IDC_STATIC_TOPIC, this);
this->m_staticHeader.SubclassDlgItem(IDC_STATIC_HEADER, this);
this->m_staticType.SubclassDlgItem(IDC_STATIC_TYPE, this);
this->m_staticName.SubclassDlgItem(IDC_STATIC_NAME, this);
this->m_staticTelecode.SubclassDlgItem(IDC_STATIC_TELECODE, this);
//
this->m_listboxView.SetFont(&this->m_fontOfList);
this->m_listboxView.SetItemHeight(0, 16);
//
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
//进入通讯录窗体
LRESULT CDlgBook::InitWnd(WPARAM wParam, LPARAM lParam)
{
this->m_staticTopic.SetText(_T("通讯录"));
this->m_staticTopic.Invalidate(FALSE);
this->m_staticHeader.SetText(_T(""));
/*
this->m_staticType.SetText(_T("号码类型"));
this->m_staticType.Invalidate(FALSE);
this->m_staticName.SetText(_T("名 称"));
this->m_staticName.Invalidate(FALSE);
this->m_staticTelecode.SetText(_T("电话号码"));
this->m_staticTelecode.Invalidate(FALSE);
this->DisplayRecord();
*/
this->DisplayJu();
this->m_iLayer= 0;
//
return 1;
}
//退出通讯录窗体
LRESULT CDlgBook::ExitWnd(WPARAM wParam, LPARAM lParam)
{
//
return 0;
}
//
//WPARAM字节分配:data2, data1, 类型
//LPARAM暂时没有用到
UINT CDlgBook::OnKeyProc(WPARAM wKey, LPARAM lunUse)
{
FromMcuInfo* pInfo= (FromMcuInfo*)wKey;
BYTE cbType= pInfo->type;//
BYTE cbValue= pInfo->key[0];//键值 或者 字节个数(可能是)
BYTE cbData1= pInfo->key[1];//音量值(可能是)
BYTE cbData2= pInfo->key[2];//
//
if(0x20==cbType)
{
switch(cbValue)//可接收的按键:左、右、退出
{
case KEY_UP:
{
this->m_nCurrentIndex= (this->m_nCurrentIndex+this->m_nTotal-1)%this->m_nTotal;
this->m_listboxView.SetCurSel(this->m_nCurrentIndex);
CRect rect;
this->m_listboxView.GetItemRect(this->m_nCurrentIndex, rect);
/*
CDC* pDC= this->m_listboxView.GetDC();
//pDC->FillSolidRect(rect, RGB(70, 170, 70));
pDC->SetBkColor(RGB(70, 170, 70));
this->m_listboxView.ReleaseDC(pDC);
*/
}
break;
case KEY_DOWN:
{
this->m_nCurrentIndex= (this->m_nCurrentIndex+this->m_nTotal+1)%this->m_nTotal;
this->m_listboxView.SetCurSel(this->m_nCurrentIndex);
}
break;
case KEY_CALL://呼叫
case KEY_ENTER://确认
{
if(0==this->m_iLayer)
{
INT iIndex= this->m_listboxView.GetCurSel();
CString strTemp;
this->m_listboxView.GetText(iIndex, strTemp);
this->m_staticHeader.SetText(strTemp);
this->m_staticHeader.Invalidate(FALSE);
iIndex++;
this->DisplayRecord(iIndex);
this->m_iLayer= 1;
}
/*
int sel=m_listboxView.GetCurSel();
if(sel!=-1 && m_listboxView.GetCurSel()< (int)this->m_records.m_nTotal)
{
CCirMMIDlg *pMMI=(CCirMMIDlg *)GetParent();
BYTE cbTemp[20];
INT iLength= 0;
this->m_records.GetTeleCodeByIndex(sel, cbTemp, iLength);
cbTemp[iLength++]= 0x3b;//0x3b为分号“;”
pMMI->GsmrCallByNUM(cbTemp, iLength);
}*/
}
break;
case KEY_QUIT://有问题呀?
{
if(1==this->m_iLayer)//要显示中国各个铁路局
{
this->DisplayJu();
this->m_nTotal= this->m_listboxView.GetCount();
this->m_iLayer= 0;
this->m_staticHeader.SetText(_T(""));
this->m_staticHeader.Invalidate(FALSE);
}
else//退回到设置界面
{
return 0;
}
}
break;
default:
;//Do nothing
}//END switch()
//
return 0x20;
}
//
return 1;
}
//
void CDlgBook::DisplayJu()
{
this->m_listboxView.ResetContent();
this->m_listboxView.AddString(_T(" ⒈哈尔滨铁路局"));
this->m_listboxView.AddString(_T(" ⒉沈阳铁路局"));
this->m_listboxView.AddString(_T(" ⒊北京铁路局"));
this->m_listboxView.AddString(_T(" ⒋呼和浩特铁路局"));
this->m_listboxView.AddString(_T(" ⒌郑州铁路局"));
this->m_listboxView.AddString(_T(" ⒍济南铁路局"));
this->m_listboxView.AddString(_T(" ⒎上海铁路局"));
this->m_listboxView.AddString(_T(" ⒏南昌铁路局"));
this->m_listboxView.AddString(_T(" ⒐广铁(集团)公司"));
this->m_listboxView.AddString(_T(" ⒑柳州铁路局"));
//
this->m_listboxView.SetCurSel(0);
this->m_nTotal= this->m_listboxView.GetCount();
this->m_nCurrentIndex= 0;
}
//在列表框中显示出通讯记录
void CDlgBook::DisplayRecord()
{
INT iCnt= 0;
this->m_listboxView.ResetContent();
if(0==this->m_nTotal)
{
this->m_listboxView.AddString(_T("没有通讯记录"));
}
else
{
for(; iCnt< (int)this->m_nTotal; iCnt++)
{
this->m_listboxView.AddString(this->m_records.GetRecordString(iCnt));
}
}
this->m_listboxView.SetCurSel(0);//SetSel(0);
this->m_nTotal= this->m_listboxView.GetCount();
}
//显示某个路局下面的电话
void CDlgBook::DisplayRecord(INT iJu)
{
INT iCnt= this->m_TeleBook.GetSize();
this->m_listboxView.ResetContent();
if(iCnt> 0)
{
TeleCode teleTemp;
for(INT iTemp= 0; iTemp< iCnt; iTemp++)
{
teleTemp= this->m_TeleBook.GetAt(iTemp);
if(iJu==teleTemp.iWhitchJu)
{
CString strType= teleTemp.cbType;
while(10!=strType.GetLength())
{
strType+= _T(" ");//不是两个空格,应该是三个空格,或者是Alt+41277(小键盘数字按键)
}
CString strTele= teleTemp.cbTele;
while(20!=strTele.GetLength())
{
strTele+= _T(" ");//不是两个空格,应该是三个空格,或者是Alt+41277(小键盘数字按键)
}
this->m_listboxView.AddString(strType+_T(" ")+ strTele);
}
}
if(0==this->m_listboxView.GetCount())
{
this->m_listboxView.AddString(_T("没有该路局电话通讯录"));
}
}
else
{
this->m_listboxView.AddString(_T("没有该路局电话通讯录"));
}
//
this->m_listboxView.SetCurSel(0);
this->m_nTotal= this->m_listboxView.GetCount();
this->m_nCurrentIndex= 0;
}
//添加一个记录(作废!)
BOOL CDlgBook::AppendRecord(BYTE cbType, CString strName, CString strTele)
{
return this->m_records.AppendRecord(cbType, strName, strTele);
}
//添加一个记录
BOOL CDlgBook::AppendRecord(INT iJu, INT iType, CString strJu, CString strType, CString strTele)
{
//return this->m_records2.AppendRecord(iJu, iType, strJu, strTele);
TeleCode teleTemp;
teleTemp.iWhitchJu= iJu;
teleTemp.iType= 0xf1;
if(strJu.GetLength()< 10)
{
::wcscpy(teleTemp.cbWhitchJu, strJu);
}
if(strType.GetLength()< 10)
{
::wcscpy(teleTemp.cbType, strType);
}
if(strTele.GetLength()< 20)
{
::wcscpy(teleTemp.cbTele, strTele);
}
//
return this->m_TeleBook.Add(teleTemp);
}
//
HBRUSH CDlgBook::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(pWnd==&m_listboxView)
{
pDC->SetBkMode(TRANSPARENT);
pDC->SetBkColor(::g_CommonSet.crMainBk);
//pDC->SetBkColor(RGB(70, 170, 70));
pDC->SetTextColor(RGB(220, 220, 120));//金黄色
//为什么整个ListBox的背景都改变了
/*
CListBox* pList= (CListBox*)pWnd;
CRect rect;
pList->GetItemRect(this->m_nCurrentIndex, rect);
pDC->FillSolidRect(rect, RGB(70, 170, 70));
*/
return (HBRUSH)g_CommonSet.pBrListBox->GetSafeHandle();
}
return hbr;
}