📄 magic.cpp
字号:
// Copyright (C) 1997-2002 Valeriy Ovechkin
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// Magic.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "Magic.h"
#include "Excerpt.h"
#include "Mailbox.h"
#include "MagicFrame.h"
#include "MagicDoc.h"
#include "MailboxView.h"
#include "ExcerptView.h"
#include "getwinver.h"
#include "htmlhelp.h"
#include "afxpriv.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define GET_INT(a) (a) = theApp.GetProfileInt( _T("settings"), _T(#a), a );
#define GET_STR(a) (a) = theApp.GetProfileString( _T("settings"), _T(#a), a );
#define GET_BOOL(a) (a) = ( 0 != theApp.GetProfileInt( _T("settings"), _T(#a), a ) );
#define SET_INT(a) VERIFY( theApp.WriteProfileInt( _T("settings"), _T(#a), (a) ) );
#define SET_STR(a) VERIFY( theApp.WriteProfileString( _T("settings"), _T(#a), (a) ) );
#define SET_BOOL(a) VERIFY( theApp.WriteProfileInt( _T("settings"), _T(#a), (a) ) );
const TCHAR *cstrMultipleSelection = _T("...");
/////////////////////////////////////////////////////////////////////////////
// CMagicApp
BEGIN_MESSAGE_MAP(CMagicApp, CWinApp)
//{{AFX_MSG_MAP(CMagicApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMagicApp construction
CMagicApp::CMagicApp()
:
m_hCmdID( 0 ),
m_uMciID( 0 ),
intMVMode( LVS_REPORT ),
// intEVMode( LVS_REPORT ),
intMVSortColumn( COLUMN_ALIAS ),
intMVSortAscend( TRUE ),
intEVSortColumn( COLUMN_FROM ),
intEVSortAscend( TRUE ),
intSplitterPos( 100 ),
intMCAliasWidth( 120 ),
intMCAliasPos( COLUMN_ALIAS ),
intMCUserWidth( 60 ),
intMCUserPos( COLUMN_USER ),
intMCHostWidth( 120 ),
intMCHostPos( COLUMN_HOST ),
intMCMailWidth( 60 ),
intMCMailPos( COLUMN_MAIL ),
intMCStatWidth( 120 ),
intMCStatPos( COLUMN_STATE ),
intMCElapsedWidth( 60 ),
intMCElapsedPos( COLUMN_ELAPSED ),
intMCPortWidth( 60 ),
intMCPortPos( COLUMN_PORT ),
intMCPollWidth( 60 ),
intMCPollPos( COLUMN_POLL ),
intECMBoxWidth( 120 ),
intECMBoxPos( COLUMN_MBOX ),
intECFromWidth( 180 ),
intECFromPos( COLUMN_FROM ),
intECToWidth( 180 ),
intECToPos( COLUMN_TO ),
intECSubjWidth( 120 ),
intECSubjPos( COLUMN_SUBJ ),
intECDateWidth( 120 ),
intECDatePos( COLUMN_DATE ),
intECSizeWidth( 60 ),
intECSizePos( COLUMN_SIZE ),
rcWnd( 0, 0, 0, 0 ),
intPlayback( ACTION_NONE ),
intPlaybackDevice( PLAYBACK_DEVICE_FILE ),
intCommand( ACTION_NONE ),
intCommandRun( COMMAND_RUN_NORMAL ),
intStartAlwaysHidden( FALSE ),
intCheckImmediately( TRUE ),
intEVConfirmDelete( TRUE ),
intPopUpMainWindow( FALSE ),
intPreviewSize(5),
intEnableFilters(0),
intMarkRead(READ_VIEW),
strFileExtensionForMessages( _T("txt") ),
m_nWindowsVersion(WUNKNOWN),
intDblAction( ACT_QVIEW ),
intRBAction( ACT_MENU ),
intRB2Action( ACT_HEADER ),
bIsSuspended( false )
{
m_nMsgPropPage = 0;
m_dwFlags = MMF_DEFAULT;
m_nMaxLogSize = 50;
m_clrFriends = RGB(0, 255, 0);
}
CMagicApp::~CMagicApp()
{
// this should fix not saving settings on Windows shutdown
// when ExitInstance is not called
SaveSettings();
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CMagicApp object
CMagicApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CMagicApp initialization
BOOL CMagicApp::InitInstance()
{
// preload icons in full color (!)
::LoadImage( m_hInstance, MAKEINTRESOURCE( IDR_MAGICTYPE ), IMAGE_ICON, 32, 32,
LR_CREATEDIBSECTION | LR_SHARED );
// ::LoadImage( m_hInstance, MAKEINTRESOURCE( IDR_MAGICTYPE ), IMAGE_ICON, 16, 16,
// LR_CREATEDIBSECTION | LR_SHARED );
::LoadImage( m_hInstance, MAKEINTRESOURCE( IDR_MAINFRAME ), IMAGE_ICON, 32, 32,
LR_CREATEDIBSECTION | LR_SHARED );
// ::LoadImage( m_hInstance, MAKEINTRESOURCE( IDR_MAINFRAME ), IMAGE_ICON, 16, 16,
// LR_CREATEDIBSECTION | LR_SHARED );
if (!AfxSocketInit())
{
AfxMessageBox( IDP_SOCKETS_INIT_FAILED );
return FALSE;
}
CString sVer;
GetWinVer(sVer, &m_nWindowsVersion);
SetRegistryKey( _T("Orient Lab") );
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
GET_INT( intMVMode );
// GET_INT( intEVMode );
GET_INT( intMVSortColumn );
GET_INT( intMVSortAscend );
GET_INT( intEVSortColumn );
GET_INT( intEVSortAscend );
GET_INT( intSplitterPos );
GET_INT( intMCAliasWidth );
GET_INT( intMCAliasPos );
GET_INT( intMCUserWidth );
GET_INT( intMCUserPos );
GET_INT( intMCHostWidth );
GET_INT( intMCHostPos );
GET_INT( intMCMailWidth );
GET_INT( intMCMailPos );
GET_INT( intMCStatWidth );
GET_INT( intMCStatPos );
GET_INT( intMCElapsedWidth );
GET_INT( intMCElapsedPos );
GET_INT( intMCPortWidth );
GET_INT( intMCPortPos );
GET_INT( intMCPollWidth );
GET_INT( intMCPollPos );
GET_INT( intECMBoxWidth );
GET_INT( intECMBoxPos );
GET_INT( intECFromWidth );
GET_INT( intECFromPos );
GET_INT( intECToWidth );
GET_INT( intECToPos );
GET_INT( intECSubjWidth );
GET_INT( intECSubjPos );
GET_INT( intECDateWidth );
GET_INT( intECDatePos );
GET_INT( intECSizeWidth );
GET_INT( intECSizePos );
GET_INT( rcWnd.left );
GET_INT( rcWnd.top );
GET_INT( rcWnd.right );
GET_INT( rcWnd.bottom );
GET_INT( intPlayback );
GET_STR( strPlayback );
GET_INT( intPlaybackDevice );
GET_INT( intCommand );
GET_STR( strCommand );
GET_INT( intCommandRun );
GET_INT( intStartAlwaysHidden );
GET_INT( intCheckImmediately );
GET_INT( intEVConfirmDelete );
GET_INT( intPopUpMainWindow );
GET_INT( intPreviewSize);
GET_INT( intEnableFilters );
GET_INT( intMarkRead);
GET_STR( strFileExtensionForMessages );
GET_STR( strLastDiction );
GET_BOOL( bIsSuspended );
GET_INT(m_dwFlags);
GET_INT (m_nMaxLogSize);
GET_INT(m_clrFriends);
GET_INT(intDblAction);
GET_INT(intRBAction);
GET_INT(intRB2Action);
// check single instance condition
if (!m_Single.AmIFirst(_T("MagicMailMonitor3")))
{
if (m_dwFlags & MMF_SINGLE)
{
m_Single.SendData(1); // WM_COPYDATA with dwData = 1
return FALSE;
}
}
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
AddDocTemplate( new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CMagicDoc),
RUNTIME_CLASS(CMagicFrame), // main SDI frame window
RUNTIME_CLASS(CMailboxView)));
// Enable DDE Execute open
EnableShellOpen();
RegisterShellFileTypes(FALSE); // FALSE will disable print and ShellNew
// load last dictionary
if (strLastDiction.GetLength())
GetDictionary()->SetDictionary(strLastDiction, TRUE);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
if( intStartAlwaysHidden ) m_nCmdShow = SW_HIDE;
CString strFile;
strFile = GetProfileString( _T("Recent File List"), _T("File1"), strFile );
m_bReset = FALSE;
// Dispatch commands specified on the command line
if( CCommandLineInfo::FileNew != cmdInfo.m_nShellCommand ||
strFile.IsEmpty() ||
!OpenDocumentFile( strFile ) )
{
if( !ProcessShellCommand( cmdInfo ) ) return FALSE;
}
if (m_bReset)
m_pMainWnd->PostMessage(WM_COMMAND, ID_FILE_NEW);
// Enable drag/drop open
m_pMainWnd->DragAcceptFiles();
m_Single.Init(m_pMainWnd->m_hWnd);
return TRUE;
}
// App command to run the dialog
void CMagicApp::OnAppAbout()
{
HINSTANCE hAbout = AfxLoadLibrary( _T("about.dll") );
if( NULL != hAbout )
{
FARPROC fnAboutBox = GetProcAddress( hAbout, "ShowAboutBox" );
if( NULL != fnAboutBox )
{
fnAboutBox();
}
else
{
CString strMessage;
AfxFormatString1( strMessage, IDP_CANNOT_FIND_1, _T("ShowAboutBox (About.dll)") );
AfxMessageBox( strMessage, MB_ICONSTOP );
}
AfxFreeLibrary( hAbout );
}
else
{
CString strMessage;
AfxFormatString1( strMessage, IDP_CANNOT_FIND_1, _T("About.dll") );
AfxMessageBox( strMessage, MB_ICONSTOP );
}
}
/////////////////////////////////////////////////////////////////////////////
// CMagicApp commands
void CMagicApp::SaveSettings()
{
SET_INT( intMVMode );
// SET_INT( intEVMode );
SET_INT( intMVSortColumn );
SET_INT( intMVSortAscend );
SET_INT( intEVSortColumn );
SET_INT( intEVSortAscend );
SET_INT( intSplitterPos );
SET_INT( intMCAliasWidth );
SET_INT( intMCAliasPos );
SET_INT( intMCUserWidth );
SET_INT( intMCUserPos );
SET_INT( intMCHostWidth );
SET_INT( intMCHostPos );
SET_INT( intMCMailWidth );
SET_INT( intMCMailPos );
SET_INT( intMCStatWidth );
SET_INT( intMCStatPos );
SET_INT( intMCElapsedWidth );
SET_INT( intMCElapsedPos );
SET_INT( intMCPortWidth );
SET_INT( intMCPortPos );
SET_INT( intMCPollWidth );
SET_INT( intMCPollPos );
SET_INT( intECMBoxWidth );
SET_INT( intECMBoxPos );
SET_INT( intECFromWidth );
SET_INT( intECFromPos );
SET_INT( intECToWidth );
SET_INT( intECToPos );
SET_INT( intECSubjWidth );
SET_INT( intECSubjPos );
SET_INT( intECDateWidth );
SET_INT( intECDatePos );
SET_INT( intECSizeWidth );
SET_INT( intECSizePos );
SET_INT( rcWnd.left );
SET_INT( rcWnd.top );
SET_INT( rcWnd.right );
SET_INT( rcWnd.bottom );
SET_INT( intPlayback );
SET_STR( strPlayback );
SET_INT( intPlaybackDevice );
SET_INT( intCommand );
SET_STR( strCommand );
SET_INT( intCommandRun );
SET_INT( intStartAlwaysHidden );
SET_INT( intCheckImmediately );
SET_INT( intEVConfirmDelete );
SET_INT( intPopUpMainWindow );
SET_INT( intPreviewSize);
SET_INT( intEnableFilters );
SET_INT( intMarkRead);
SET_STR( strFileExtensionForMessages );
SET_STR( strLastDiction );
SET_BOOL( bIsSuspended );
SET_INT( m_dwFlags );
SET_INT( m_nMaxLogSize );
SET_INT(m_clrFriends);
SET_INT(intDblAction);
SET_INT(intRBAction);
SET_INT(intRB2Action);
}
BOOL CMagicApp::OnIdle(LONG lCount)
{
if( CWinApp::OnIdle(lCount) ) return TRUE;
if( m_pMainWnd ) m_pMainWnd->SendMessage( VM_UPDATEITEM );
return FALSE;
}
void BytesToString( int intSize, CString &strSize )
{
MAKE_STRING(strBytes, IDP_BYTES );
MAKE_STRING(strKiloBytes, IDP_KILOBYTES );
MAKE_STRING(strMegaBytes, IDP_MEGABYTES );
if( 1048576 <= intSize )
strSize.Format
(
_T("%.1f%s (%d %s)"),
float(intSize)/1048576.,
strMegaBytes,
intSize,
strBytes
);
else if( 1024 <= intSize )
strSize.Format
(
_T("%.1f%s (%d %s)"),
float(intSize)/1024.,
strKiloBytes,
intSize,
strBytes
);
else
strSize.Format
(
_T("%d %s"),
intSize,
strBytes
);
}
int CMagicApp::ExitInstance()
{
SaveSettings();
return CWinApp::ExitInstance();
}
HICON CMagicApp::LoadIcon( UINT nIDResource, bool Large ) const
{
int size = Large ? 32 : 16;
return (HICON) ::LoadImage
(
m_hInstance,
MAKEINTRESOURCE( nIDResource ),
IMAGE_ICON,
size, size,
LR_CREATEDIBSECTION | LR_SHARED
);
}
HBITMAP CMagicApp::LoadBitmap( UINT nIDResource ) const
{
return (HBITMAP) ::LoadImage
(
m_hInstance,
MAKEINTRESOURCE( nIDResource ),
IMAGE_BITMAP,
0, 0,
LR_CREATEDIBSECTION | LR_SHARED
);
}
int CMagicApp::DoMessageBox(LPCTSTR lpszPrompt, UINT nType, UINT nIDPrompt)
{
CString s;
if (lpszPrompt && _tcsstr(lpszPrompt, _T("$") _T("{")))
{
s = lpszPrompt;
StrTranslate(s);
lpszPrompt = s;
}
return CWinApp::DoMessageBox(lpszPrompt, nType, nIDPrompt);
}
void CMagicApp::GenDefaultFilters()
{
m_Filters.SetSize(1);
CMailFilter filter;
filter.m_sName = "Blacklist";
filter.m_aCnd[0].m_nField = MFF_FROM;
filter.m_aCnd[0].m_nOperation = MFO_EQUAL;
filter.m_aCnd[0].m_sText = "$blacklst.txt"; // get from file
filter.m_nCombination = MFC_NONE;
filter.m_dwAction = MFA_SPAM;
filter.m_sMailBox = "*"; // for all mailboxes
m_Filters.SetAt(0, filter);
}
LPCTSTR GetHelpFilePath()
{
return theApp.GetHelpFilePath();
}
void CMagicApp::WinHelp(DWORD dwData, UINT nCmd)
{
#ifdef USE_HTML_HELP
if (dwData>HID_BASE_RESOURCE && nCmd == 1)
{
HtmlHelp(AfxGetMainWnd()->m_hWnd, GetHelpFilePath(),
HH_HELP_CONTEXT, dwData/*-HID_BASE_RESOURCE*/);
}
else if (nCmd == 3)
HtmlHelp(AfxGetMainWnd()->m_hWnd, GetHelpFilePath(), HH_DISPLAY_TOC, 0);
/*
else if (dwData>HID_BASE_COMMAND && nCmd == 1)
HtmlHelp(AfxGetMainWnd()->m_hWnd, GetHelpFilePath(),
HH_HELP_CONTEXT, dwData-HID_BASE_RESOURCE);
*/
#else
CWinApp::WinHelp(dwData, nCmd);
#endif
}
LPCTSTR CMagicApp::GetHelpFilePath()
{
if (m_sHelpPath.IsEmpty())
{
CString s;
GetModuleFileName(NULL, s.GetBuffer(MAX_PATH+2), MAX_PATH);
s.ReleaseBuffer();
TCHAR szDrive[_MAX_DRIVE+1];
TCHAR szPath[_MAX_PATH+1];
TCHAR szName[_MAX_PATH+1];
_tsplitpath(s, szDrive, szPath, szName, NULL);
s.Format(_T("%s%s%s.chm"), szDrive, szPath, szName);
if (GetFileAttributes(s) != (DWORD)-1)
{
m_sHelpPath = s;
}
else
{
CFileFind find;
if (find.FindFile(_T("magic.chm")))
{
find.FindNextFile();
m_sHelpPath = find.GetFilePath();
}
}
}
return m_sHelpPath;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -