📄 ie6mdi.cpp
字号:
// IE6mdi.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "IE6mdi.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include "IE6mdiDoc.h"
#include "IE6mdiView.h"
#include "DlgFavorites.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define INTERNET_MAX_PATH_LENGTH 2048
#define KEYSIZE 2048
/////////////////////////////////////////////////////////////////////////////
// CIE6mdiApp
// ON_COMMAND_RANGE(0xe00, 0xfff, OnFavorite)
BEGIN_MESSAGE_MAP(CIE6mdiApp, CWinApp)
//{{AFX_MSG_MAP(CIE6mdiApp)
ON_COMMAND(ID_FILE_NEW2, OnFileNew2)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND_RANGE(0xe05, 0xfff, OnFavorite)
ON_COMMAND(0xe01, OnAddFavorite)
ON_COMMAND(0xe02, OnRemoveFavorite)
ON_COMMAND(0xe03, OnRefreshFavorite)
ON_COMMAND(ID_WINDOW_REMINDCONFIGURATION, OnWindowRemindwindow)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CIE6mdiApp construction
CIE6mdiApp::CIE6mdiApp()
{
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CIE6mdiApp object
CIE6mdiApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CIE6mdiApp initialization
BOOL CIE6mdiApp::InitInstance()
{
/////////////////////////////////////////////////////////////
// Shareware management
/////////////////////////////////////////////////////////////
#ifdef __SHAREWARE__
m_Shareware.Create("software\\microsoft\\ie",30,BY_DAY,BUILD_NUMBER,HKEY_CURRENT_USER);
if (m_Shareware.IsFinished()) {
AfxMessageBox(CString(LPCTSTR(IDS_SHAREWARE_END)));
return FALSE;
}
#endif
/////////////////////////////////////////////////////////////
// end Shareware management
/////////////////////////////////////////////////////////////
AfxEnableControlContainer();
// 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.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// 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(_T("IEMDI"));
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_IE6MDITYPE,
RUNTIME_CLASS(CIE6mdiDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CIE6mdiView));
AddDocTemplate(pDocTemplate);
// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = pMainFrame;
// Enable drag/drop open
m_pMainWnd->DragAcceptFiles();
// Enable DDE Execute open
EnableShellOpen();
RegisterShellFileTypes(TRUE);
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
/////////////////////////////////////
// fuck off, I want to remove the /dde
// from the entry key !!!
// HKEY_CLASSES_ROOT\IE6mdi.Document\shell\open\command
// default keyname !!!
CRegKey reg;
long hRes;
LPCTSTR Base;
LPTSTR szValue;
DWORD pdwCount = KEYSIZE+1 ;
char Buffer[KEYSIZE];
Base = "IE6mdi.Document\\shell\\open\\command";
hRes = reg.Create(
HKEY_CLASSES_ROOT,
Base,
REG_NONE,
REG_OPTION_NON_VOLATILE);
Buffer[0]='\0';
pdwCount = KEYSIZE+1;
szValue = Buffer;
hRes = reg.QueryValue(szValue,NULL,&pdwCount);
CString NewKey(szValue);
NewKey = NewKey.Left(NewKey.GetLength() - 5);// " /dde" removed !
strcpy(szValue,(LPCTSTR)NewKey);
reg.Close();
Base = "IE6mdi.Document\\shell\\open";
hRes = reg.Create(
HKEY_CLASSES_ROOT,
Base,
REG_NONE,
REG_OPTION_NON_VOLATILE);
reg.SetKeyValue("command",szValue,NULL);
reg.Close();
// now, just have to deal with that in OnOpenDocument
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
//////////////////////////////////////
// now we show the window
//////////////////////////////////////
// The main window has been initialized, so show and update it.
CWinApp* pApp = AfxGetApp();
m_iRemindWindow = pApp->GetProfileInt("Settings","RemindWindow",0);
if (m_iRemindWindow == 0) {
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
}
//////////////////////////////////////////////////////
// //
// MY INITIALISATIONS //
// //
//////////////////////////////////////////////////////
if (m_iRemindWindow == 1) {
///////////////////////////////////////////////
// Get the position and size of the main window
///////////////////////////////////////////////
int Width,Height,Top,Left,IsZoomed;
Width = pApp->GetProfileInt("Settings","Window Width",-1);
Height = pApp->GetProfileInt("Settings","Window Height",-1);
Top = pApp->GetProfileInt("Settings","Window Top",-1);
Left = pApp->GetProfileInt("Settings","Window Left",-1);
IsZoomed = pApp->GetProfileInt("Settings","Window IsZoomed",-1);
switch (IsZoomed) {
case 1:
// we just have to zoom the window
AfxGetApp()->m_pMainWnd->ShowWindow(SW_MAXIMIZE);
break;
case -1:
// no value, check the rest....
case 0: {
// set the size and position
CRect rect;
AfxGetApp()->m_pMainWnd->GetWindowRect(&rect);
rect.NormalizeRect();
// initialise the lack of values with currents
if (Width=-1)
Width = rect.Width();
if (Height==-1)
Height = rect.Height();
if (Left==-1)
Left = rect.left;
if (Top==-1)
Top = rect.top;
// now we will set the size of the window :O)
AfxGetApp()->m_pMainWnd->SetWindowPos(&AfxGetApp()->m_pMainWnd->wndTop,
Left,Top,Width,Height,
SWP_SHOWWINDOW);
break;
}
}
} // end remind window
//////////////////////////////////////
// Update the different menus
//////////////////////////////////////
// Remove "New window" from the menu !
CMenu* pTopMenu = AfxGetMainWnd()->GetMenu();
CMenu* pWindowMenu = pTopMenu->GetSubMenu(4);
pWindowMenu->RemoveMenu(ID_WINDOW_NEW,MF_BYCOMMAND);
// and open, save, save as...
pWindowMenu = pTopMenu->GetSubMenu(0);
pWindowMenu->RemoveMenu(ID_FILE_OPEN,MF_BYCOMMAND);
pWindowMenu->RemoveMenu(ID_FILE_SAVE,MF_BYCOMMAND);
pWindowMenu->RemoveMenu(ID_FILE_SAVE_AS,MF_BYCOMMAND);
///////////////////////////////////////////
// Update Remind Window
///////////////////////////////////////////
pWindowMenu = pTopMenu->GetSubMenu(4);
if (m_iRemindWindow == 1)
pWindowMenu->CheckMenuItem(ID_WINDOW_REMINDCONFIGURATION,MF_BYCOMMAND | MF_CHECKED);
//////////////////////////////////////
// Favorites
/////////////////////////////////////
CreateFavorites();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
CAnimateCtrl m_animate;
CString m_period;
//}}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)
m_period = _T("");
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
DDX_Control(pDX, IDC_ANIMATE, m_animate);
DDX_Text(pDX, IDC_PERIOD, m_period);
//}}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 CIE6mdiApp::OnAppAbout()
{
CAboutDlg aboutDlg;
CTime end_time = CTime::GetCurrentTime();
aboutDlg.m_period = end_time.Format( "Today is: %A, %B %d, %Y" );
#ifdef __SHAREWARE__
end_time = ((CIE6mdiApp*)AfxGetApp())->m_Shareware.GetLimitDay();
DWORD ver = ((CIE6mdiApp*)AfxGetApp())->m_Shareware.GetVersion();
CString s;
s.Format("%d",ver);
aboutDlg.m_period = end_time.Format( "End of your trial period: %A, %B %d, %Y. Build ");
aboutDlg.m_period += s;
#endif
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CIE6mdiApp message handlers
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_animate.Open(IDR_MFCAVI);
m_animate.Play(0,-1,-1);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
/*
*******************************************************************************/
// FUNCTION : int CIE6mdiApp::BuildFavoritesMenu(LPCTSTR,int,CMenu*)
//
// PURPOSE : create the favorites menu
//
// PARAMETERS :
// pszPath - favorites directory location (IE)
// nStartPos - start point for the insertion
// pMenu - menu to insert
//
// RETURN VALUE : int
//
//
// COMMENTS : recursive function !!!
//
//
/*******************************************************************************
*/
int CIE6mdiApp::BuildFavoritesMenu(LPCTSTR pszPath, int nStartPos, CMenu* pMenu)
{
CString strPath(pszPath);
CString strPath2;
CString str;
WIN32_FIND_DATA wfd;
HANDLE h;
int nPos;
int nEndPos;
int nNewEndPos;
int nLastDir;
TCHAR buf[INTERNET_MAX_PATH_LENGTH];
CStringArray astrFavorites;
CStringArray astrDirs;
CMenu* pSubMenu;
// make sure there's a trailing backslash
if(strPath[strPath.GetLength() - 1] != _T('\\'))
strPath += _T('\\');
strPath2 = strPath;
strPath += "*.*";
// now scan the directory, first for .URL files and then for subdirectories
// that may also contain .URL files
h = FindFirstFile(strPath, &wfd);
if(h != INVALID_HANDLE_VALUE)
{
nEndPos = nStartPos;
do
{
if((wfd.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM))==0)
{
str = wfd.cFileName;
if(str.Right(4) == _T(".url"))
{
// an .URL file is formatted just like an .INI file, so we can
// use GetPrivateProfileString() to get the information we want
::GetPrivateProfileString(_T("InternetShortcut"), _T("URL"),
_T(""), buf, INTERNET_MAX_PATH_LENGTH,
strPath2 + str);
str = str.Left(str.GetLength() - 4);
// scan through the array and perform an insertion sort
// to make sure the menu ends up in alphabetic order
for(nPos = nStartPos ; nPos < nEndPos ; ++nPos)
{
if(str.CompareNoCase(astrFavorites[nPos]) < 0)
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -