📄 mailmonitordlg.cpp
字号:
/*
MailMonitorDlg.cpp
Ventana principal con todas las opciones para el usuario.
Autor: Sergio Scarnatto
*/
#include "stdafx.h"
#include "MailMonitor.h"
#include "MailMonitorDlg.h"
#include "Ingresoclave.h"
#include "mmsystem.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CString _ver;
_ver.LoadString(IDS_VERSIONAPP);
((CStatic*) GetDlgItem(IDC_LINEA1))->SetWindowText
("MailMonitor++ version "+_ver + "\
\n\nBy Sergio Luis Scarnatto, 2004\nsergiols@keko.com.ar");
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
/////////////////////////////////////////////////////////////////////////////
// CMailMonitorDlg dialog
CMailMonitorDlg::CMailMonitorDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMailMonitorDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMailMonitorDlg)
m_chk_sonido = FALSE;
m_chk_iniwindows = FALSE;
m_chk_inimailprg = FALSE;
m_chk_guardarclave = FALSE;
m_buscarcada = _T("");
m_clave = _T("");
m_cuenta = _T("");
m_servidor = _T("");
m_chk_usedefaultsound = FALSE;
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
popUp.LoadMenu(IDR_POPUP);
pMenu = popUp.GetSubMenu(0);
bInTrayIcon = FALSE;
m_chk_sonido = TRUE;
bManualCheck = false;
m_strMsg = "";
bChecking = false;
bFlashIcon = false;
}
void CMailMonitorDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMailMonitorDlg)
DDX_Check(pDX, IDC_CHKPLAYSOUND, m_chk_sonido);
DDX_Check(pDX, IDC_CHKINI_WINDOWS, m_chk_iniwindows);
DDX_Check(pDX, IDC_CHKINI_MAILPROGRAM, m_chk_inimailprg);
DDX_Check(pDX, IDC_CHKGUARDARCLAVE, m_chk_guardarclave);
DDX_Text(pDX, IDC_BUSCARCADA, m_buscarcada);
DDX_Text(pDX, IDC_CLAVE, m_clave);
DDX_Text(pDX, IDC_CUENTA, m_cuenta);
DDX_Text(pDX, IDC_SERVIDOR, m_servidor);
DDX_Check(pDX, IDC_CHK_USEDEFAULTSOUND, m_chk_usedefaultsound);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMailMonitorDlg, CDialog)
//{{AFX_MSG_MAP(CMailMonitorDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_COMMAND(ID_SALIR, OnSalir)
ON_COMMAND(ID_OPCIONES, OnOpciones)
ON_COMMAND(ID_DUMMY_CHECKMAIL, OnDummyCheckmail)
ON_BN_CLICKED(IDC_BTNCHECKNOW, OnBtnchecknow)
ON_BN_CLICKED(IDC_BTNACEPTAR, OnBtnaceptar)
ON_BN_CLICKED(IDC_BTNCHOOSESOUND, OnBtnchoosesound)
ON_BN_CLICKED(IDC_BTNCHOOSEMAILPRG, OnBtnchoosemailprg)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_CHK_USEDEFAULTSOUND, OnChkUsedefaultsound)
ON_BN_CLICKED(IDC_CHKINI_MAILPROGRAM, OnChkiniMailprogram)
ON_BN_CLICKED(IDC_CANCELAR, OnCancel)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_TRAYICON, OnTrayIcon)
ON_MESSAGE(WM_TASKBARNOTIFIERCLICKED, OnTaskbarNotifierClicked)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMailMonitorDlg message handlers
BOOL CMailMonitorDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
m_wndTaskbarNotifier1.Create(this);
m_wndTaskbarNotifier1.SetBitmap(IDB_SKIN_MSN);
m_wndTaskbarNotifier1.SetTextFont("Arial", 85, TN_TEXT_NORMAL | TN_TEXT_BOLD, TN_TEXT_UNDERLINE | TN_TEXT_BOLD);
m_wndTaskbarNotifier1.SetTextColor(RGB(0, 0, 0), RGB(0, 0, 200));
m_wndTaskbarNotifier1.SetTextRect(CRect(10, 100, m_wndTaskbarNotifier1.m_nBitmapWidth - 5, m_wndTaskbarNotifier1.m_nBitmapHeight - 5));
GetDlgItem(IDC_SERVIDOR)->SetWindowText(ud.getServidor());
GetDlgItem(IDC_CUENTA)->SetWindowText(ud.getUsuario());
GetDlgItem(IDC_CLAVE)->SetWindowText(ud.getClave());
((CButton*)GetDlgItem(IDC_CHKGUARDARCLAVE))->SetCheck(ud.getGuardarClave());
CString s;
s.Format("%d", ud.getBuscarCada());
GetDlgItem(IDC_BUSCARCADA)->SetWindowText(s);
((CButton*)GetDlgItem(IDC_CHKINI_MAILPROGRAM))->SetCheck(ud.getbIniciarMailPrg());
((CButton*)GetDlgItem(IDC_CHKINI_WINDOWS))->SetCheck(ud.getbIniciarConWindows());
((CButton*)GetDlgItem(IDC_CHKPLAYSOUND))->SetCheck(ud.getbPlaySound());
((CButton*)GetDlgItem(IDC_CHK_USEDEFAULTSOUND))->SetCheck(ud.getbUseDefSound());
OnChkUsedefaultsound();
OnChkiniMailprogram();
SetReloj();
GetDlgItem(IDC_CUENTA)->SetFocus();
SetTimer(2, 500, NULL);
return FALSE; // return TRUE unless you set the focus to a control
}
void CMailMonitorDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CMailMonitorDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x =(rect.Width() - cxIcon + 1) / 2;
int y =(rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
HCURSOR CMailMonitorDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
static void PlaySound(LPCTSTR lpszSound)
{
HRSRC hRes; // resource handle to wave file
HGLOBAL hData;
BOOL bOk = FALSE;
if ((hRes = ::FindResource(AfxGetResourceHandle(), lpszSound,
_T("sound"))) != NULL &&
(hData = ::LoadResource(AfxGetResourceHandle(), hRes)) != NULL)
{
// found the resource, play it
bOk = sndPlaySound((LPCTSTR)::LockResource(hData),
SND_MEMORY | SND_ASYNC | SND_NODEFAULT);
FreeResource(hData);
}
if (!bOk)
{
static BOOL bReported = FALSE;
if (!bReported)
{
AfxMessageBox(IDS_CANNOT_PLAY_SOUND);
bReported = TRUE; // once please
}
}
}
void CMailMonitorDlg::Dispatch(LONG param)
{
CString s;
switch (param)
{
case S_CONNECT:
bSinErrores = false;
break;
case S_CLOSE:
if (! bSinErrores && bManualCheck)
{
if (! bInTrayIcon)
m_pBalloonTip = CBalloonTip::Show(GetDlgItem(IDC_BTNCHECKNOW),
pop3.GetError());
else
{
m_strMsg = pop3.GetError();
// PlaySound("IDR_CHECKERROR");
m_wndTaskbarNotifier1.Show(m_strMsg, 200, 3000, 200);
}
}
else
{
if (m_chk_inimailprg && pop3.NewMessages())
showExplorer(ud.getMailProgramFN());
}
if (bInTrayIcon)
{
SetTrayIcon();
Shell_NotifyIcon(NIM_MODIFY, &tnid);
}
break;
case S_ENDRETR:
if (pop3.GetNumMsg()>0)
bSinErrores = true;
if (bInTrayIcon)
{
SetTrayIcon();
Shell_NotifyIcon(NIM_MODIFY, &tnid);
}
if (pop3.GetNumMsg()>0 &&(pop3.NewMessages() || bManualCheck))
{
if (pop3.NewMessages() >0)
{
if (bInTrayIcon)
SetTimer(3, 1000, NULL);
if (pop3.NewMessages() == 1)
{
s.LoadString(IDS_NUEVOMENSAJE_DE);
m_strMsg.Format(s,pop3.GetFromUltMensaje());
}
else
{
s.LoadString(IDS_NUEVOSMENSAJES);
m_strMsg.Format(s, pop3.NewMessages());
}
}
else
{
s.LoadString(IDS_TIENEMENSAJES);
m_strMsg.Format(s, pop3.GetNumMsg());
}
if (m_chk_sonido)
if (ud.getSoundFN() == "" || m_chk_usedefaultsound)
PlaySound("IDR_NEWEMAIL");
else
PlaySound(ud.getSoundFN(), NULL, SND_ASYNC | SND_NODEFAULT);
m_wndTaskbarNotifier1.Show(m_strMsg, 600, 6000, 200);
}
break;
default:;
}
}
void CMailMonitorDlg::MostrarTrayIcon()
{
CString _tipmsg;
tnid.cbSize = sizeof(NOTIFYICONDATA);
tnid.hWnd = m_hWnd;
tnid.uID = 1;
tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
tnid.uCallbackMessage = WM_TRAYICON;
SetTrayIcon();
_tipmsg.LoadString(IDS_TRAYCAPTION);
lstrcpy(tnid.szTip, _tipmsg);
bInTrayIcon = Shell_NotifyIcon(NIM_ADD, &tnid);
}
void CMailMonitorDlg::QuitarTrayIcon()
{
if (bInTrayIcon)
{
tnid.cbSize = sizeof(NOTIFYICONDATA);
tnid.hWnd = m_hWnd;
tnid.uID = 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -