This repository has been archived on 2024-03-20. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
ContactBook/CB32.cpp
2024-03-20 09:28:18 -05:00

276 lines
6.8 KiB
C++

// CB32.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "CB32.h"
#include "ComboBar.h"
#include "MainFrm.h"
#include "CB32Doc.h"
#include "CB32View.h"
#include "HyperLink.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCB32App
BEGIN_MESSAGE_MAP(CCB32App, CWinApp)
//{{AFX_MSG_MAP(CCB32App)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_HELP_INDEX, OnHelpIndex)
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCB32App construction
CCB32App::CCB32App()
{
m_inStart = TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CCB32App object
CCB32App theApp;
/////////////////////////////////////////////////////////////////////////////
// CCB32App initialization
BOOL CCB32App::InitInstance()
{
// find the location of the exe from Help File Path
CString sHelp, sIni;
sHelp = m_pszHelpFilePath;
sIni = sHelp.Left(sHelp.ReverseFind('.'));
sIni += ".INI";
free((void*)m_pszProfileName);
m_pszProfileName = _tcsdup((LPCSTR)sIni);
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// Load standard INI file options (including MRU)
if (GetProfileInt(_T("Preferences"),_T("UseMRU"),1))
LoadStdProfileSettings(GetProfileInt(_T("Preferences"),
_T("NumMRU"),2));
else
LoadStdProfileSettings(0);
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CCB32Doc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CCB32View));
AddDocTemplate(pDocTemplate);
// Enable DDE Execute open
EnableShellOpen();
RegisterShellFileTypes(TRUE);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Are we starting minimized?
theApp.m_nCmdShow = !GetProfileInt(_T("Preferences"),_T("StartMinimized"),0);
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// set flag for status messages - AFTER ProcessShellCommand
m_inStart = FALSE;
// Enable drag/drop open
m_pMainWnd->DragAcceptFiles();
// Force immediate refresh
AfxGetMainWnd()->UpdateWindow();
// grab last document
if (m_lpCmdLine[0] == '\0')
{
// Open file name saved in private INI file.
if (GetProfileInt(_T("Preferences"),_T("UseLastBook"),0))
{
CString strDocPath = GetDocPathFromIniFile();
if (!strDocPath.IsEmpty())
{
SetStatusMsg(IDS_LOADING);
theApp.m_nCmdShow = !GetProfileInt(_T("Preferences"),_T("StartMinimized"),0);
OpenDocumentFile(strDocPath);
}
}
}
return TRUE;
}
int CCB32App::ExitInstance()
{
int nReturn = CWinApp::ExitInstance();
//free((void*)m_pszExeName);
//free((void*)m_pszAppName);
//free((void*)m_pszHelpFilePath);
//free((void*)m_pszProfileName);
return nReturn;
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
CHyperLink m_WebLink;
CHyperLink m_HyperLink;
//}}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)
DDX_Control(pDX, IDC_MYWEB, m_WebLink);
DDX_Control(pDX, IDC_MYEMAIL, m_HyperLink);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
void CCB32App::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_HyperLink.SetURL(_T("mailto:tengel@sonic.net"));
m_HyperLink.SetColours(m_HyperLink.GetLinkColour(), RGB(255,0,0));
m_HyperLink.SetUnderline(FALSE);
m_HyperLink.SetLinkCursor(AfxGetApp()->LoadCursor(IDC_HAND1));
m_WebLink.SetURL(_T("http://www.sonic.net/~tengel/ContactBook"));
m_WebLink.SetColours(m_HyperLink.GetLinkColour(), RGB(255,0,0));
m_WebLink.SetUnderline(FALSE);
m_WebLink.SetLinkCursor(AfxGetApp()->LoadCursor(IDC_HAND1));
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
/////////////////////////////////////////////////////////////////////////////
// CCB32App commands
/////////////////////////////////////////////////////////////////////////////
// INI file implementation
static TCHAR BASED_CODE szIniFileSection[] = _T("AddressBookInUse");
static TCHAR BASED_CODE szIniFileEntry[] = _T("File");
void CCB32App::UpdateIniFileWithDocPath(LPCTSTR lpszPathName)
{
WriteProfileString(szIniFileSection, szIniFileEntry,
lpszPathName);
}
CString CCB32App::GetDocPathFromIniFile()
{
return GetProfileString(szIniFileSection, szIniFileEntry, NULL);
}
void CCB32App::SetStatusMsg(UINT umsg)
{
CString strTemp;
if (!strTemp.LoadString(umsg))
return;
SetStatusMsg(strTemp);
}
void CCB32App::SetStatusMsg(CString msg)
{
if (!m_inStart)
{
CStatusBar& statusBar = ((CMainFrame *)m_pMainWnd)->GetStatusBar();
statusBar.SetPaneText(0, msg, TRUE);
AfxGetMainWnd()->UpdateWindow();
}
}
void CCB32App::OnHelpIndex()
{
CWinApp::OnHelpIndex();
}
BOOL CCB32App::OnIdle(LONG lCount)
{
// call the base class
BOOL bBaseIdle = CWinApp::OnIdle(lCount);
BOOL bMoreIdle = TRUE;
if (lCount == 0)
{
// more important idle time processing
}
else if (lCount == 100)
{
// less important idle time processing
}
else if (lCount == 1000)
{
// occasional tasks during idle
bMoreIdle = bBaseIdle;
}
// return FALSE when there is no more idle processing to do
return bMoreIdle;
}