home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.funduc.com
/
2014.08.ftp.funduc.com.tar
/
ftp.funduc.com
/
fshedcode-072212.zip
/
fshed.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2012-07-03
|
14KB
|
391 lines
/////////////////////////////////////////////////////////////////////////////
// License (GPLv2+):
// 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., 675 Mass Ave, Cambridge, MA 02139, USA.
/////////////////////////////////////////////////////////////////////////////
// fshed.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include <afxadv.h>
#include "fshed.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include "fshedDoc.h"
#include "fshedView.h"
#include "OptionsDlg.h"
#include "colorspage.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFshedApp
BEGIN_MESSAGE_MAP(CFshedApp, CWinApp)
//{{AFX_MSG_MAP(CFshedApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_VIEW_OPTIONS, OnViewOptions)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CFshedApp construction
#define FSH_INI_SECTION1 _T("Settings")
#define FSH_INI_ENTRY1 _T("Text Editor Name")
#define FSH_INI_ENTRY2 _T("Automatic BPL")
#define FSH_INI_ENTRY3 _T("Bytes per line")
#define FSH_INI_ENTRY4 _T("Offset Length")
#define FSH_INI_ENTRY5 _T("Character Set")
#define FSH_INI_ENTRY6 _T("Font Size")
#define FSH_INI_ENTRY7 _T("Open Read Only")
#define FSH_INI_ENTRY8 _T("Binary Mode")
#define FSH_INI_ENTRY9 _T("Show Unsigned")
#define FSH_INI_SECTION2 _T("Colors")
#define FSH_INI_ENTRY2_1 _T("Text")
#define FSH_INI_ENTRY2_2 _T("Selected Text")
#define FSH_INI_ENTRY2_3 _T("Background")
#define FSH_INI_ENTRY2_4 _T("Selected Background")
#define FSH_INI_ENTRY2_5 _T("Bookmark")
#define FSH_INI_ENTRY2_6 _T("Separator")
HWND WINAPI AfxHtmlHelp(HWND hWnd, LPCTSTR szHelpFilePath, UINT nCmd, DWORD_PTR dwData);
CFshedApp::CFshedApp()
{
m_bAutomaticBPL = BST_CHECKED;
m_iBytesPerLine = 16;
m_iOffsetLen = 6;
m_iCharacterSet = ANSI_FIXED_FONT;
m_iFontSize = 10;
m_bOpenReadOnly = FALSE;
m_iBinaryMode = LITTLEENDIAN_MODE;
m_bUnsignedView = TRUE;
m_clrBmk = RGB( 255, 0, 0 );
m_clrSelBk = RGB( 255, 255, 0 );
m_clrSelText = RGB( 0, 0, 0 );
m_clrText = RGB (0,0,0);
m_clrBk = RGB (255,255,255);
m_clrSep = RGB (192,192,192);
EnableHtmlHelp();
}
void CFshedApp::WinHelpInternal(DWORD_PTR dwData, UINT nCmd)
{
if (nCmd == HELP_CONTEXT)
AfxHtmlHelp(NULL, AfxGetApp()->m_pszHelpFilePath, HH_HELP_CONTEXT, dwData);
else
CWinApp::WinHelpInternal(dwData, nCmd);
}
CFshedApp::~CFshedApp()
{
WriteProfileString(FSH_INI_SECTION1, FSH_INI_ENTRY1, m_TexteditorName);
WriteProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY2, m_bAutomaticBPL);
WriteProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY3, m_iBytesPerLine);
WriteProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY4, m_iOffsetLen);
WriteProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY5, m_iCharacterSet);
WriteProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY6, m_iFontSize);
WriteProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY7, m_bOpenReadOnly);
WriteProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY8, m_iBinaryMode);
WriteProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY9, m_bUnsignedView);
WriteProfileInt(FSH_INI_SECTION2, FSH_INI_ENTRY2_1, m_clrText);
WriteProfileInt(FSH_INI_SECTION2, FSH_INI_ENTRY2_2, m_clrSelText);
WriteProfileInt(FSH_INI_SECTION2, FSH_INI_ENTRY2_3, m_clrBk);
WriteProfileInt(FSH_INI_SECTION2, FSH_INI_ENTRY2_4, m_clrSelBk);
WriteProfileInt(FSH_INI_SECTION2, FSH_INI_ENTRY2_5, m_clrBmk);
WriteProfileInt(FSH_INI_SECTION2, FSH_INI_ENTRY2_6, m_clrSep);
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CFshedApp object
CFshedApp theApp;
class CFshedCommandLineInfo : public CCommandLineInfo
{
public:
CFshedCommandLineInfo() { m_dwStartOffset = m_dwEndOffset = 0; }
DWORD m_dwStartOffset, m_dwEndOffset;
void ParseParam(const TCHAR* pszParam, BOOL bFlag, BOOL bLast)
{
CCommandLineInfo::ParseParam(pszParam, bFlag, bLast);
if (bFlag)
{
LPTSTR pEnd;
switch (pszParam[0])
{
case 's':
case 'S':
m_dwStartOffset = _tcstoul(pszParam + 1, &pEnd, 0);
break;
case 'e':
case 'E':
m_dwEndOffset = _tcstoul(pszParam + 1, &pEnd, 0);
break;
case 'l':
case 'L':
m_dwEndOffset = m_dwStartOffset + _tcstoul(pszParam + 1, &pEnd, 0) - 1;
if (m_dwEndOffset < m_dwStartOffset)
m_dwEndOffset = m_dwStartOffset;
break;
}
}
}
};
/////////////////////////////////////////////////////////////////////////////
// CFshedApp initialization
BOOL CFshedApp::InitInstance()
{
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
//SetRegistryKey(IDS_COMP_NAME);
free((void*)m_pszProfileName);
CString strPath = m_pszHelpFilePath;
strPath = strPath.Left(strPath.ReverseFind('.') + 1) + _T("ini");
m_pszProfileName = _tcsdup(strPath);
strPath = (LPCTSTR)GetProfileString(FSH_INI_SECTION1, FSH_INI_ENTRY1);
m_TexteditorName = (LPTSTR)(LPCTSTR)strPath;
m_bAutomaticBPL = GetProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY2, m_bAutomaticBPL);
m_iBytesPerLine = GetProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY3, m_iBytesPerLine);
m_iOffsetLen = GetProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY4, m_iOffsetLen);
m_iCharacterSet = GetProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY5, m_iCharacterSet);
m_iFontSize = GetProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY6, m_iFontSize);
m_bOpenReadOnly = GetProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY7, m_bOpenReadOnly);
m_iBinaryMode = GetProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY8, m_iBinaryMode);
m_bUnsignedView = GetProfileInt(FSH_INI_SECTION1, FSH_INI_ENTRY9, m_bUnsignedView);
m_clrText = GetProfileInt(FSH_INI_SECTION2, FSH_INI_ENTRY2_1, m_clrText);
m_clrSelText = GetProfileInt(FSH_INI_SECTION2, FSH_INI_ENTRY2_2, m_clrSelText);
m_clrBk = GetProfileInt(FSH_INI_SECTION2, FSH_INI_ENTRY2_3, m_clrBk);
m_clrSelBk = GetProfileInt(FSH_INI_SECTION2, FSH_INI_ENTRY2_4, m_clrSelBk);
m_clrBmk = GetProfileInt(FSH_INI_SECTION2, FSH_INI_ENTRY2_5, m_clrBmk);
m_clrSep = GetProfileInt(FSH_INI_SECTION2, FSH_INI_ENTRY2_6, m_clrSep);
//LoadStdProfileSettings(5); // Load standard INI file options (including MRU)
// create file MRU since nMaxMRU not zero
m_pRecentFileList = new CRecentFileList(0, _T("Recent File List"), _T("File%d"), 5);
m_pRecentFileList->ReadList();
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_FSHEDTYPE,
RUNTIME_CLASS(CFshedDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CFshedView));
AddDocTemplate(pDocTemplate);
// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = pMainFrame;
// Parse command line for standard shell commands, DDE, file open
CFshedCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew)
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
if (CCommandLineInfo::FileOpen)
{
POSITION pos = pDocTemplate->GetFirstDocPosition();
if (pos)
{
CFshedDoc *pDoc = (CFshedDoc *)pDocTemplate->GetNextDoc(pos);
if (pDoc && (cmdInfo.m_dwStartOffset <= cmdInfo.m_dwEndOffset))
{
pos = pDoc->GetFirstViewPosition();
if (pos)
{
CFshedView *pView = (CFshedView *)pDoc->GetNextView(pos);
if (pView)
{
pView->SetSel(cmdInfo.m_dwStartOffset, cmdInfo.m_dwEndOffset);
}
}
}
}
}
// The main window has been initialized, so show and update it.
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
virtual BOOL OnInitDialog();
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
afx_msg void OnVisit();
//}}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)
//}}AFX_DATA_MAP
}
BOOL CAboutDlg::OnInitDialog()
{
BOOL bRtn = CDialog::OnInitDialog();
CWnd* pwndChild = GetDlgItem(IDC_STATIC_COPYRIGHT);
if (pwndChild)
{
CString str;
pwndChild->GetWindowText(str);
CTime tmCurrent = CTime::GetCurrentTime();
CString strCurYear;
strCurYear.Format(_T("%d"), tmCurrent.GetYear());
if (str.Replace(_T("2010"), strCurYear))
pwndChild->SetWindowText(str);
}
return bRtn;
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
ON_BN_CLICKED(IDC_VISIT, OnVisit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
void CFshedApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CFshedApp message handlers
void CFshedApp::OnViewOptions()
{
CPropertySheet optSheet(IDS_TTL_OPTIONS, AfxGetMainWnd());
CDispPage dispPage;
CGenPage genPage;
CColorsPage clrPage;
optSheet.AddPage(&genPage);
optSheet.AddPage(&dispPage);
optSheet.AddPage(&clrPage);
genPage.m_strTextEditor = m_TexteditorName;
genPage.m_nNumBytes = m_iBytesPerLine;
genPage.m_bAdjustBytes = m_bAutomaticBPL;
genPage.m_nOffsetLen = m_iOffsetLen;
genPage.m_bSetRead = m_bOpenReadOnly;
dispPage.m_nSigned = !m_bUnsignedView;
dispPage.m_nAnsi = (m_iCharacterSet == OEM_FIXED_FONT) ? 1 : 0;
dispPage.m_nFontSize = m_iFontSize;
dispPage.m_nIntel = (m_iBinaryMode == BIGENDIAN_MODE) ? 1 : 0;
clrPage.m_clrbtnText.currentcolor = m_clrText;
clrPage.m_clrbtnSep.currentcolor = m_clrSep;
clrPage.m_clrbtnSelBack.currentcolor = m_clrSelBk;
clrPage.m_clrbtnSel.currentcolor = m_clrSelText;
clrPage.m_clrbtnBookmark.currentcolor = m_clrBmk;
clrPage.m_clrbtnBack.currentcolor = m_clrBk;
if (optSheet.DoModal() == IDOK)
{
m_TexteditorName = (LPTSTR)(LPCTSTR)genPage.m_strTextEditor;
m_iBytesPerLine = genPage.m_nNumBytes;
m_bAutomaticBPL = genPage.m_bAdjustBytes;
m_iOffsetLen = genPage.m_nOffsetLen;
m_bUnsignedView = !dispPage.m_nSigned;
m_bOpenReadOnly = genPage.m_bSetRead;
m_iCharacterSet = (dispPage.m_nAnsi ? OEM_FIXED_FONT : ANSI_FIXED_FONT);
m_iFontSize = dispPage.m_nFontSize;
m_iBinaryMode = (dispPage.m_nIntel ? BIGENDIAN_MODE : LITTLEENDIAN_MODE);
m_clrText = clrPage.m_clrbtnText.currentcolor;
m_clrSep = clrPage.m_clrbtnSep.currentcolor;
m_clrSelBk = clrPage.m_clrbtnSelBack.currentcolor;
m_clrSelText = clrPage.m_clrbtnSel.currentcolor;
m_clrBmk = clrPage.m_clrbtnBookmark.currentcolor;
m_clrBk = clrPage.m_clrbtnBack.currentcolor;
POSITION pos = GetFirstDocTemplatePosition();
CMultiDocTemplate *pDocTemplate = (CMultiDocTemplate *)GetNextDocTemplate(pos);
if (pDocTemplate)
{
pos = pDocTemplate->GetFirstDocPosition();
while (pos)
{
CFshedDoc *pDoc = (CFshedDoc *)pDocTemplate->GetNextDoc(pos);
pDoc->UpdateAllViews(NULL);
}
}
}
}
void CAboutDlg::OnVisit()
{
ShellExecute(m_hWnd, _T("open"), _T("http://www.searchandreplace.com/fshexedit.htm"), NULL, NULL, SW_SHOWNORMAL );
}