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

📄 myie.cpp

📁 1.MyIE开源工程协议 MyIE开源工程遵循GNU通用公共许可证GPL(GNU General Public License)开发,任何人都可以永久免费安装使用,在你下载和使用MyIE源代码前,请
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// MyIE.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "MyIE.h"

#include "MainFrm.h"
#include "ChildFrm.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"
#include <initguid.h>
#include "MyIE_i.c"
#include "MyIENSHandle.h"
//add new
#include "SelectURL.h"
#include "SelectLang.h"
#include "InputDlg.h"

//##############################################################
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// 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)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyIEApp construction

CMyIEApp::CMyIEApp()
{
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CMyIEApp object
CMyIEApp theApp;

/////////////////////////////////////////////////////////////////////////////
// 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);

	if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated)
	{
		return TRUE;
	}

	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(...)
	{
		return FALSE;
	}

	if (GetModuleFileName(hInstance, lpszModule, _MAX_PATH))
    {
		m_strProfile = lpszModule;
		int i = m_strProfile.ReverseFind('\\');
		m_strProfile= m_strProfile.Left(i+1);
		m_strRoot	= m_strProfile;
		m_strUser	= m_strProfile + "User\\";
		//
		m_strProfile		= m_strUser + "MyIE.ini";
		m_strFormDataPath	= m_strUser + "FormData.ini";
		//
		m_strSkinPath		= m_strRoot + "skin\\";
    }
    delete [] lpszModule;
	
	//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;

	//must first create user path
	_CreateFullDir(m_strUser);
	
	HANDLE hfile ;
	CString filename;
	//
	filename = m_strProfile;
	hfile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if(hfile == INVALID_HANDLE_VALUE)
		CopyFile(m_strRoot+"Resource\\MyIE.ini.default",filename, FALSE);
	else
		CloseHandle(hfile);
	//
	filename = m_strUser+"SearchEngine.ini";
	hfile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if(hfile == INVALID_HANDLE_VALUE)
		CopyFile(m_strRoot+"Resource\\SearchEngine.ini.default",filename, FALSE);
	else
		CloseHandle(hfile);
	//
	filename = m_strUser+"Filter.ini";
	hfile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if(hfile == INVALID_HANDLE_VALUE)
		CopyFile(m_strRoot+"Resource\\Filter.ini.default",filename, FALSE);
	else
		CloseHandle(hfile);
	//
	g_bForbidMult = GetProfileInt("Settings", "ForbidMult", FALSE);

	//2 means first run,not select language
	m_bUseLngFile = GetProfileInt("Settings", "UseLngFile", 2);
	m_strLngFile = GetProfileString("Settings", "LngFile", "");
	if (m_bUseLngFile==2)
	{
		m_bUseLngFile = 0;
		WriteProfileInt("Settings", "UseLngFile", m_bUseLngFile );
		//
		CSelectLang dlg;
		dlg.DoModal();
	}
	else
	{
		m_strLngFile = theApp.m_strRoot+"Language\\" + m_strLngFile;
		if (m_strLngFile.GetLength()<1)
			m_bUseLngFile = FALSE;
		else
			_InitLanguageFile(m_strLngFile);
	}
	//
	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)
							{
								MSGBOX("App:Fail to create share memory!");
							}
							else
							{
								lpData = (LPSTR) MapViewOfFile(hMapping,FILE_MAP_ALL_ACCESS,0,0,0);
								if (lpData==NULL)
								{
									MSGBOX("App:MapViewOfFile Fail");
								}
								else
								{
									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(::GetLastActivePopup(hWndPrevious));
					return FALSE;
				}
				hWndPrevious = ::GetWindow(hWndPrevious, GW_HWNDNEXT);
			}
			return FALSE;
		}
	}
	else if(g_bForbidMult && !m_bAutoStart)
	{
		//only one instance
		HWND hWndPrevious = ::GetWindow(::GetDesktopWindow(), GW_CHILD);
		while (::IsWindow(hWndPrevious))
		{
			if (::GetProp(hWndPrevious, m_pszAppName))
			{
				if (::IsWindowVisible(hWndPrevious)==FALSE)
					::SendMessage(hWndPrevious,WM_HOTKEY,NULL,NULL);
				else
				{
					if (::IsIconic(hWndPrevious))
						::ShowWindow(hWndPrevious,SW_RESTORE);
					::SetForegroundWindow(::GetLastActivePopup(hWndPrevious));
				}
				return FALSE;
			}
			hWndPrevious = ::GetWindow(hWndPrevious, GW_HWNDNEXT);
		}	
	}
	// initialize Winsock library
	WSADATA wsaData;
	WORD wVersionRequested = MAKEWORD(1, 1);
	int nResult = WSAStartup(wVersionRequested, &wsaData);
	if (nResult == 0)
	{
		if (LOBYTE(wsaData.wVersion) != 1 || HIBYTE(wsaData.wVersion) != 1)
		{
			WSACleanup();
		}
	}

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

#if _WIN32_WINNT >= 0x0400
	CoInitializeEx(NULL, COINIT_MULTITHREADED);
#else
	CoInitialize(NULL);
#endif

	if (!InitATL())
		return FALSE;

	// 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 ) );
	g_nTrayIconID = rand()/16;

	CString strAbsDir;
	strAbsDir = GetProfileString("Settings", "SkinPath", NULL);
	if(!strAbsDir.IsEmpty())
	{
		DO_RELATIVE_URL(strAbsDir)
		m_strSkinPath = strAbsDir;
	}
	
	//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* mf = new CMainFrame;
	if (!mf->LoadFrame(IDR_MAINFRAME))
		return FALSE;
	m_pMainWnd = mf;
	//global main frame point
	::pmf = mf;

	// Enable drag/drop open
	m_pMainWnd->DragAcceptFiles();

	//############################################################################
	LoadConfg();

	int nOpenType;
	CString strURL;

	BOOL bGoHome = GetProfileInt("Settings", "StartupMode", 2);
	//disable the old menu
	::SetMenu(pmf->m_hWnd, NULL);
	pmf->ShowWindow(m_nCmdShow);
	//max wins
	BOOL run = 	GetProfileInt("Settings", "Running", 0);
	if(!m_bAutoStart)
		run = FALSE;
	g_bMax = GetProfileInt("Settings", "PageMax", 1);
	g_bMax = g_bMax>0 ? 1 : 0;
	//
	pmf->m_bKeepOnePage = GetProfileInt("Settings", "KeepOnePage", FALSE);
	if (pmf->m_bKeepOnePage)
	{
		if (bGoHome!=0 && bGoHome!=6)
			pmf->PostMessage(WM_COMMAND, ID_FILE_NEW_BLANK, 0);
	}
	//
	pmf->m_bAutoRunExternal = GetProfileInt("Settings", "AutoRunExternal", FALSE);
	pmf->m_bConfirmUnsafePage = GetProfileInt("Settings", "ConfirmUnsafePage", TRUE);
	pmf->m_dwDefaultProperty = GetProfileInt("Settings", "DefaultProperty", pmf->GetDefaultProperty());
	pmf->m_bUseTargetFrameName = GetProfileInt("Settings", "UseTargetFrameName", FALSE);

	//#####################################################################
	//!!anything before navigate add prev
	if (cmdInfo.m_nShellCommand==CCommandLineInfo::FileOpen)
	{
		nOpenType = 2;
		strURL = cmdInfo.m_strFileName;
		TCHAR           buf[2048];
		if(IS_FAVURL(strURL))
		{
			// 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, 2048,
									  strURL);
			strURL =  buf;
		}
		pmf->NewChildWindow(1, nOpenType, strURL);
	}
	else
	{
		//enable go home
		nOpenType = bGoHome;
		if(bGoHome == 2|| run)// must be first for run
		{
			char tmp[INTERNET_MAX_PATH_LENGTH];
			if (run)
			{
				remove(m_strUser+"LastVisit.ini");
				rename(m_strUser+"Visiting.ini", m_strUser+"LastVisit.ini");
			}
			CString filename = m_strUser+"LastVisit.ini";
			DWORD r = ::GetPrivateProfileString("LastVisit", "url0", NULL, tmp, INTERNET_MAX_PATH_LENGTH, filename);
			if(r)
			{
				CSelectURL dlg;
				dlg.DoModal();
			}
		}
		else if(bGoHome == 3)
		{
			CChildFrame *tcf;
			//load last visit
			char state[10]="state",url[8]="url"; // x+5
			CString filename = m_strUser+"LastVisit.ini";
			int i=0,nState;
			char tmp[INTERNET_MAX_PATH_LENGTH];
			BOOL r = TRUE;
			//
			BOOL bTemp = pmf->m_nNewSequence;
			pmf->m_nNewSequence = 0;
			while(r)
			{
				itoa(i, state+5, 10);
				itoa(i, url+3, 10);
				r = ::GetPrivateProfileString("LastVisit", url, NULL, tmp, INTERNET_MAX_PATH_LENGTH, filename);
				if (r)
				{
					tcf = pmf->NewChildWindow(1, 2, tmp);
					if (tcf)
					{
						nState = ::GetPrivateProfileInt("LastVisit", state, 0, filename);
						if (nState ==4)
							tcf->m_bLock = TRUE;
					}
				}
				i++;
			}
			pmf->m_nNewSequence  = bTemp;
		}
		else if(bGoHome == 0)
			pmf->PostMessage(WM_COMMAND, ID_FILE_NEW_BLANK, 0);
		else if(bGoHome == 1)//3.2
			pmf->PostMessage(WM_COMMAND, ID_FILE_NEW_S, 0);
		else if(bGoHome == 4)
		{
			pmf->OpenAllFavs(pmf->m_strStartFavFolder);
		}
		else if(bGoHome == 5)
			;//do nothing		
	}
	
	pmf->m_bAutoHideMode = GetProfileInt("Settings", "AutoHide", 0);
	if(pmf->m_bAutoHideMode)
	{
		pmf->AutoHideModeOn();
	}
	//full screen
	pmf->m_bFullScreenMode = GetProfileInt("Settings", "FullScreen", 0);
	if(pmf->m_bFullScreenMode)
	{
		pmf->FullScreenModeOn();
	}

	//############################################################################
	pmf->UpdateWindow();
	//delay load
	pmf->PostMessage(WM_DELAYLOAD_CONFIG);
	WriteProfileInt("Settings", "Running", 1);

	return TRUE;
}

