📄 myie.cpp
字号:
// MyIE.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "MyIE.h"
#include "MainFrm.h"
#include "ChildFrm.h"
//#include "MyIEDoc.h"
#include "MyIEView.h"
#include "afxpriv.h"
#include <..\src\occimpl.h>
#include "CustSite.h"
//#include <afxsock.h>
#include <Winsock.h>
#include <afxmt.h>
#include <wininet.h>
#include "rasspdm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define INTERNET_CONNECTION_OFFLINE 0x20 //18
char MyIEVer[]="MyIE 3.01";
/////////////////////////////////////////////////////////////////////////////
// CMyIEApp
BEGIN_MESSAGE_MAP(CMyIEApp, CWinApp)
//{{AFX_MSG_MAP(CMyIEApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMyIEApp construction
CMyIEApp::CMyIEApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
// m_hasEmptyDoc=true;
m_nAutoStart = 0;
m_bNeedCreateDir= FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CMyIEApp object
CMyIEApp theApp;
///////////////////////////////////////////////////////////////////
//global exception handle, not good at this time.
/*LONG __stdcall ExcepCallBack ( EXCEPTION_POINTERS * pExPtrs )
{
// AfxMessageBox ( "crash" ) ;
//let it crash
//return ( EXCEPTION_CONTINUE_SEARCH ) ;
//let it terminal
//return ( EXCEPTION_EXECUTE_HANDLER ) ;
if(pExPtrs->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION )
{
AfxMessageBox("Memory access violation. \nYou can try to increase the virtual memory and keep enough disk space for it.");
}
return EXCEPTION_CONTINUE_SEARCH;
}
*/
/////////////////////////////////////////////////////////////////////////////
// CMyIEApp initialization
BOOL CMyIEApp::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.
// SetUnhandledExceptionFilter(ExcepCallBack);
//only one instance is allowed except -m
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
HANDLE hSem = CreateSemaphore(NULL, 1, 1, m_pszAppName);
if (GetLastError() == ERROR_ALREADY_EXISTS)
m_bAutoStart = FALSE;
else
m_bAutoStart = TRUE;
HINSTANCE hInstance = AfxGetResourceHandle();
ASSERT(hInstance != NULL);
LPTSTR lpszModule;
try
{
lpszModule = new TCHAR[_MAX_PATH];
}
catch(CMemoryException* e)
{
// if(e!=NULL)e->Delete();
return FALSE;
}
if (GetModuleFileName(hInstance, lpszModule, _MAX_PATH))
{
m_strProfile = lpszModule;
int i = m_strProfile.ReverseFind('\\');
m_strProfile = m_strProfile.Left(i+1);
m_strBitmapPath = m_strProfile;
m_strGroupPath = m_strProfile;
m_strQuickSearchPath = m_strProfile;
m_strFormDataPath = m_strProfile;
m_strSaveTxtFile = m_strProfile;
m_strLinkListPath = m_strProfile;
m_strProfile += "myie.ini";
m_strBitmapPath += "myieskin\\";
m_strGroupPath += "groups\\";
m_strQuickSearchPath += "QuickSearch.ini";
m_strFormDataPath += "FormData.ini";
m_strSaveTxtFile += "SaveText.txt";
m_strLinkListPath += "urllist.htm";
}
delete [] lpszModule;
//2.5 victor
//First free the string allocated by MFC at CWinApp startup.
//The string is allocated before InitInstance is called.
free((void*)m_pszProfileName);
//Change the name of the .INI file.
//The CWinApp destructor will free the memory.
m_pszProfileName=_tcsdup(m_strProfile);
//delete[] (char*)m_pszProfileName;
//m_pszProfileName = m_strProfile;
HANDLE hfile = CreateFile(m_strProfile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hfile == INVALID_HANDLE_VALUE)
{
hfile = CreateFile(m_strProfile, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
if(hfile != INVALID_HANDLE_VALUE)
{
CString def; def.LoadString(IDS_DEFAULTPOS);
DWORD dwW;
WriteFile(hfile, def.GetBuffer(300), def.GetLength(), &dwW, NULL);
def.ReleaseBuffer();
CloseHandle(hfile);
}
}
else
CloseHandle(hfile);
bOneInstance = GetProfileInt("Settings", "OneInstance", FALSE);
//group path
m_strGroupPath = GetProfileString("Settings", "GroupPath", m_strGroupPath);
if (cmdInfo.m_nShellCommand!=CCommandLineInfo::FileNew )
{
if (!m_bAutoStart)
{
CloseHandle(hSem);
HWND hWndPrevious = ::GetWindow(::GetDesktopWindow(), GW_CHILD);
while (::IsWindow(hWndPrevious))
{
if (::GetProp(hWndPrevious, m_pszAppName))
{
if (cmdInfo.m_nShellCommand==CCommandLineInfo::FileOpen)
{
if (::GetLastActivePopup(hWndPrevious)==hWndPrevious)
{
LPSTR lpData;
//mutex
HANDLE hMyIESem = CreateMutex(NULL, TRUE, "MyIEMutex");
WaitForSingleObject(hMyIESem, INFINITE);
HANDLE hMapping = CreateFileMapping
((HANDLE)0xFFFFFFFF,NULL,
PAGE_READWRITE,0,2560,"MY2IESHARE");
if (hMapping==NULL)
{
AfxMessageBox("App:Fail to create share memory!");
}
else
{
lpData = (LPSTR) MapViewOfFile(hMapping,FILE_MAP_ALL_ACCESS,0,0,0);
if (lpData==NULL)
{
AfxMessageBox("App:MapViewOfFile Fail");
}
else {//MapViewOfFile??
sprintf(lpData,"%s",cmdInfo.m_strFileName);
::SendMessage(hWndPrevious,WM_USER_SHELL_OPEN,NULL,NULL);
}
CloseHandle(hMapping);
}
ReleaseMutex(hMyIESem);
}
}
if (::IsIconic(hWndPrevious))
::ShowWindow(hWndPrevious,SW_RESTORE);
//::SetForegroundWindow(hWndPrevious);
::SetForegroundWindow(::GetLastActivePopup(hWndPrevious));
return FALSE;
}
hWndPrevious = ::GetWindow(hWndPrevious, GW_HWNDNEXT);
}
return FALSE;
}
}
else if(bOneInstance && !m_bAutoStart)
{
//only one instance
HWND hWndPrevious = ::GetWindow(::GetDesktopWindow(), GW_CHILD);
while (::IsWindow(hWndPrevious))
{
if (::GetProp(hWndPrevious, m_pszAppName))
{
if (::IsIconic(hWndPrevious))
::ShowWindow(hWndPrevious,SW_RESTORE);
//::SetForegroundWindow(hWndPrevious);
::SetForegroundWindow(::GetLastActivePopup(hWndPrevious));
return FALSE;
}
hWndPrevious = ::GetWindow(hWndPrevious, GW_HWNDNEXT);
}
}
//2.2
//if (!AfxSocketInit())
// return FALSE;
// initialize Winsock library
bSockInied = FALSE;
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CoInitialize(NULL);
// 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.
//get a random ID
srand( (unsigned)time( NULL ) );
nTrayIconID = rand()/16;
BOOL bFirst = FirstRun();
CString bmpath;
bmpath = GetProfileString("Settings", "SkinPath", NULL);
if(!bmpath.IsEmpty())
m_strBitmapPath = bmpath;
m_bTopTab = GetProfileInt("Settings", "TabPos", 0);
//IShellUIHandle
CCustomOccManager *pMgr = new CCustomOccManager;
// Create an IDispatch class for extending the Dynamic HTML Object Model
m_pDispOM = new CImpIDispatch;
//Drop target
m_pDropTarget = new CImpIDropTarget;
// Set our control containment up but using our control container
// management class instead of MFC's default
AfxEnableControlContainer(pMgr);
// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = pMainFrame;
//global main frame point
::pMainFrame = pMainFrame;
// Enable drag/drop open
m_pMainWnd->DragAcceptFiles();
// Enable DDE Execute open
// EnableShellOpen();
// RegisterShellFileTypes(TRUE);
LoadConfg();
// Parse command line for standard shell commands, DDE, file open
// CCommandLineInfo cmdInfo;
// ParseCommandLine(cmdInfo);
int nOpenType;
CString strURL;
bGoHome = GetProfileInt("Settings", "goHome", 1);
/* if(bGoHome==0)
((CMainFrame*)m_pMainWnd)->GetMenu()->CheckMenuItem(ID_OPTIONS_MYIESTARTUP_OPENBLANKPAGE,MF_CHECKED);
if(bGoHome==1)
((CMainFrame*)m_pMainWnd)->GetMenu()->CheckMenuItem(ID_OPTIONS_MYIEGOHOME,MF_CHECKED);
if(bGoHome==2)
((CMainFrame*)m_pMainWnd)->GetMenu()->CheckMenuItem(ID_OPTIONS_MYIESTARTUP_RESUMELASTVISITEDPAGES,MF_CHECKED);
if(bGoHome==3)
((CMainFrame*)m_pMainWnd)->GetMenu()->CheckMenuItem(ID_OPTIONS_MYIESTARTUP_OPENFAVORITEPAGES,MF_CHECKED);
if(bGoHome==4)
((CMainFrame*)m_pMainWnd)->GetMenu()->CheckMenuItem(ID_OPTIONS_MYIESTARTUP_OPENMOSTFAVORITEPAGES,MF_CHECKED);
if(bGoHome==5)
((CMainFrame*)m_pMainWnd)->GetMenu()->CheckMenuItem(ID_OPTIONS_MYIESTARTUP_OPENSTARTUPGROUP,MF_CHECKED);
*/
//disable the old menu
::SetMenu(pMainFrame->m_hWnd, NULL);
//add user agent
HKEY hKey=NULL;
// TCHAR sz[MAX_PATH];
if(RegOpenKey(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\User Agent\\Post Platform"), &hKey) != ERROR_SUCCESS)
{
RegCreateKey(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\User Agent\\Post Platform"), &hKey);
}
if(hKey!=NULL)
{
RegSetValueEx(hKey, _T(MyIEVer), 0, REG_SZ, (LPBYTE)"IEAK", 4);
RegCloseKey(hKey);
}
pMainFrame->ShowWindow(m_nCmdShow);
//max wins
nMaxWins = GetProfileInt("Settings", "MaxWins", 100);
/* if(OpenFile(m_strProfile,&fst ,OF_EXIST)==HFILE_ERROR)
{
delete[] (char*)m_pszProfileName;
m_pszProfileName = m_strProfile;
}
delete[] (char*)m_pszRegistryKey;
m_pszRegistryKey = NULL;
*/
//load bytes
// ((CMainFrame*)m_pMainWnd)->m_lPreBytes = LoadBytes();
QueryPerformanceCounter(&((CMainFrame*)m_pMainWnd)->m_tPreBytes);
BOOL run = GetProfileInt("Settings", "Running", 0);
if(!m_bAutoStart)
run = FALSE;
//restore proxy server
if(((CMainFrame*)m_pMainWnd)->m_strCurProxy.Find("127.0.0.1")<0 && ((CMainFrame*)m_pMainWnd)->m_strCurProxy.Find("localhost")<0)
{
int ep = GetProfileInt("Settings", "EnableProxy", -1);
if(ep!=-1 && !((CMainFrame*)m_pMainWnd)->m_strCurProxy.IsEmpty())
{
//disable proxy first
INTERNET_PROXY_INFO ipi;
DWORD dwSize=sizeof(ipi);
ipi.dwAccessType = INTERNET_OPEN_TYPE_DIRECT ;
InternetSetOption(NULL, INTERNET_OPTION_PROXY, &ipi, dwSize);
}
if(ep==1)
{
if(!((CMainFrame*)m_pMainWnd)->m_strCurProxy.IsEmpty())
{
::SendMessage(m_pMainWnd->m_hWnd, WM_COMMAND, ID_OPTIONS_USE_PROXY, 0);
}
}
}
/* //3.0 auto detect offline
DWORD dwOffline;
if(InternetGetConnectedState(&dwOffline, 0))
{
if(dwOffline == INTERNET_CONNECTION_OFFLINE || dwOffline==0x20)
{
//set offline
HKEY hKey;
DWORD dwSize = sizeof(DWORD), sz;
if(RegOpenKey(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"), &hKey) != ERROR_SUCCESS)
{
TRACE0("Global settings not found\n");
}
else
{
sz = 1;
RegSetValueEx(hKey, _T("GlobalUserOffline"), NULL, REG_DWORD, (LPBYTE)(&sz), dwSize);
RegCloseKey(hKey);
//infor the system that setting is changed.
InternetSetOption(
NULL,
INTERNET_OPTION_SETTINGS_CHANGED,
NULL,
0
);
}
}
}*/
if (cmdInfo.m_nShellCommand==CCommandLineInfo::FileOpen)
{
nOpenType = 2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -