📄 crecievemaillistdlg.cpp
字号:
// CRecieveMailListDlg.cpp: implementation of the CRecieveMailListDlg class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CRecieveMailListDlg.h"
#include "resource.h"
#include "CMailImfDlg.h"
#include "CNewContactDlg.h"
#include "MailDate.h"
#include "CeUidlDB.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
extern CMailImfDlg g_cmailimfdlg;
extern HINSTANCE g_hInst;
extern HBITMAP g_readedmailmap;
extern HBITMAP g_newmailmap;
extern CeMailDate g_maildate;
extern CNewContactDlg g_newcontactdlg;
extern TCHAR g_username[ADDRESS_LENTH];
extern CeMailDate g_mailtrash;
extern CeUidlDB g_uiddb;
CRecieveMailListDlg g_recievemaillistdlg;
CRecieveMailListDlg::CRecieveMailListDlg()
{
}
CRecieveMailListDlg::~CRecieveMailListDlg()
{
}
BOOL CALLBACK RecieveMailListDlgProc(const HWND hDlg, const UINT uiMessage, const WPARAM wParam, const LPARAM lParam)
{
BOOL bProcessedMsg = TRUE;
switch(uiMessage)
{
case WM_INITDIALOG:
CRecieveMailListDlg::InitialDlg(g_recievemaillistdlg,hDlg);
break;
case WM_MEASUREITEM: //Set the item height to 36 pixels
{
LPMEASUREITEMSTRUCT lpmi;
lpmi = (LPMEASUREITEMSTRUCT)lParam;
if(lpmi->CtlType == ODT_LISTVIEW)
{
lpmi->itemHeight = 30;
}
break;
}
case WM_DRAWITEM: //custom drawing code for owner-draw listview control
CRecieveMailListDlg::DrawItem(g_recievemaillistdlg,hDlg,lParam);
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case ID_MENUITEM_EXIT:
CRecieveMailListDlg::DestroyDlg(g_recievemaillistdlg,hDlg);
break;
case ID_MENUITEM_BYSIZE:
g_maildate.OpenMailInfoDB(NULL,g_username,PID_SIZE);
ListView_SetItemCount(g_recievemaillistdlg.m_view,g_maildate.GetDBRecordsNum(g_username));
g_recievemaillistdlg.m_curcep.propid = 0;
InvalidateRect(g_recievemaillistdlg.m_view,NULL,FALSE);
break;
case ID_MENUITEM_SBYADDRESS:
g_maildate.OpenMailInfoDB(NULL,g_username,PID_FROM);
ListView_SetItemCount(g_recievemaillistdlg.m_view,g_maildate.GetDBRecordsNum(g_username));
g_recievemaillistdlg.m_curcep.propid = 0;
InvalidateRect(g_recievemaillistdlg.m_view,NULL,FALSE);
break;
case ID_MENUITEM_SBYDATE:
g_maildate.OpenMailInfoDB(NULL,g_username,PID_DATE);
ListView_SetItemCount(g_recievemaillistdlg.m_view,g_maildate.GetDBRecordsNum(g_username));
g_recievemaillistdlg.m_curcep.propid = 0;
InvalidateRect(g_recievemaillistdlg.m_view,NULL,FALSE);
break;
case ID_MENUITEM_FNONE:
g_recievemaillistdlg.m_curcep.propid = 0;
ListView_SetItemCount(g_recievemaillistdlg.m_view,g_maildate.GetDBRecordsNum(g_username));
g_maildate.OpenMailInfoDB(NULL,g_username,PID_DATE);
InvalidateRect(g_recievemaillistdlg.m_view,NULL,FALSE);
break;
case ID_MENUITEM_FNEWMAIL:
{
g_recievemaillistdlg.m_curcep.propid = PID_READED;
g_recievemaillistdlg.m_curcep.wFlags = 0;
g_recievemaillistdlg.m_curcep.wLenData = 0;
g_recievemaillistdlg.m_curcep.val.lVal = 0;
g_maildate.OpenMailInfoDB(NULL,g_username,PID_READED);
ListView_SetItemCount(g_recievemaillistdlg.m_view,g_maildate.GetNumDisplay(g_username,&g_recievemaillistdlg.m_curcep,1));
InvalidateRect(g_recievemaillistdlg.m_view,NULL,FALSE);
break;
}
case ID_MENUITEM_SAVEADDRESS:
{
CRecieveMailListDlg::DoAddContact(g_recievemaillistdlg,hDlg);
break;
}
case ID_MENUITEM_TORECYCLE:
{
CRecieveMailListDlg::MoveToRecycle(g_recievemaillistdlg,hDlg);
ListView_SetItemCount(g_recievemaillistdlg.m_view,g_maildate.GetNumDisplay(g_username,&g_recievemaillistdlg.m_curcep,1));
InvalidateRect(g_recievemaillistdlg.m_view,NULL,FALSE);
break;
}
case ID_MENUITEM_DELETE:
{
CRecieveMailListDlg::DeleteMail(g_recievemaillistdlg,hDlg);
ListView_SetItemCount(g_recievemaillistdlg.m_view,g_maildate.GetNumDisplay(g_username,&g_recievemaillistdlg.m_curcep,1));
InvalidateRect(g_recievemaillistdlg.m_view,NULL,FALSE);
break;
}
default:
if(BN_CLICKED == HIWORD(wParam))
{
MailInfoDB rmail;
int index = ListView_GetNextItem(g_recievemaillistdlg.m_view,-1,LVNI_SELECTED);
g_maildate.SeekToPos(index,&g_recievemaillistdlg.m_curcep);
g_maildate.ReadMailInfoDBRecord(rmail);
rmail.m_IsReaded = 1;
g_maildate.WriteMailInfoDB(rmail);
g_cmailimfdlg.m_prmail = &rmail;
CMailImfDlg::DlgBox(g_cmailimfdlg,g_hInst,hDlg);
}
break;
}
break;
case WM_CLOSE:
CRecieveMailListDlg::DestroyDlg(g_recievemaillistdlg,hDlg);
break;
case WM_HOTKEY:
if(VK_TBACK == HIWORD(lParam))
{
}
else
bProcessedMsg = FALSE;
break;
case WM_ACTIVATE:
{
DWORD dwFlags = LOWORD(wParam);
if(dwFlags != WA_INACTIVE)
{
SetFocus(g_recievemaillistdlg.m_view);
}
}
break;
case WM_NOTIFY:
if(IDC_LIST_MAIL == wParam)
{
CRecieveMailListDlg::OnListViewNotify(g_recievemaillistdlg,hDlg,lParam);
}
else
{
bProcessedMsg = FALSE;
}
break;
default:
bProcessedMsg = FALSE;
break;
}
return bProcessedMsg;
}
BOOL CRecieveMailListDlg::DlgBox(CRecieveMailListDlg& dlg,HINSTANCE hinstance, HWND parent)
{
dlg.m_result = DialogBox(hinstance,MAKEINTRESOURCE(IDD_DIALOG_RECIEVEMAILDLG),parent,(DLGPROC)RecieveMailListDlgProc);
if(dlg.m_result == -1)
return FALSE;
return TRUE;
}
BOOL CRecieveMailListDlg::InitialDlg(CRecieveMailListDlg &dlg, HWND hDlg)
{
TCHAR lpszSubTitle[30];
TCHAR headertitle[30];
// Specify that the dialog box should stretch full screen
SHINITDLGINFO shidi;
ZeroMemory(&shidi, sizeof(shidi));
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN;
shidi.hDlg = hDlg;
// Set up the menu bar
SHMENUBARINFO shmbi;
ZeroMemory(&shmbi, sizeof(shmbi));
shmbi.cbSize = sizeof(shmbi);
shmbi.hwndParent = hDlg;
shmbi.nToolBarId = IDR_MENUBAR_MAILBOXMENU;
shmbi.hInstRes = g_hInst;
// If we could not initialize the dialog box, return an error
if (!(SHInitDialog(&shidi) && SHCreateMenuBar(&shmbi)))
{
return FALSE;
}
// set the title bar
LoadString(g_hInst,IDS_STRING_RECIEVEMAILBOXDLG,lpszSubTitle,ARRAYSIZE(lpszSubTitle));
if (lpszSubTitle)
SetWindowText(hDlg,lpszSubTitle);
RECT rc;
GetClientRect(hDlg,&rc);
dlg.m_view = CreateWindow(WC_LISTVIEW, NULL,
WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_OWNERDATA |LVS_OWNERDRAWFIXED | WS_BORDER,
rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
hDlg, (HMENU)IDC_LIST_MAILBOXLISTVIEW, g_hInst,NULL);
ListView_SetExtendedListViewStyle(dlg.m_view,
ListView_GetExtendedListViewStyle(dlg.m_view) | LVS_EX_FULLROWSELECT);
//添加列
dlg.m_columwidth[0] = (rc.right-rc.left)*3/5;
LV_COLUMN lvColumn;
lvColumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_WIDTH |LVCF_TEXT;
lvColumn.fmt = LVCFMT_LEFT;
lvColumn.cx = dlg.m_columwidth[0];
LoadString(g_hInst,IDS_STRING_MAILFROM,headertitle,30);
lvColumn.pszText = headertitle;
if(-1 == ListView_InsertColumn(dlg.m_view,0, &lvColumn))
{
return FALSE;
}
dlg.m_columwidth[1] = (rc.right - rc.left)*3/5;
lvColumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_WIDTH |LVCF_TEXT;
lvColumn.fmt = LVCFMT_LEFT;
lvColumn.cx = dlg.m_columwidth[1];
LoadString(g_hInst,IDS_STRING_MAILSUBJECT,headertitle,30);
lvColumn.pszText = headertitle;
if(-1 == ListView_InsertColumn(dlg.m_view,1, &lvColumn))
{
return FALSE;
}
dlg.m_columwidth[2] = (rc.right - rc.left)*2/5+4;
lvColumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_WIDTH |LVCF_TEXT;
lvColumn.fmt = LVCFMT_LEFT;
lvColumn.cx = dlg.m_columwidth[2];
LoadString(g_hInst,IDS_STRING_MAILDATE,headertitle,30);
lvColumn.pszText = headertitle;
if(-1 == ListView_InsertColumn(dlg.m_view,2, &lvColumn))
{
return FALSE;
}
dlg.m_columwidth[3] = (rc.right - rc.left)/4 + 5;
lvColumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_WIDTH |LVCF_TEXT;
lvColumn.fmt = LVCFMT_LEFT;
lvColumn.cx = dlg.m_columwidth[3];
LoadString(g_hInst,IDS_STRING_MAILSIZE,headertitle,30);
lvColumn.pszText = headertitle;
if(-1 == ListView_InsertColumn(dlg.m_view,3, &lvColumn))
{
return FALSE;
}
//Overriding Back button functionality
(void)SendMessage(shmbi.hwndMB, SHCMBM_OVERRIDEKEY, VK_TBACK,
MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY,
SHMBOF_NODEFAULT | SHMBOF_NOTIFY));
//db operation
if(g_maildate.FindDatebase(g_username,DATABASE_TYPE) == FALSE)
{
g_maildate.CreateMailInfoDB(g_username);
}
g_maildate.ReadAllMailInfo(g_username);
ListView_SetItemCount(dlg.m_view,g_maildate.GetDBRecordsNum(g_username));
return TRUE;
}
BOOL CRecieveMailListDlg::DestroyDlg(CRecieveMailListDlg &dlg, HWND hDlg)
{
if(!EndDialog(hDlg,dlg.m_result))
return FALSE;
return TRUE;
}
LRESULT CRecieveMailListDlg::OnListViewNotify(CRecieveMailListDlg &dlg, HWND hDlg, LPARAM lParam)
{
NMHDR* pnmh = (NMHDR*) lParam;
LRESULT lResult = 0;
switch(pnmh->code)
{
case LVN_GETDISPINFO:
break;
case LVN_ITEMACTIVATE:
break;
case LVN_ODFINDITEM:
break;
}
return(lResult);
}
void CRecieveMailListDlg::DrawItem(CRecieveMailListDlg &dlg, HWND hDlg, LPARAM lParam)
{
LPDRAWITEMSTRUCT lpdis;
lpdis = (LPDRAWITEMSTRUCT)lParam;
MailInfoDB rmail;
HDC hdc;
int index;
if(lpdis->CtlType != ODT_LISTVIEW)
return ;
LPCTSTR lpszText = (LPCTSTR) lpdis->itemData;
index = lpdis->itemID;
hdc = lpdis->hDC;
g_maildate.SeekToPos(index,&dlg.m_curcep);
g_maildate.ReadMailInfoDBRecord(rmail);
//draw the back ground
COLORREF crOldTextColor = GetTextColor(hdc);
COLORREF crOldBkColor = GetBkColor(hdc);
HBRUSH hbrBkColor = CreateSolidBrush (crOldBkColor);
HBRUSH hbrSEL = CreateSolidBrush (GetSysColor(COLOR_HIGHLIGHT));
if ((lpdis->itemAction | ODA_SELECT) && (lpdis->itemState & ODS_SELECTED))
{
SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
FillRect(hdc, &lpdis->rcItem,hbrSEL);
}
else
FillRect(hdc, &lpdis->rcItem,hbrBkColor);
DeleteObject (hbrSEL);
DeleteObject (hbrBkColor);
if(!rmail.m_IsReaded)
{
HDC hdcTemp = CreateCompatibleDC(hdc);
SelectObject(hdcTemp, g_newmailmap);
BITMAP bm;
GetObject(g_newmailmap, sizeof(BITMAP), &bm);
BOOL res = TransparentImage(hdc,lpdis->rcItem.left+2,(lpdis->rcItem.top+5), bm.bmWidth, bm.bmHeight, hdcTemp,0,0,bm.bmWidth, bm.bmHeight,RGB(255,255,255));
DeleteDC(hdcTemp);
}
else
{
HDC hdcTemp = CreateCompatibleDC(hdc);
SelectObject(hdcTemp, g_readedmailmap);
BITMAP bm;
GetObject(g_readedmailmap, sizeof(BITMAP), &bm);
BOOL res = TransparentImage(hdc,lpdis->rcItem.left+2,(lpdis->rcItem.top+5), bm.bmWidth, bm.bmHeight, hdcTemp,0,0,bm.bmWidth, bm.bmHeight,RGB(255,255,255));
DeleteDC(hdcTemp);
}
RECT textrc;
TCHAR buffer[80];
//draw address
textrc.bottom = lpdis->rcItem.bottom;
textrc.top = lpdis->rcItem.top;
textrc.right = lpdis->rcItem.left + dlg.m_columwidth[0];
textrc.left = lpdis->rcItem.left + 18;
if(lstrlen(rmail.m_Filename) < 14)
lstrcpy(buffer,rmail.m_From);
else
{
wcsncpy(buffer,rmail.m_From,14);
buffer[14] = '\n';
lstrcpy(buffer + 15,rmail.m_From + 14);
}
DrawText(hdc,buffer,-1,&textrc,DT_WORDBREAK);
//draw sub
textrc.left = lpdis->rcItem.left + dlg.m_columwidth[0]+6;
textrc.right = lpdis->rcItem.left + dlg.m_columwidth[0] + dlg.m_columwidth[1];
if(lstrlen(rmail.m_Subject) < 16)
lstrcpy(buffer,rmail.m_Subject);
else
{
wcsncpy(buffer,rmail.m_Subject,16);
buffer[16] = '\n';
lstrcpy(buffer + 17,rmail.m_Subject + 16);
}
DrawText(hdc,buffer,-1,&textrc,DT_WORDBREAK);
// draw time
SYSTEMTIME systime = rmail.m_Date;
wsprintf(buffer,L"%04d.%02d.%02d\n%02d : %02d ",systime.wYear,systime.wMonth,systime.wDay,systime.wHour,systime.wMinute);
textrc.left = lpdis->rcItem.left + dlg.m_columwidth[0] + dlg.m_columwidth[1]+6;
textrc.right = lpdis->rcItem.left + dlg.m_columwidth[0] + dlg.m_columwidth[1] + dlg.m_columwidth[2];
DrawText(hdc,buffer,-1,&textrc,DT_WORDBREAK);
//draw size;
textrc.left = lpdis->rcItem.left + dlg.m_columwidth[0] + dlg.m_columwidth[1]+ dlg.m_columwidth[2]+6;
textrc.right = lpdis->rcItem.left + dlg.m_columwidth[0] + dlg.m_columwidth[1] + dlg.m_columwidth[2]+ dlg.m_columwidth[3];
if(rmail.m_Size < 1024)
{
wsprintf(buffer,L"%d B",rmail.m_Size);
}
else
{
wsprintf(buffer,L"%.2f KB",rmail.m_Size / 1024.0);
}
DrawText(hdc,buffer,-1,&textrc,DT_WORDBREAK);
SetTextColor(hdc,crOldTextColor);
SetBkColor(hdc,crOldBkColor);
ReleaseDC (dlg.m_view, hdc);
}
BOOL CRecieveMailListDlg::DoAddContact(CRecieveMailListDlg &dlg, HWND hDlg)
{
MailInfoDB rmail;
int index = ListView_GetNextItem(dlg.m_view,-1,LVNI_SELECTED);
if(index == -1)
return FALSE;
g_maildate.SeekToPos(index,&dlg.m_curcep);
g_maildate.ReadMailInfoDBRecord(rmail);
lstrcpy(g_newcontactdlg.m_address,rmail.m_From);
g_newcontactdlg.m_addcontact = TRUE;
g_newcontactdlg.CreateDlg(hDlg,g_hInst);
return TRUE;
}
BOOL CRecieveMailListDlg::DeleteMail(CRecieveMailListDlg &dlg, HWND hDlg)
{
MailInfoDB rmail;
int index = ListView_GetNextItem(dlg.m_view,-1,LVNI_SELECTED);
if(index == -1)
return FALSE;
g_maildate.SeekToPos(index,&dlg.m_curcep);
g_maildate.ReadMailInfoDBRecord(rmail);
g_maildate.DeleteMailInfoDBRecord(rmail);
g_uiddb.OpenUidlDB(g_username,0);
g_uiddb.DeleteDBRecord(rmail.m_uidl);
BOOL res = DeleteFile(rmail.m_Filename);
return res;
}
BOOL CRecieveMailListDlg::MoveToRecycle(CRecieveMailListDlg &dlg, HWND hDlg)
{
MailInfoDB rmail;
BOOL res;
int index = ListView_GetNextItem(dlg.m_view,-1,LVNI_SELECTED);
if(index == -1)
return FALSE;
g_maildate.SeekToPos(index,&dlg.m_curcep);
g_maildate.ReadMailInfoDBRecord(rmail);
g_maildate.DeleteMailInfoDBRecord(rmail);
rmail.m_ceoid = 0;
res = g_mailtrash.OpenMailInfoDB(0,g_username,0);
res = g_mailtrash.WriteMailInfoDB(rmail);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -