"Pausing" an MFC application while Word doc is opened.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ahammad
    New Member
    • May 2007
    • 79

    "Pausing" an MFC application while Word doc is opened.

    I have an MFC application that opens up a Word document for editing using automation. Is there a way to pause or freeze the MFC application while the Word doc is being edited? After the editing is done and Word is closed, I want the MFC application to regain control and continue with doing something else. It's kind of like having it take a break until Microsoft Word is closed.

    How can this be implemented?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Edit your Word document on a separate thread by calling CreateThread().

    Use the HANDLE returned by CreaateThread() as an argument to WaitForSingleOb ject().

    When WaitForSingleOb ject() returns, the thread is gone meaning your edit is complete.

    Comment

    • ahammad
      New Member
      • May 2007
      • 79

      #3
      I've never heard of this before...could you please show me an example of how to implement that with my code which uses Automation?

      Code:
      _Application wordAppLib;
      	CString id("Word.Application");
      	BOOL status = wordAppLib.CreateDispatch(id);
      
      	_Document myDoc;
      	COleVariant covTrue((short)TRUE);
      	COleVariant covFalse((short)FALSE);
      	COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
      	Documents docs = wordAppLib.GetDocuments();
      	CString ReportFileName(_T("C:\\Documents and Settings\\Sleep\\Desktop\\CPFTool Project\\CPFTool\\CPFTool\\Library.doc"));
      	myDoc = docs.Open(COleVariant(ReportFileName),
      		covOptional,
      		covFalse,  // ReadOnly
      		covOptional,
      		covOptional,
      		covOptional,
      		covOptional,
      		covOptional,
      		covOptional,
      		covOptional,
      		covOptional,
      		covOptional);
      
      
      	wordAppLib.Resize((GetSystemMetrics(SM_CXSCREEN) * 0.375), GetSystemMetrics(SM_CYSCREEN));
      	wordAppLib.Move(dtRect.left, dtRect.top);
      	wordAppLib.SetVisible(TRUE);
      	wordAppLib.Activate();
      
      
      	_Application wordAppBlank;
      	CString idBlank("Word.Application");
      	BOOL statusBlank = wordAppBlank.CreateDispatch(idBlank);
      
      	_Document myDocBlank;
      
      	Documents docsBlank = wordAppBlank.GetDocuments();
      	myDocBlank = docsBlank.Add(covOptional,covOptional,covOptional,covOptional);
      
      	wordAppBlank.Resize((GetSystemMetrics(SM_CXSCREEN) * 0.375), GetSystemMetrics(SM_CYSCREEN));
      	wordAppBlank.Move(((GetSystemMetrics(SM_CXSCREEN) * 0.375) + 1), 0);
      	wordAppBlank.SetVisible(TRUE);
      	wordAppBlank.Activate();

      Comment

      Working...