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

📄 myie.cpp

📁 myie的源程序是用VC++写自已可以扩搌使用
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// 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 <afxmt.h>

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


char MyIEVer[]="MyIE 2.0 Beta 2";


/////////////////////////////////////////////////////////////////////////////
// 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_posAutoStart = NULL;
}

/////////////////////////////////////////////////////////////////////////////
// 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.

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

	if (cmdInfo.m_nShellCommand!=CCommandLineInfo::FileNew)
		{
			
			if (GetLastError() == ERROR_ALREADY_EXISTS)
			{
				CloseHandle(hSem);

				Sleep(600); //wait for a while

				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;
			}
		}

	if (!AfxSocketInit())
		return 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;

    HINSTANCE hInstance = AfxGetResourceHandle();
    ASSERT(hInstance != NULL);
    LPTSTR lpszModule = new TCHAR[_MAX_PATH];
    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_strProfile += "myie.ini";
		m_strBitmapPath += "myieskin\\";
    }
    delete [] lpszModule;

/*	OFSTRUCT fst;
	if(OpenFile(m_strProfile,&fst ,OF_EXIST)==HFILE_ERROR)
		SetRegistryKey(_T("Internet"));
	else
*/	{
		delete[]  (char*)m_pszProfileName;
		m_pszProfileName = m_strProfile;
	}

//	LoadStdProfileSettings();  // Load standard INI file options (including MRU)

	BOOL bFirst = FirstRun();

	CString bmpath;
	bmpath = GetProfileString("Settings", "SkinPath", NULL);
	if(!bmpath.IsEmpty())
		m_strBitmapPath = bmpath;
	
	m_bTopTab = GetProfileInt("Settings", "TabPos", 0);

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

/*	CMultiDocTemplate* pDocTemplate;
	pDocTemplate = new CMultiDocTemplate(
		IDR_MyIEYPE,
		RUNTIME_CLASS(CMyIEDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CMyIEView));
	AddDocTemplate(pDocTemplate);
*/
	//IShellUIHandle
	CCustomOccManager *pMgr = new CCustomOccManager;

	// Create an IDispatch class for extending the Dynamic HTML Object Model 
	m_pDispOM = new CImpIDispatch;

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

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


	//max wins
	nMaxWins = GetProfileInt("Settings", "MaxWins", 100);


	pMainFrame->ShowWindow(m_nCmdShow);

	//full screen
	BOOL bFullScreenMode = GetProfileInt("Settings", "FullScreen", 0);
	if(bFullScreenMode)
	{
		((CMainFrame*)m_pMainWnd)->FullScreenModeOn();
	}

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


	if (cmdInfo.m_nShellCommand==CCommandLineInfo::FileOpen)
	{
		nOpenType = 2;
		strURL = cmdInfo.m_strFileName;
		TCHAR           buf[2048];
		strURL.MakeLower();
		if(strURL.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, 2048,
									  strURL);

			strURL =  buf;
		}
		pMainFrame->NewChildWindow(1, nOpenType, strURL);
	}
	else
	{
		//enable go home
		nOpenType = bGoHome;
		if(bGoHome == 2)
		{
			//load last visit
			UINT len;
			char *tmp = NULL;
			BOOL r = GetProfileBinary("Settings","lastvisit", (LPBYTE*)(&tmp), &len);
			if(r)
			{
				//load pop list
				char *token;
				char seps[] = "\n";
				token = strtok( tmp, seps);
				while( token != NULL )
				{
					  /* While there are tokens in "string" */
					  ((CMainFrame*)m_pMainWnd)->NewChildWindow(1, nOpenType, token);
					  /* Get next token: */
					  token = strtok( NULL, seps );
				}
				delete[] tmp;

			}
		}
		else if(bGoHome == 3)
		{
			pMainFrame->OpenAllFavs(((CMainFrame*)m_pMainWnd)->m_strStartFavFolder);
		}
		else if(bGoHome == 4)
		{
			pMainFrame->OpenAllFavs(((CMainFrame*)m_pMainWnd)->m_strStartFavFolder, TRUE);
		}
		else
			pMainFrame->NewChildWindow(1, nOpenType, strURL);
	}
	
	
	//go my homepage when first run 
	if(bFirst)
	{
		CString strURL = "http://changyou.126.com/";
		((CMainFrame*)m_pMainWnd)->NewChildWindow(1,2,strURL);
	}


	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

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
		// No message handlers
	//}}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
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

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

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


/*CDocument* CMyIEApp::OpenDocumentFile(LPCTSTR lpszFileName) 
{
	// TODO: Add your specialized code here and/or call the base class
	//load file to the empty doc which is opend when initializing.
//	ASSERT(m_pDocManager != NULL);
	POSITION pos=m_pDocManager->GetFirstDocTemplatePosition();
	if(pos!=NULL)
	{
		CDocTemplate* pTemplate = m_pDocManager->GetNextDocTemplate(pos);
		POSITION pos2 = pTemplate->GetFirstDocPosition();
		if(pos2!=NULL)
		{
			CMyIEDoc * pDoc = (CMyIEDoc*)pTemplate->GetNextDoc(pos2);
			if(pDoc!=NULL && pDoc->m_bEmpty)
			{
				pDoc->m_bEmpty=false;
				POSITION dpos = pDoc->GetFirstViewPosition();
				CFixedHtmlView* pv =((CFixedHtmlView*)(pDoc->GetNextView(dpos)));
				pv->Navigate2(lpszFileName,NULL,NULL);
				pDoc->SetPathName(lpszFileName);
				
				//bring the MDI child window to the top, 
				//we should bring the frame to top, not the view itself.
				//a view has no title bar and border.
				pv->GetParentFrame()->BringWindowToTop(); 
				return pDoc;
			}
		}
	}
	return CWinApp::OpenDocumentFile(lpszFileName);
}*/

int CMyIEApp::ExitInstance() 
{
	// TODO: Add your specialized code here and/or call the base class
	CoUninitialize();

	delete m_pDispOM;

	//delete agent
	HKEY            hKey;
	TCHAR           sz[MAX_PATH];

	if(RegOpenKey(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\User Agent\\Post Platform"), &hKey) != ERROR_SUCCESS)
	{
		TRACE0("Main setting not found\n");
	}
	else
	{
		RegDeleteValue(hKey, _T(MyIEVer));
		RegCloseKey(hKey);
	}

//	CloseHandle(m_hMutex);

	return CWinApp::ExitInstance();

⌨️ 快捷键说明

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