⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 magic.cpp

📁 强大易用的邮件收发客户端
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			fnAboutBox();
		}
		else
		{
			CString strMessage;
			AfxFormatString1( strMessage, IDP_CANNOT_FIND_1, _T("ShowAboutBox (About.dll)") );
			AfxMessageBox( strMessage, MB_ICONSTOP );
		}

		FreeLibrary( hAbout );
	}
	else
	{
		CString strMessage;
		AfxFormatString1( strMessage, IDP_CANNOT_FIND_1, _T("About.dll") );
		AfxMessageBox( strMessage, MB_ICONSTOP );
	}
}

void InitImageList(CImageList& img)
{
	CEnBitmap	bmp;
	CWindowDC SDC(NULL);  // screen device context
	int nRasterCaps= SDC.GetDeviceCaps(BITSPIXEL);
	BOOL bExtFile = FALSE;
	int nColors = 8;
	HANDLE hBitmap = NULL;
	if (nRasterCaps>=16)
	{
		CString sBmpFile;
		// try loading another picture
		bExtFile = FindLocalFile("mmm3small.bmp", sBmpFile, FALSE);
		if (bExtFile)
		{
			hBitmap = ::LoadImage(NULL, sBmpFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
			if (!hBitmap)
				bExtFile = FALSE;
			BITMAP bm;
			int nObj = CEnBitmap::GetFileData(sBmpFile, &bm);
			if (!nObj)
				bExtFile = FALSE;
			else 
				nColors = bm.bmBitsPixel;
		}
	}
	if (hBitmap && (nColors<32 || theApp.m_nWindowsVersion >= W2K))
	{
		bmp.Attach(hBitmap);
	}
	else
	{
		/*if (theApp.m_nWindowsVersion < WNTFIRST)
			bmp.LoadBitmap(IDB_ICONS_98);
		else*/
			bmp.LoadBitmap(IDB_MM_ICONS);
			nColors = 24;
	}
	if (nColors == 32)
	{
		img.Create(16, 16, ILC_COLOR32|ILC_MASK, II_COUNTER, 1);
		if (bmp.ApplyAlpha(GetSysColor(COLOR_WINDOW)))
			img.Add(&bmp, (CBitmap *)NULL);
		else
			img.Add(&bmp, GetSysColor(COLOR_WINDOW));
	}
	else
	{
		img.Create(16, 16, ILC_COLOR24|ILC_MASK, II_COUNTER, 1);
		img.Add(&bmp, RGB(255, 0, 255));
	}
}
void CMagicApp::PrepareImages()
{
	InitImageList(m_imgMailbox);
	InitImageList(m_imgMsg);

	VERIFY( m_imgMailbox.SetOverlayImage( II_FAIL, 1 ) );
	VERIFY( m_imgMailbox.SetOverlayImage( II_DISABLE, 2 ) );
	VERIFY( m_imgMailbox.SetOverlayImage( II_SECURE, 3 ) );
	
	VERIFY( m_imgMsg.SetOverlayImage( II_PRIORITY, 1 ) );
	VERIFY( m_imgMsg.SetOverlayImage( II_ATTACH, 2 ) );
	VERIFY( m_imgMsg.SetOverlayImage( II_ATTACH_PRIO, 3 ) );
	VERIFY( m_imgMsg.SetOverlayImage( II_SECURE, 4 ) );
}

/////////////////////////////////////////////////////////////////////////////
// CMagicApp commands

void CMagicApp::SaveSettings(LPCTSTR sFile)
{
	CStorageHelper Helper(this, sFile);

	if (m_bUseIni || sFile)	// mark a fact of using ini file
	{
		theApp.WriteProfileInt( _T("version"), _T("version"), 1 );
	}

	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( strApp );
	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);
	if (m_dwFlags & MMF_FONT)
	{
		CString sMainFont;
		LF2String(m_lfMain, sMainFont, TRUE);
		SET_STR( sMainFont );
	}
}

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() 
{
	m_bExited = TRUE;
	SaveSettings(NULL);
	
	
	// default implementation calls SaveStdProfileSettings(), which always updates ini
	// need to set m_pCmdInfo->m_nShellCommand == CCommandLineInfo::AppUnregister
	// to avoid this if list is same
	
	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);
		if (s.GetLength())
			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;
}
void	CMagicApp::SetFont(LOGFONT& lf)
{
	memcpy(&m_lfMain, &lf, sizeof(LOGFONT));
	m_fntMain.DeleteObject();
}
void	CMagicApp::SetDefFont(CFont* pF)
{
	LOGFONT lf;
	pF->GetObject(sizeof(LOGFONT), &lf);
	memcpy(&m_lfDef, &lf, sizeof(LOGFONT));
}
CFont*	CMagicApp::GetFont()
{
	LOGFONT* pLF = &m_lfMain;
	if ((m_dwFlags & MMF_FONT)==0)
		pLF = &m_lfDef;
	if (m_fntMain.m_hObject)
		return &m_fntMain;
	// if not set - do not use
	if (_tcslen(pLF->lfFaceName)<3)
		return FALSE;
	if (!m_fntMain.CreateFontIndirect(pLF))
		return NULL;
	return &m_fntMain;
}

static TCHAR BASED_CODE szFilter[] = _T( "Configuration files (*.ini)|*.ini|All Files (*.*)|*.*||");
void CMagicApp::OnExport() 
{
	CFileDialog dlg(FALSE, _T(".ini"), _T("magic.ini"), 
		OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST,
		szFilter);
	if (dlg.DoModal()!=IDOK)
		return;
	CString s = dlg.GetPathName();
	SaveSettings(s);
}

void CMagicApp::OnImport() 
{
	CFileDialog dlg(TRUE, _T(".ini"), _T("magic.ini"), 
		OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_FILEMUSTEXIST,
		szFilter);
	if (dlg.DoModal()!=IDOK)
		return;
	CString s = dlg.GetPathName();
	LoadSettings(s);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -