コード例 #1
0
ファイル: TRiASDocTempl.cpp プロジェクト: hkaiser/TRiAS
/////////////////////////////////////////////////////////////////////////////
// CTRiASDocTemplate commands
CTRiASView* CTRiASDocTemplate::SubclassView (CFrameWnd *pMainFrm, HWND hWndView)
{
	TRACE( "FakeMFC: CTRiASDocTemplate::SubclassView\r\n");

// Document erzeugen
CDocument* pDocument = CreateNewDocument();

	if (pDocument == NULL)
	{
		AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
		return NULL;
	}
	ASSERT(pDocument == m_pOnlyDoc);

// Frame mitteilen, daß View erzeugt/Subclassed werden muß
BOOL bAutoDelete = pDocument->m_bAutoDelete;
CTRiASView *pViewWnd = NULL;

	pDocument->m_bAutoDelete = FALSE;	// don't destroy if something goes wrong
	pViewWnd = CreateSubclassedView (pDocument, hWndView);
	pDocument->m_bAutoDelete = bAutoDelete;

	if (NULL == pViewWnd) {
		AfxMessageBox (AFX_IDP_FAILED_TO_CREATE_DOC);
		delete pDocument;       // explicit delete on error
		return NULL;
	}

// Die neue View als aktive im Frame setzen
	pMainFrm -> SetActiveView (pViewWnd);

	AfxGetApp()->m_nCmdShow = DEXI_isAppWindowVisible() ? SW_SHOW : SW_HIDE; // set to default after first time
	InitialUpdateFrame(pMainFrm, pDocument, TRUE);
	return pViewWnd;
}
コード例 #2
0
CDocument* CMyDocTemplate::OpenDocumentFile(LPCTSTR lpszPathName, BOOL bMakeVisible)
{
	if (lpszPathName == NULL)
	{
		TRACE(_T("Creating new documents is disabled.\n"));
		return NULL;
	}

	CWaitCursor wait;

	CDocument* pDocument = CreateNewDocument();
	if (pDocument == NULL)
	{
		TRACE(_T("CDocTemplate::CreateNewDocument returned NULL.\n"));
		AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
		return NULL;
	}
	ASSERT_VALID(pDocument);

	BOOL bAutoDelete = pDocument->m_bAutoDelete;
	pDocument->m_bAutoDelete = false;   // don't destroy if something goes wrong

	CWnd* pMDIChild = CreateNewMDIChild(pDocument);

	pDocument->m_bAutoDelete = bAutoDelete;
	if (pMDIChild == NULL)
	{
		AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
		delete pDocument;       // explicit delete on error
		return NULL;
	}
	ASSERT_VALID(pMDIChild);

	// open an existing document
	if (!pDocument->OnOpenDocument(lpszPathName))
	{
		// user has be alerted to what failed in OnOpenDocument
		TRACE(_T("CDocument::OnOpenDocument returned FALSE.\n"));
		pMDIChild->DestroyWindow();
		return NULL;
	}
	pDocument->SetPathName(lpszPathName);

	InitialUpdateMDIChild(pMDIChild, pDocument, bMakeVisible);
	return pDocument;
}
コード例 #3
0
ファイル: visualmsthread.cpp プロジェクト: artemeliy/inf4715
// ============================================================================
CVMSDocTemplate::CVMSDocTemplate(
    UINT nIDResource,
    CRuntimeClass* pDocClass,
    CRuntimeClass* pFrameClass,
    CRuntimeClass* pViewClass,
    CVisualMSThread *pThread)
    : CSingleDocTemplate(nIDResource, pDocClass, pFrameClass, pViewClass)
{
    m_pThread = pThread;

    m_pOnlyDoc = CreateNewDocument();
    ASSERT(m_pOnlyDoc != NULL);
    m_pThread->m_pMainDoc = (CVisualMSDoc*)m_pOnlyDoc;

    CFrameWnd *pFrame = CreateNewFrame(m_pOnlyDoc, NULL);
    ASSERT(pFrame != NULL);
    m_pThread->m_pMainWnd = pFrame;

    InitialUpdateFrame(pFrame, m_pOnlyDoc, FALSE);
    m_pOnlyDoc->OnNewDocument();
}
コード例 #4
0
   /// <summary>Opens a new document using a template file.</summary>
   /// <param name="docPath">Initial document path.</param>
   /// <param name="t">template.</param>
   /// <param name="bMakeVisible">make visible.</param>
   /// <returns></returns>
   /// <exception cref="Logic::ApplicationException">Unable to create document or view<exception>
   /// <exception cref="Logic::FileNotFoundException">Template file is missing<exception>
   DocumentBase* ProjectDocTemplate::OpenDocumentTemplate(Path docPath, const TemplateFile& t, BOOL bMakeVisible)
   {
      AppPath templatePath(t.SubPath);
      ProjectDocument* pDocument = nullptr;

      // Verify template file exists
      if (!templatePath.Exists())
         throw FileNotFoundException(HERE, templatePath);

      // Existing document - close/save
	   if (pDocument = dynamic_cast<ProjectDocument*>(m_pOnlyDoc))
         if (!pDocument->CloseModified())
		      return nullptr; 
	   
      // create new doc
		pDocument = dynamic_cast<ProjectDocument*>(CreateNewDocument());     // Sets m_pOnlyDoc
      if (!pDocument)
         throw ApplicationException(HERE, L"Failed to create document class");

      // Use default title
		//SetDefaultTitle(pDocument);

      // Open template file
		if (!pDocument->OnOpenTemplate(docPath, t))
		{
			// Failed: Cleanup
         delete pDocument;
			return nullptr;
		}
      
      // Set user-selected path (+ update title)
      pDocument->SetPathName(docPath.c_str(), FALSE);

      // Raise 'After New Document'
      pDocument->OnDocumentEvent(CDocument::onAfterNewDocument);

      // Ensure *MODIFIED* because file doesn't exist on disc yet
      pDocument->SetModifiedFlag(TRUE);
	   return pDocument;
   }
コード例 #5
0
ファイル: DComDoc.cpp プロジェクト: cdesjardins/DCom
CDocument* CMyMultiDocTemplate::OpenDocumentFile(SDialingDir *psDialingDir)
{
    CDComDoc* pDocument = (CDComDoc*)CreateNewDocument();
    if (pDocument == NULL)
    {
        TRACE(traceAppMsg, 0, "CDocTemplate::CreateNewDocument returned NULL.\n");
        AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
        return NULL;
    }
    ASSERT_VALID(pDocument);

    BOOL bAutoDelete = pDocument->m_bAutoDelete;
    pDocument->m_bAutoDelete = FALSE;   // don't destroy if something goes wrong
    CFrameWnd* pFrame = CreateNewFrame(pDocument, NULL);
    pDocument->m_bAutoDelete = bAutoDelete;
    if (pFrame == NULL)
    {
        AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
        delete pDocument;       // explicit delete on error
        return NULL;
    }
    ASSERT_VALID(pFrame);

    // open an existing document
    CWaitCursor wait;
    if (!pDocument->OnOpenDocument(psDialingDir))
    {
        // user has be alerted to what failed in OnOpenDocument
        TRACE(traceAppMsg, 0, "CDocument::OnOpenDocument returned FALSE.\n");
        pFrame->DestroyWindow();
        return NULL;
    }

    InitialUpdateFrame(pFrame, pDocument, TRUE);
    return pDocument;
}
コード例 #6
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;
}
コード例 #7
0
   /// <summary>Opens the document file.</summary>
   /// <param name="szFullPath">The sz full path.</param>
   /// <param name="bAddToMRU">The b add to MRU.</param>
   /// <param name="bMakeVisible">The b make visible.</param>
   /// <returns></returns>
   CDocument* ProjectDocTemplate::OpenDocumentFile(LPCTSTR szFullPath, BOOL bAddToMRU, BOOL bMakeVisible)
   {
	   ProjectDocument* pDocument = nullptr;

      // Check: Ensure not called by framework in unsupported manner
	   if (!szFullPath)
      {
         AfxMessageBox(L"Invariant violated -- ProjectDocTemplate::OpenDocumentFile() attempting to create new project");
         return nullptr;
      }

      // Existing project: Save/Close
	   if (pDocument = dynamic_cast<ProjectDocument*>(m_pOnlyDoc))
         if (!pDocument->CloseModified())
		      return nullptr; 
	   
      // create a new document    (Sets m_pOnlyDoc)
		pDocument = dynamic_cast<ProjectDocument*>(CreateNewDocument());     
	   if (!pDocument)
	   {
		   AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
		   return nullptr;
	   }
	   ASSERT(pDocument == m_pOnlyDoc);

      
	   CWaitCursor wait;
      ImportProjectDialog dlg(szFullPath);

		// Preserve 'Modified' flag
		BOOL bWasModified = pDocument->IsModified();
		pDocument->SetModifiedFlag(FALSE);  // not dirty for open

      // Legacy: Upgrade 
      if (IsLegacyProject(szFullPath))
      {
         // IMPORT DOCUMENT
         if (dlg.DoModal() == IDCANCEL || !pDocument->OnImportDocument(szFullPath, dlg.NewPath))
            return nullptr;

         // Open upgraded project, not legacy
         szFullPath = dlg.NewPath.c_str();
         bAddToMRU = TRUE;
      }

      // Set path before open - relied upon for resolving backup paths
      pDocument->SetPathName(szFullPath, bAddToMRU);

      // OPEN DOCUMENT
		if (!pDocument->OnOpenDocument(szFullPath))
		{
			// Failed: Destroy
			delete pDocument;
         m_pOnlyDoc = nullptr;
			return nullptr;
		}

      // Success: Raise 'After Open Document'
		pDocument->OnDocumentEvent(CDocument::onAfterOpenDocument);
	   return pDocument;
   }
コード例 #8
0
ファイル: docsingl.cpp プロジェクト: rickerliang/OpenNT
CDocument* CSingleDocTemplate::OpenDocumentFile(LPCTSTR lpszPathName,
	BOOL bMakeVisible)
	// if lpszPathName == NULL => create new file of this type
{
	CDocument* pDocument = NULL;
	CFrameWnd* pFrame = NULL;
	BOOL bCreated = FALSE;      // => doc and frame created
	BOOL bWasModified = FALSE;

	if (m_pOnlyDoc != NULL)
	{
		// already have a document - reinit it
		pDocument = m_pOnlyDoc;
		if (!pDocument->SaveModified())
			return NULL;        // leave the original one

		pFrame = (CFrameWnd*)AfxGetMainWnd();
		ASSERT(pFrame != NULL);
		ASSERT(pFrame->IsKindOf(RUNTIME_CLASS(CFrameWnd)));
		ASSERT_VALID(pFrame);
	}
	else
	{
		// create a new document
		pDocument = CreateNewDocument();
		ASSERT(pFrame == NULL);     // will be created below
		bCreated = TRUE;
	}

	if (pDocument == NULL)
	{
		AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
		return NULL;
	}
	ASSERT(pDocument == m_pOnlyDoc);

	if (pFrame == NULL)
	{
		ASSERT(bCreated);

		// create frame - set as main document frame
		BOOL bAutoDelete = pDocument->m_bAutoDelete;
		pDocument->m_bAutoDelete = FALSE;
					// don't destroy if something goes wrong
		pFrame = CreateNewFrame(pDocument, NULL);
		pDocument->m_bAutoDelete = bAutoDelete;
		if (pFrame == NULL)
		{
			AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
			delete pDocument;       // explicit delete on error
			return NULL;
		}
	}

	if (lpszPathName == NULL)
	{
		// create a new document
		SetDefaultTitle(pDocument);

		// avoid creating temporary compound file when starting up invisible
		if (!bMakeVisible)
			pDocument->m_bEmbedded = TRUE;

		if (!pDocument->OnNewDocument())
		{
			// user has been alerted to what failed in OnNewDocument
			TRACE0("CDocument::OnNewDocument returned FALSE.\n");
			if (bCreated)
				pFrame->DestroyWindow();    // will destroy document
			return NULL;
		}
	}
	else
	{
		BeginWaitCursor();

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

		if (!pDocument->OnOpenDocument(lpszPathName))
		{
			// user has been alerted to what failed in OnOpenDocument
			TRACE0("CDocument::OnOpenDocument returned FALSE.\n");
			if (bCreated)
			{
				pFrame->DestroyWindow();    // will destroy document
			}
			else if (!pDocument->IsModified())
			{
				// original document is untouched
				pDocument->SetModifiedFlag(bWasModified);
			}
			else
			{
				// we corrupted the original document
				SetDefaultTitle(pDocument);

				if (!pDocument->OnNewDocument())
				{
					TRACE0("Error: OnNewDocument failed after trying to open a document - trying to continue.\n");
					// assume we can continue
				}
			}
			EndWaitCursor();
			return NULL;        // open failed
		}
#ifdef _MAC
		// if the document is dirty, we must have opened a stationery pad - don't
		// change the pathname because we want to treat the document as untitled
		if (!pDocument->IsModified())
#endif
			pDocument->SetPathName(lpszPathName);

		EndWaitCursor();
	}

	if (bCreated && AfxGetMainWnd() == NULL)
	{
		// set as main frame (InitialUpdateFrame will show the window)
		AfxGetThread()->m_pMainWnd = pFrame;
	}
	InitialUpdateFrame(pFrame, pDocument, bMakeVisible);

	return pDocument;
}
コード例 #9
-1
ファイル: SnoopyPro.cpp プロジェクト: cyphunk/sectk
void CSnoopyProApp::ScanForNewSnoopedDevices(void)
{
    TRACE("Accessing usbsnoopies to find new devices...\n");
    HANDLE hSniffer = CreateFile(USBSNPYS_W32NAME_2K, 
        GENERIC_READ | GENERIC_WRITE,
        FILE_SHARE_READ | FILE_SHARE_WRITE,
        NULL, // no SECURITY_ATTRIBUTES structure
        OPEN_EXISTING, // No special create flags
        0, // No special attributes
        NULL);
    
    if(INVALID_HANDLE_VALUE == hSniffer)
    {
        hSniffer = CreateFile(USBSNPYS_W32NAME_9X,
            GENERIC_READ | GENERIC_WRITE,
            FILE_SHARE_READ | FILE_SHARE_WRITE,
            NULL, // no SECURITY_ATTRIBUTES structure
            OPEN_EXISTING,
            FILE_FLAG_DELETE_ON_CLOSE,
            NULL);
    }

    m_bIsSnpysPresent = (INVALID_HANDLE_VALUE != hSniffer);

    if(INVALID_HANDLE_VALUE != hSniffer)
    {
        DWORD dwBytesReturned = 0;
        SNOOPED_DEVICES SnoopedDevices;
        ZeroMemory(&SnoopedDevices, sizeof(SnoopedDevices));

        BOOL bResult = DeviceIoControl(hSniffer, USBSNOOP_GET_SNOOPED_DEVS, 
                &SnoopedDevices, sizeof(SnoopedDevices),
                &SnoopedDevices, sizeof(SnoopedDevices),
                &dwBytesReturned, NULL);
        CloseHandle(hSniffer);
        hSniffer = INVALID_HANDLE_VALUE;

        TRACE("DeviceIoControl(): got %d snooped devices\n", SnoopedDevices.uCount);
        m_nSnpysUsage = SnoopedDevices.uCount;
        if(bResult)
        {
            TRACE("Devices:\n");
            for(ULONG nSnooped = 0; nSnooped < SnoopedDevices.uCount; ++nSnooped)
            {
                PSNOOPED_DEVICE pSnooped = &SnoopedDevices.Entry[nSnooped];
                TRACE(" Dev[%d] = 0x%08x\n", nSnooped, pSnooped->uDeviceID);
                if(INVALID_DEVICE_ID == pSnooped->uDeviceID)
                {
                    TRACE("  .. skipping\n");
                }
                else
                {
                    BOOL bAlreadySnooped = FALSE;
                    if(!m_DocsNeedingUpdate.IsEmpty())
                    {
                        POSITION pos = m_DocsNeedingUpdate.GetHeadPosition();
                        while(NULL != pos)
                        {
                            CUSBLogDoc *pDoc = m_DocsNeedingUpdate.GetNext(pos);
                            ASSERT(NULL != pDoc);
                            if(NULL != pDoc)
                            {
                                if(pSnooped->uDeviceID == pDoc->GetSnifferDevice())
                                {
                                    bAlreadySnooped = TRUE;
                                    break;
                                }
                            }
                        }
                    }
                    if(!bAlreadySnooped)
                    {
                        CUSBLogDoc *pDoc = CreateNewDocument();
                        pDoc->AccessSniffer(pSnooped->uDeviceID, pSnooped->sHardwareIDs);
                        pDoc->SetTimeStampZero(SnoopedDevices.Entry[nSnooped].uTimeStampZero);
                    }
                }
            }
        }
    }
}