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

📄 greenbrowser.cpp

📁 用VC写的浏览器
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// GreenBrowser.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "GreenBrowser.h"

#include "MainFrm.h"
#include "ChildFrm.h"
#include "GreenBrowserView.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 "GreenBrowser_i.c"
#include "GreenBrowserNSHandle.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

/////////////////////////////////////////////////////////////////////////////
// CGreenBrowserApp

BEGIN_MESSAGE_MAP(CGreenBrowserApp, CWinApp)
	//{{AFX_MSG_MAP(CGreenBrowserApp)
	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()

/////////////////////////////////////////////////////////////////////////////
// CGreenBrowserApp construction

CGreenBrowserApp::CGreenBrowserApp()
{
}

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

/////////////////////////////////////////////////////////////////////////////
// CGreenBrowserApp initialization
BOOL CGreenBrowserApp::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 + "GreenBrowser.ini";
		m_strFormDataPath	= m_strUser + "FormData.ini";
		//
		m_strSkinPath		= m_strRoot + "skin\\";
		m_strGroupPath		= m_strRoot + "groups\\";
    }
    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\\GreenBrowser.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);
	//group path
	CString strAbsDir;
	strAbsDir = GetProfileString("Settings", "GroupPath", NULL);
	if(!strAbsDir.IsEmpty())
	{
		CHECK_TAIL(strAbsDir);
		DO_RELATIVE_URL(strAbsDir)
		m_strGroupPath = strAbsDir;
	}

	//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 hGreenBrowserSem = CreateMutex(NULL, TRUE, "GreenBrowserMutex");
							WaitForSingleObject(hGreenBrowserSem, 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(hGreenBrowserSem);
						}
					}
					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;

	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
	g_nMaxWins = GetProfileInt("Settings", "MaxWins", 100);
	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", TRUE);

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

⌨️ 快捷键说明

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