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);
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 }
可以说的详细一些吗?或者说个关键词好让我去搜索。
为了这个我下MYIE的源码去看唉。
我想尽快解决这个问题。
{
// 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);
{
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;
}