?? 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"
#include "enbitmap.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)
ON_COMMAND(ID_EXPORT, OnExport)
ON_COMMAND(ID_IMPORT, OnImport)
//}}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 ),
#ifdef USE_SSL
m_SSL(TRUE),
#endif
bIsSuspended( false )
{
m_nMsgPropPage = 0;
m_dwFlags = MMF_DEFAULT;
m_nMaxLogSize = 50;
m_clrFriends = RGB(0, 255, 0);
m_bUseIni = FALSE;
m_bExited = FALSE;
}
CMagicApp::~CMagicApp()
{
// this should fix not saving settings on Windows shutdown
// when ExitInstance is not called
#ifdef USE_SSL
#endif
if (!m_bExited)
SaveSettings(NULL);
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CMagicApp object
CMagicApp theApp;
class CStorageHelper
{
public:
CStorageHelper(CWinApp* p, LPCTSTR sFile)
{
if (!sFile || !p)
{
pApp = NULL;
return;
}
pApp = p;
szRegistry = p->m_pszRegistryKey;
p->m_pszRegistryKey = NULL;
szApp = p->m_pszProfileName;
p->m_pszProfileName = sFile;
};
~CStorageHelper()
{
if (!pApp)
return;
pApp->m_pszRegistryKey = szRegistry;
pApp->m_pszProfileName = szApp;
};
protected:
CWinApp* pApp;
LPCTSTR szRegistry;
LPCTSTR szApp;
};
/////////////////////////////////////////////////////////////////////////////
// CMagicApp initialization
void CMagicApp::LoadSettings(LPCTSTR sFile)
{
CStorageHelper Helper(this, sFile);
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
GET_INT( intMVMode );
if (intMVMode == LVS_ICON)
intMVMode = LVS_REPORT;
// 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( strApp );
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);
if (m_dwFlags & MMF_FONT)
{
CString sMainFont;
GET_STR( sMainFont );
LF2String(m_lfMain, sMainFont, FALSE);
}
}
BOOL CMagicApp::InitInstance()
{
if (!AfxSocketInit())
{
AfxMessageBox( IDP_SOCKETS_INIT_FAILED );
return FALSE;
}
CString sVer;
GetWinVer(sVer, &m_nWindowsVersion);
CString sCfg;
if (FindLocalFile(_T("magic.ini"), sCfg, FALSE))
{
if (GetPrivateProfileInt(_T("version"), _T("version"), 0, sCfg) >0 ||
GetPrivateProfileInt(_T("settings"), _T("m_dwFlags"), -1, sCfg) >=0) // data was saved here
m_bUseIni = TRUE; // load from ini
// else load from registry and switch to ini afterwards
}
else
sCfg.Empty();
if (!m_bUseIni)
{
SetRegistryKey( _T("Orient Lab") );
}
else
{
if (m_pszProfileName)
free((void*)m_pszProfileName);
m_pszProfileName=_tcsdup(sCfg);
}
LoadSettings(NULL);
// 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);
PrepareImages();
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);
if (!m_bUseIni && !sCfg.IsEmpty())
{
if (m_pszRegistryKey)
free((void*)m_pszRegistryKey);
m_pszRegistryKey = NULL;
if (m_pszProfileName)
free((void*)m_pszProfileName);
m_pszProfileName=_tcsdup(sCfg);
m_bUseIni = TRUE;
}
return TRUE;
}
// App command to run the dialog
void CMagicApp::OnAppAbout()
{
HINSTANCE hAbout = LoadLibrary( _T("about.dll") );
if( NULL != hAbout )
{
FARPROC fnAboutBox = GetProcAddress( hAbout, "ShowAboutBox" );
if( NULL != fnAboutBox )
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -