📄 calllogdlg.cpp
字号:
// CallLogDlg.cpp : implementation file
//
#include "stdafx.h"
#include "netpro.h"
#include "CallLogDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCallLogDlg dialog
CCallLogDlg::CCallLogDlg(CPtrList* pList,CMapStringToString* map,CWnd* pParent /*=NULL*/)
: CDialog(CCallLogDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCallLogDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_pList = pList;
m_pMap = map;
iItem=0;
}
void CCallLogDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCallLogDlg)
DDX_Control(pDX, IDC_LIST_CALLLOG, m_listctrl);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCallLogDlg, CDialog)
//{{AFX_MSG_MAP(CCallLogDlg)
ON_WM_DESTROY()
ON_BN_CLICKED(IDB_CLEAR, OnClear)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCallLogDlg message handlers
BOOL CCallLogDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CString s1;
s1.LoadString(IDS_CALL_LOG);
SetWindowText(s1);
// TODO: Add extra initialization here
pApp = (CNetproApp *)AfxGetApp();
srand((unsigned) time(NULL)); // start the random number generator
HWND hwnd;
hwnd=pApp->GetMainWnd()->m_hWnd;
CRect rect;
//GetClientRect(rect);
::GetWindowRect(hwnd,rect);
//ScreenToClient(rect);
::SetWindowPos(GetSafeHwnd(),HWND_NOTOPMOST,rect.left+100,rect.top-100,rect.Width(),rect.Height(),
SWP_NOSIZE | SWP_FRAMECHANGED);
//::SetWindowLong(GetSafeHwnd(),GWL_EXSTYLE,::GetWindowLong(hwnd,GWL_EXSTYLE)|WS_EX_TOOLWINDOW);
// create image list for header items
m_pImageHdrSmall = new CImageList();
ASSERT(m_pImageHdrSmall != NULL); // serious allocation failure checking
m_pImageHdrSmall->Create(16, 16, ILC_MASK, 2, 2);
m_pImageHdrSmall->Add(pApp->LoadIcon(IDI_HDRICON1));
m_pImageHdrSmall->Add(pApp->LoadIcon(IDI_HDRICON2));
// fill in image lists
m_pImageList = new CImageList();
m_pImageListSmall = new CImageList();
ASSERT(m_pImageList != NULL && m_pImageListSmall != NULL); // serious allocation failure checking
m_pImageList->Create(32, 32, TRUE, 2, 2);
m_pImageListSmall->Create(16, 16, TRUE, 2, 2);
m_pImageList->Add(pApp->LoadIcon(IDI_LOG_ICONLIST1));
m_pImageList->Add(pApp->LoadIcon(IDI_LOG_ICONLIST2));
m_pImageListSmall->Add(pApp->LoadIcon(IDI_LOG_ICONLIST1));
m_pImageListSmall->Add(pApp->LoadIcon(IDI_LOG_ICONLIST2));
FillListCtrl();
//Add item here
ASSERT(m_pList!=NULL);
POSITION pos = m_pList->GetHeadPosition();
if(pos==NULL)
::EnableWindow(::GetDlgItem(m_hWnd,IDB_CLEAR),FALSE);
while(pos!=NULL)
{
CALLLOGNODE* pNode = (LPCALLLOGNODE)m_pList->GetNext(pos);
InsertRow(pNode->m_sCallNum,pNode->m_sCallTime,pNode->m_sCallEndTime,pNode->m_sState);
}
m_listctrl.UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CCallLogDlg::OnDestroy()
{
delete m_pImageList;
delete m_pImageListSmall;
delete m_pImageHdrSmall;
CDialog::OnDestroy();
}
void CCallLogDlg::FillListCtrl()
{
CRect rect;
CString strItem1;
CString strItem2;
CString strItem3;
CString strItem4;
CString strItem5;
strItem1.LoadString(IDS_PHONENUM);
strItem2.LoadString(IDS_CALL_TIME);
strItem3.LoadString(IDS_CALL_END_TIME);
strItem4.LoadString(IDS_STATE);
strItem5.LoadString(IDS_NAME);
m_listctrl.SetImageList(m_pImageList, LVSIL_NORMAL);
m_listctrl.SetImageList(m_pImageListSmall, LVSIL_SMALL);
// insert two columns (REPORT mode) and modify the new header items
m_listctrl.GetWindowRect(&rect);
m_listctrl.InsertColumn(0, strItem1, LVCFMT_LEFT,
rect.Width() * 8/40, 0);
m_listctrl.InsertColumn(1, strItem2, LVCFMT_LEFT,
rect.Width() * 14/40, 1);
m_listctrl.InsertColumn(2, strItem3, LVCFMT_LEFT,
rect.Width() * 8/40, 2);
m_listctrl.InsertColumn(3, strItem4, LVCFMT_LEFT,
rect.Width() * 5/40, 3);
m_listctrl.InsertColumn(4, strItem5, LVCFMT_LEFT,
rect.Width() * 5/40, 4);
/*Another way
// insert columns
int i;
LV_COLUMN lvc;
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
for(i = 0; i<NUM_COLUMNS; i++)
{
lvc.iSubItem = i;//?在列表中的序号
lvc.pszText = _gszColumnLabel[i];
lvc.cx = _gnColumnWidth[i];
lvc.fmt = _gnColumnFmt[i];
m_CListMail.InsertColumn(i,&lvc);
}
*/
// ModifyHeaderItems();
ChangeView(LVS_REPORT);
m_listctrl.SetExtendedStyle(m_listctrl.GetExtendedStyle()|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
}
void CCallLogDlg::ModifyHeaderItems()
{
HD_ITEM curItem;
// retrieve embedded header control
CHeaderCtrl* pHdrCtrl= NULL;
pHdrCtrl= m_listctrl.GetHeaderCtrl();
pHdrCtrl->SetImageList(m_pImageHdrSmall);
// add bmaps to each header item
pHdrCtrl->GetItem(0, &curItem);
curItem.mask= HDI_IMAGE | HDI_FORMAT;
curItem.iImage= 0;
curItem.fmt= HDF_LEFT | HDF_IMAGE | HDF_STRING;
pHdrCtrl->SetItem(0, &curItem);
pHdrCtrl->GetItem(1, &curItem);
curItem.mask= HDI_IMAGE | HDI_FORMAT;
curItem.iImage= 1;
curItem.fmt= HDF_LEFT | HDF_IMAGE | HDF_STRING;
pHdrCtrl->SetItem(1, &curItem);
}
void CCallLogDlg::RenewListCtrl(DWORD dwStyle, BOOL bSetBits)
{
DWORD dwStyleOld, dwExtStyles;
CRect rect;
dwStyleOld = GetWindowLong(m_listctrl.m_hWnd, GWL_STYLE);
if (bSetBits)
dwStyleOld |= dwStyle; // turn on bits specified by caller.
else
dwStyleOld &= ~dwStyle; // turn off bits specified by caller.
m_listctrl.GetWindowRect(&rect);
ScreenToClient(&rect);
dwExtStyles= m_listctrl.GetExtendedStyle(); //save extended styles
m_listctrl.DestroyWindow();
m_listctrl.Create(dwStyleOld, rect, this, IDC_LIST_PHONEBOOK);
m_listctrl.ModifyStyleEx(0,WS_EX_CLIENTEDGE); // renew the 3D border of the control
m_listctrl.SetExtendedStyle(dwExtStyles);
FillListCtrl(); // repopulate with a new item group
// work areas are not carried over with the new control
m_listctrl.SetWorkAreas(0, NULL);
UpdateData(FALSE); // update the dialog
}
void CCallLogDlg::ChangeListCtrlStyle(DWORD dwStyle, BOOL bSetBits)
{
CRect rect;
m_listctrl.GetWindowRect(&rect);
ScreenToClient(&rect);
ASSERT(dwStyle != 0); // watch out for LVS_foo DEFINITIONS which are 0.
if (bSetBits)
m_listctrl.ModifyStyle(0, dwStyle);
else
m_listctrl.ModifyStyle(dwStyle, 0);
InvalidateRect(rect);
UpdateData(FALSE); // send information back to the dialog
}
void CCallLogDlg::ChangeView(long style)
{
long lStyle,lStyleOld;
lStyle = style;
lStyleOld = GetWindowLong(m_listctrl.m_hWnd, GWL_STYLE);
lStyleOld &= ~(LVS_TYPEMASK); // turn off all the style (view mode) bits
lStyleOld |= lStyle; // Set the new style for the control
SetWindowLong(m_listctrl.m_hWnd, GWL_STYLE, lStyleOld);
}
void CCallLogDlg::InsertRow(CString m_sCallNum, CString m_sCallTime, CString m_sCallEndTime,CString m_sState)
{
LV_ITEM lvitem;
int iIcon, iSubItem, iActualItem;
CString strCallTime, strCallNum,strState,strCallName,strCallEndTime;
LPTSTR pStrTemp1, pStrTemp2, pStrTemp3,pStrTemp4,pStrTemp5;
strCallTime = m_sCallTime;
strCallNum = m_sCallNum;
strState = m_sState;
strCallName = "";
if(strState=="1"){
strState.LoadString(IDS_ACCEPTED);
strCallEndTime = m_sCallEndTime;
iIcon =0;
}else{
strState.LoadString(IDS_REJECTED);
strCallEndTime = "";
iIcon = 1;
}
ASSERT(m_pMap!=NULL);
m_pMap->Lookup((LPCTSTR)strCallNum,(CString&)strCallName);
pStrTemp5= strCallName.GetBuffer(strCallName.GetLength());
CNetproApp *pApp;
pApp = (CNetproApp *)AfxGetApp();
// calculate the main and sub-item strings for the current item
pStrTemp1= strCallNum.GetBuffer(strCallNum.GetLength());
pStrTemp2= strCallTime.GetBuffer(strCallTime.GetLength());
pStrTemp3= strCallEndTime.GetBuffer(strCallEndTime.GetLength());
pStrTemp4= strState.GetBuffer(strState.GetLength());
for (iSubItem = 0; iSubItem < 5; iSubItem++)
{
lvitem.mask = LVIF_TEXT | (iSubItem == 0? LVIF_IMAGE : 0);
lvitem.iItem = (iSubItem == 0)? iItem : iActualItem;
lvitem.iSubItem = iSubItem;
switch(iSubItem){
case 0:
lvitem.pszText = pStrTemp1;
break;
case 1:
lvitem.pszText = pStrTemp2;
break;
case 2:
lvitem.pszText = pStrTemp3;
break;
case 3:
lvitem.pszText = pStrTemp4;
break;
case 4:
lvitem.pszText = pStrTemp5;
break;
}
lvitem.iImage = iIcon;
if (iSubItem == 0)
iActualItem = m_listctrl.InsertItem(&lvitem); // insert new item
else
m_listctrl.SetItem(&lvitem); // modify existing item (the sub-item text)
}
iItem=iActualItem+1;
}
void CCallLogDlg::OnClear()
{
CString s1,s2;
s1.LoadString(IDS_CONFIRM_DEL_CALLLOG);
s2.LoadString(IDS_CALL_LOG);
if(MessageBox(s1,s2,MB_ICONWARNING|MB_OKCANCEL)==IDOK){
if(!m_pList->IsEmpty( ))
m_pList->RemoveAll();
m_listctrl.DeleteAllItems();
::EnableWindow(GetDlgItem(IDB_CLEAR)->GetSafeHwnd(),FALSE);
}
}
void CCallLogDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -