コード例 #1
0
ファイル: StkUI.cpp プロジェクト: amikey/tradingstrategyking
CStrategy* CStkUIApp::OpenStrategyFile( LPCTSTR lpszPathName )
{
	// Resolve File Name
	TCHAR szPath[_MAX_PATH];
	ASSERT(lstrlen(lpszPathName) < sizeof(szPath));
	if( NULL != lpszPathName )
	{
		TCHAR szTemp[_MAX_PATH];
		if (lpszPathName[0] == '\"')
			++lpszPathName;
		lstrcpyn(szTemp, lpszPathName, _MAX_PATH);
		LPTSTR lpszLast = _tcsrchr(szTemp, '\"');
		if (lpszLast != NULL)
			*lpszLast = 0;
		AfxFullPath(szPath, szTemp);
		TCHAR szLinkName[_MAX_PATH];
		if (AfxResolveShortcut(AfxGetMainWnd(), szPath, szLinkName, _MAX_PATH))
			lstrcpy(szPath, szLinkName);
	}

	if( NULL != lpszPathName )
	{
		POSITION pos = GetFirstStrategyPosition();
		while (pos != NULL)
		{
			CStrategy* pStrategy = GetNextStrategy(pos);
			if( 0 == pStrategy->GetPathName().CompareNoCase( szPath ) )
			{
				if( m_bAutoUpdateViews )
				{
					::SendMessage( AfxGetStrategyView()->GetSafeHwnd(), WM_USER_ACTIVATESTRATEGY, DWORD(pStrategy), 0 );
					AfxGetStaticDoc()->UpdateAllViews( NULL, UPDATE_HINT_WIZARDVIEW, NULL );
					// AfxGetMainFrame()->ShowWorkspBar( );
				}
				return pStrategy;
			}
		}
	}

	CStrategy   * pStrategy = new CStrategy();
	if( NULL == pStrategy )
		return NULL;
	char	szErr[256];
	if( !pStrategy->OpenStrategyFile( szPath, szErr, sizeof(szErr)-1 ) )
	{
		AfxMessageBox( szErr, MB_OK|MB_ICONINFORMATION );
		delete	pStrategy;
		return NULL;
	}
	
	AddStrategy( pStrategy );
	return pStrategy;
}
コード例 #2
0
ファイル: StaticDoc.cpp プロジェクト: ZhaoboMeng/k-line-print
CStaticDoc* CStaticDoc::OpenDocumentFile( LPCTSTR lpszPathName )
{
	// Resolve File Name
	TCHAR szPath[_MAX_PATH];
	ASSERT(lstrlen(lpszPathName) < sizeof(szPath));
	if( NULL != lpszPathName )
	{
		TCHAR szTemp[_MAX_PATH];
		if (lpszPathName[0] == '\"')
			++lpszPathName;
		lstrcpyn(szTemp, lpszPathName, _MAX_PATH);
		LPTSTR lpszLast = _tcsrchr(szTemp, '\"');
		if (lpszLast != NULL)
			*lpszLast = 0;
		AfxFullPath(szPath, szTemp);
		TCHAR szLinkName[_MAX_PATH];
		if (AfxResolveShortcut(AfxGetMainWnd(), szPath, szLinkName, _MAX_PATH))
			lstrcpy(szPath, szLinkName);
	}

	// Create document
	CStaticDoc *pDocument = CreateNewDocument( );
	if( NULL == pDocument )
		return NULL;

	if (lpszPathName == NULL)
	{
		// create a new document
		if (!pDocument->OnNewDocument())
		{
			// user has been alerted to what failed in OnNewDocument
			TRACE0("CStaticDoc::OnNewDocument returned FALSE.\n");
			delete pDocument;
			return NULL;
		}
	}
	else
	{
		CWaitCursor wait;

		// open an existing document
		BOOL bWasModified = pDocument->IsModified();
		pDocument->SetModifiedFlag(FALSE);  // not dirty for open

		if (!pDocument->OnOpenDocument( szPath ))
		{
			// user has been alerted to what failed in OnOpenDocument
			TRACE0("CStaticDoc::OnOpenDocument returned FALSE.\n");
			if (!pDocument->IsModified())
			{
				// original document is untouched
				pDocument->SetModifiedFlag(bWasModified);
			}
			else
			{
				// we corrupted the original document
				if (!pDocument->OnNewDocument())
				{
					TRACE0("Error: OnNewDocument failed after trying to open a document - trying to continue.\n");
					// assume we can continue
				}
			}
			delete pDocument;
			return NULL;        // open failed
		}
		pDocument->SetPathName(szPath);
	}
	return pDocument;
}
コード例 #3
0
CDocument* CMyDocManager::OpenDocumentFile(LPCTSTR lpszFileName)
{
	// From MFC: CDocManager::OpenDocumentFile

	CString strFileName = lpszFileName;

	strFileName.TrimLeft();
	strFileName.TrimRight();
	if (strFileName[0] == '\"')
		strFileName.Delete(0);
	int nPos = strFileName.ReverseFind('\"');
	if (nPos != -1)
		strFileName.Delete(nPos);

	CString strQuery, strPage;
	nPos = strFileName.Find('?');
	if (nPos != -1)
	{
		strQuery = strFileName.Mid(nPos + 1);
		strFileName = strFileName.Left(nPos);
	}

	bool bPathTooLong = false;
	TCHAR szPath[_MAX_PATH];
	if (!AfxFullPath(szPath, strFileName))
		bPathTooLong = true;

	if (bPathTooLong || !PathFileExists(szPath))
	{
		// Try extracting page number
		nPos = strFileName.ReverseFind('#');
		if (nPos != -1)
		{
			strPage = strFileName.Mid(nPos + 1);
			strFileName = strFileName.Left(nPos);

			if (!AfxFullPath(szPath, strFileName))
				bPathTooLong = true;
		}
	}

	if (bPathTooLong)
	{
		AfxMessageBox(FormatString(IDS_PATH_TOO_LONG, szPath), MB_ICONEXCLAMATION | MB_OK);
		return NULL;
	}

	TCHAR szLinkName[_MAX_PATH];
	if (AfxResolveShortcut(GetMainWnd(), szPath, szLinkName, _MAX_PATH))
		lstrcpy(szPath, szLinkName);

	// find the highest confidence
	CDocTemplate::Confidence bestMatch = CDocTemplate::noAttempt;
	CDocTemplate* pBestTemplate = NULL;
	CDocument* pOpenDocument = NULL;
	CMainFrame* pOldMainFrm = (CMainFrame*) theApp.m_pMainWnd;

	POSITION pos = m_templateList.GetHeadPosition();
	while (pos != NULL)
	{
		CDocTemplate* pTemplate = (CDocTemplate*)m_templateList.GetNext(pos);
		ASSERT_KINDOF(CDocTemplate, pTemplate);

		CDocTemplate::Confidence match;
		ASSERT(pOpenDocument == NULL);
		match = pTemplate->MatchDocType(szPath, pOpenDocument);
		if (match > bestMatch)
		{
			bestMatch = match;
			pBestTemplate = pTemplate;
		}
		if (match == CDocTemplate::yesAlreadyOpen)
			break;
	}

	if (pOpenDocument != NULL)
	{
		POSITION pos = pOpenDocument->GetFirstViewPosition();
		if (pos != NULL)
		{
			CView* pView = pOpenDocument->GetNextView(pos);
			ASSERT_VALID(pView);

			CMainFrame* pMainFrm = (CMainFrame*) pView->GetTopLevelFrame();
			pMainFrm->ActivateDocument(pOpenDocument);
		}
		else
			TRACE(_T("Error: Can not find a view for document to activate.\n"));
	}

	if (pOpenDocument == NULL)
	{
		if (pBestTemplate == NULL)
		{
			AfxMessageBox(AFX_IDP_FAILED_TO_OPEN_DOC);
			return NULL;
		}

		pOpenDocument = pBestTemplate->OpenDocumentFile(szPath);
	}

	if (pOpenDocument != NULL)
	{
		CDjVuDoc* pDoc = (CDjVuDoc*) pOpenDocument;
		CDjVuView* pView = pDoc->GetDjVuView();
		CMainFrame* pMainFrm = pView->GetMainFrame();

		// CDocManager::OnDDECommand shows the previous main window.
		// If it was in the fullscreen mode, hide it back.
		if (pOldMainFrm != NULL && pOldMainFrm != pMainFrm && pOldMainFrm->IsFullscreenMode())
			pOldMainFrm->ShowWindow(SW_HIDE);

		if (!strPage.IsEmpty())
			pView->GoToURL(MakeUTF8String(_T("#") + strPage));
	}

	return pOpenDocument;
}