// App command to run the dialog
void CMyIEApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CMyIEApp message handlers

//#pragma optimize( "", on )

int CMyIEApp::ExitInstance() 
{
	// TODO: Add your specialized code here and/or call the base class
	try{
	WSACleanup();
	if(m_pDispOM)
		delete m_pDispOM;
	if(m_pDropTarget)
		delete m_pDropTarget;
	}catch(...){}

	if (m_bATLInited)
	{
		_Module.RevokeClassObjects();
		_Module.Term();
	}
	CoUninitialize();
	return CWinApp::ExitInstance();
}

void CMyIEApp::LoadConfg()
{
	char *tmp = NULL;

	//enable popup
	g_bKillPop = GetProfileInt("Settings", "KillPop", 1);
	g_bKillAutoWin = GetProfileInt("Settings", "KillAutoWin", 1);
	g_bKillDupWin = GetProfileInt("Settings", "KillDupWin", 1);
	g_bKillListWin = GetProfileInt("Settings", "KillListWin", 1);
	//
	pmf->m_bNotConfirmPopupFilter = GetProfileInt("Settings", "NotConfirmPopupFilter", 1);
	pmf->m_bPlayPopupFilterSound = GetProfileInt("Settings", "PlayPopupFilterSound", 1);
	pmf->m_nPopDelay = GetProfileInt("Settings", "PopupBound", 120);
	pmf->m_nPopDelay /= 100;
	pmf->m_bFilterRefresh = GetProfileInt("Settings", "FilterRefresh", FALSE);
	pmf->m_bNotFilterClickDialog = GetProfileInt("Settings", "NotFilterClickDialog", TRUE);

⌨️ 快捷键说明

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