📄 mailmonitordlg.cpp
字号:
Shell_NotifyIcon(NIM_DELETE, &tnid);
bInTrayIcon = false;
}
}
LRESULT CMailMonitorDlg::OnTrayIcon(WPARAM wParam, LPARAM lParam)
{
UINT uMouseMsg;
uMouseMsg = (UINT)lParam;
if (uMouseMsg == WM_LBUTTONDOWN || uMouseMsg == WM_RBUTTONDOWN)
{
LPPOINT pPunto;
pPunto = (LPPOINT)malloc(sizeof(POINT));
GetCursorPos(pPunto);
// Display the menu at the current mouse location. There's a "bug"
// (Microsoft calls it a feature) in Windows 95 that requires calling
// SetForegroundWindow. To find out more, search for Q135788 in MSDN.
::SetForegroundWindow(m_hWnd);
::TrackPopupMenu(pMenu->m_hMenu, TPM_CENTERALIGN, ((pPunto->x) + 20),
((pPunto->y) - 10), 0, m_hWnd, NULL);
free(pPunto);
}
/*
if (uMouseMsg == WM_MOUSEMOVE)
{
if (bInTrayIcon == TRUE)
{
Shell_NotifyIcon(NIM_MODIFY, &tnid);
}
}
*/
return 0;
}
void CMailMonitorDlg::OnCancel()
{
UpdateData(TRUE);
grabaropciones();
UpdateData(FALSE);
QuitarTrayIcon();
CDialog::OnCancel();
}
void CMailMonitorDlg::OnSalir()
{
UpdateData(TRUE);
grabaropciones();
UpdateData(FALSE);
QuitarTrayIcon();
EndDialog(0);
}
/*
getFile : Retorna el contenido de un archivo en internet en forma de lista
de cadenas.
Parametros:
url : Direcci髇 URL del archivo a leer.
*/
CString * CMailMonitorDlg::getFile(CString _url)
{
CString* _sfile = new CString;
CHttpFile *httpFile;
httpFile = (CHttpFile*)inetSession.OpenURL(_url/*,1,INTERNET_FLAG_TRANSFER_ASCII|
INTERNET_FLAG_RELOAD |
INTERNET_FLAG_DONT_CACHE*/);
CString aux;
try
{
while (httpFile->ReadString(aux))
{
*_sfile += aux + "\n";
}
}
catch (...)
{
//char szAux[255];
//ex.GetErrorMessage(szAux, 255);
//MessageBox(aux, "Error de HTTP", MB_OK);
return FALSE;
}
httpFile->Close();
delete httpFile;
return _sfile;
}
LRESULT CMailMonitorDlg::OnTaskbarNotifierClicked(WPARAM wParam, LPARAM lParam)
{
KillTimer(3);
SetTrayIcon();
if (ud.getMailProgramFN()!="")
showExplorer(ud.getMailProgramFN());
return 0;
}
void CMailMonitorDlg::OnOpciones()
{
this->ShowWindow(SW_SHOW);
QuitarTrayIcon();
}
void CMailMonitorDlg::showExplorer(CString url)
{
SHELLEXECUTEINFO ei;
memset(&ei, 0, sizeof(ei));
ei.cbSize = sizeof(ei);
ei.lpVerb = "open";
ei.lpFile = url;
ei.fMask = SEE_MASK_NOCLOSEPROCESS;
ei.nShow = SW_SHOWMAXIMIZED;
ShellExecuteEx(&ei);
}
void CMailMonitorDlg::OnDummyCheckmail()
{
OnBtnchecknow();
}
void CMailMonitorDlg::OnBtnchecknow()
{
if (! IsValid(TRUE))
return;
DoCheckMail(TRUE);
}
bool CMailMonitorDlg::IsValid(bool bShowError)
{
bool bvalidos;
bvalidos = true;
UpdateData(TRUE);
CString serror;
if (m_servidor.IsEmpty())
{
serror.LoadString(IDS_NOMSERVIDOR_INVALID);
bvalidos = false;
if (bShowError)
m_pBalloonTip = CBalloonTip::Show(GetDlgItem(IDC_SERVIDOR),
serror);
}
if (m_cuenta.IsEmpty())
{
serror.LoadString(IDS_NOMCUENTA_INVALID);
bvalidos = false;
if (bShowError)
m_pBalloonTip = CBalloonTip::Show(GetDlgItem(IDC_CUENTA),
serror);
}
if (m_clave.IsEmpty() && m_chk_guardarclave)
{
serror.LoadString(IDS_CLAVE_INVALID);
bvalidos = false;
if (bShowError)
m_pBalloonTip = CBalloonTip::Show(GetDlgItem(IDC_CLAVE),
serror);
}
if (m_buscarcada == "0" || m_buscarcada.IsEmpty())
{
serror.LoadString(IDS_BUSCARCADA_INVALID);
bvalidos = false;
if (bShowError)
m_pBalloonTip = CBalloonTip::Show(GetDlgItem(IDC_BUSCARCADA),
serror);
}
if (ud.getSoundFN() == "" && ! m_chk_usedefaultsound)
{
serror.LoadString(IDS_CHOOSESOUNDFN_INVALID);
bvalidos = false;
if (bShowError)
m_pBalloonTip = CBalloonTip::Show(GetDlgItem(IDC_BTNCHOOSESOUND),
serror);
}
if (ud.getMailProgramFN() == "" && m_chk_inimailprg)
{
serror.LoadString(IDS_CHOOSEMAILPRGFN_INVALID);
bvalidos = false;
if (bShowError)
m_pBalloonTip = CBalloonTip::Show(GetDlgItem(IDC_BTNCHOOSEMAILPRG),
serror);
}
return bvalidos;
}
void CMailMonitorDlg::OnBtnaceptar()
{
if (! IsValid(TRUE))
return;
DoTray();
}
void CMailMonitorDlg::OnBtnchoosesound()
{
CFileDialog dlg(TRUE, _T("wav"), ud.getSoundFN(),
OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_EXPLORER,
_T("Sound file (*.wav)|*.wav||"));
if (dlg.DoModal() == IDOK)
{
ud.setSoundFN(dlg.GetPathName());
}
}
void CMailMonitorDlg::OnBtnchoosemailprg()
{
CFileDialog dlg(TRUE, _T("exe"), ud.getMailProgramFN(),
OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_EXPLORER,
_T("Email client (*.exe)|*.exe||"));
if (dlg.DoModal() == IDOK)
{
ud.setMailProgramFN(dlg.GetPathName());
}
}
void CMailMonitorDlg::OnTimer(UINT nIDEvent)
{
if (nIDEvent == 1)
{
DoCheckMail(FALSE);
}
if (nIDEvent == 2)
{
KillTimer(2);
if (IsValid(FALSE))
{
if (m_bIniciarMinimizado)
DoTray();
if (m_chk_guardarclave)
DoCheckMail(TRUE);
}
m_bIniciarMinimizado = false;
}
if (nIDEvent == 3)
{
FlashTrayIcon();
Shell_NotifyIcon(NIM_MODIFY, &tnid);
}
CDialog::OnTimer(nIDEvent);
}
void CMailMonitorDlg::DoCheckMail(bool bManual)
{
if (bChecking)
return;
bChecking =true;
if (bManual)
{
KillTimer(3);
SetTrayIcon();
}
if (pop3.m_hSocket != INVALID_SOCKET)
{
pop3.JustClose();
pop3.m_hSocket = -1;
}
pop3.Set(this);
UpdateData(TRUE);
if (! m_chk_guardarclave && m_clave == "")
{
CIngresoClave dlg;
dlg.m_cuenta = m_cuenta;
switch (dlg.DoModal())
{
case IDCANCEL:
break;
case IDOK:
m_clave = dlg.m_Clave;
break;
}
}
grabaropciones();
pop3.SetUserData(&ud);
pop3.SetProp(m_cuenta, m_clave);
pop3.SetNomServer(m_servidor);
bManualCheck = bManual;
pop3.Create();
pop3.Connect(m_servidor, 110);
UpdateData(FALSE);
bChecking =false;
}
void CMailMonitorDlg::SetReloj()
{
if (IsValid(FALSE))
SetTimer(1, ud.getBuscarCada()*60000, NULL);
}
void CMailMonitorDlg::grabaropciones()
{
ud.setServidor(m_servidor);
#ifndef _NOSUFIJO
if (m_cuenta.Find("@")<0)
{
CString _sufijo;
_sufijo.LoadString(IDS_SUFIJO_EMAIL);
m_cuenta += _sufijo.TrimRight();
GetDlgItem(IDC_CUENTA)->SetWindowText(m_cuenta);
}
#endif
ud.setUsuario(m_cuenta);
ud.setClave(m_clave, m_chk_guardarclave);
ud.setbIniciarConWindows(m_chk_iniwindows);
ud.setbIniciarMailPrg(m_chk_inimailprg);
ud.setbPlaySound(m_chk_sonido);
ud.setBuscarCada(atoi(m_buscarcada));
ud.setbUseDefSound(m_chk_usedefaultsound);
ud.saveUsuario();
ud.saveClave();
}
void CMailMonitorDlg::OnChkUsedefaultsound()
{
if (((CButton*)GetDlgItem(IDC_CHK_USEDEFAULTSOUND))->GetCheck())
{
GetDlgItem(IDC_BTNCHOOSESOUND)->EnableWindow(FALSE);
}
else
{
GetDlgItem(IDC_BTNCHOOSESOUND)->EnableWindow(TRUE);
}
}
void CMailMonitorDlg::OnChkiniMailprogram()
{
if (((CButton*)GetDlgItem(IDC_CHKINI_MAILPROGRAM))->GetCheck())
{
GetDlgItem(IDC_BTNCHOOSEMAILPRG)->EnableWindow(TRUE);
}
else
{
GetDlgItem(IDC_BTNCHOOSEMAILPRG)->EnableWindow(FALSE);
}
}
void CMailMonitorDlg::DoTray()
{
this->ShowWindow(SW_HIDE);
MostrarTrayIcon();
grabaropciones();
SetReloj();
}
void CMailMonitorDlg::SetTrayIcon()
{
HICON hicon = NULL;
hicon = AfxGetApp()->LoadIcon(IDR_GOTMAIL);
tnid.hIcon = hicon;
}
void CMailMonitorDlg::FlashTrayIcon()
{
HICON hicon = NULL;
bFlashIcon = ! bFlashIcon;
if (bFlashIcon)
hicon = AfxGetApp()->LoadIcon(IDR_GOTMAIL);
else
hicon = AfxGetApp()->LoadIcon(IDR_GOTMAIL2);
tnid.hIcon = hicon;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -