By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,376 Members | 1,566 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,376 IT Pros & Developers. It's quick & easy.

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

P: 79
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?
Jul 18 '07 #1
Share this Question
Share on Google+
2 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
Edit your Word document on a separate thread by calling CreateThread().

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

When WaitForSingleObject() returns, the thread is gone meaning your edit is complete.
Jul 18 '07 #2

P: 79
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?

Expand|Select|Wrap|Line Numbers
  1. _Application wordAppLib;
  2.     CString id("Word.Application");
  3.     BOOL status = wordAppLib.CreateDispatch(id);
  4.  
  5.     _Document myDoc;
  6.     COleVariant covTrue((short)TRUE);
  7.     COleVariant covFalse((short)FALSE);
  8.     COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
  9.     Documents docs = wordAppLib.GetDocuments();
  10.     CString ReportFileName(_T("C:\\Documents and Settings\\Sleep\\Desktop\\CPFTool Project\\CPFTool\\CPFTool\\Library.doc"));
  11.     myDoc = docs.Open(COleVariant(ReportFileName),
  12.         covOptional,
  13.         covFalse,  // ReadOnly
  14.         covOptional,
  15.         covOptional,
  16.         covOptional,
  17.         covOptional,
  18.         covOptional,
  19.         covOptional,
  20.         covOptional,
  21.         covOptional,
  22.         covOptional);
  23.  
  24.  
  25.     wordAppLib.Resize((GetSystemMetrics(SM_CXSCREEN) * 0.375), GetSystemMetrics(SM_CYSCREEN));
  26.     wordAppLib.Move(dtRect.left, dtRect.top);
  27.     wordAppLib.SetVisible(TRUE);
  28.     wordAppLib.Activate();
  29.  
  30.  
  31.     _Application wordAppBlank;
  32.     CString idBlank("Word.Application");
  33.     BOOL statusBlank = wordAppBlank.CreateDispatch(idBlank);
  34.  
  35.     _Document myDocBlank;
  36.  
  37.     Documents docsBlank = wordAppBlank.GetDocuments();
  38.     myDocBlank = docsBlank.Add(covOptional,covOptional,covOptional,covOptional);
  39.  
  40.     wordAppBlank.Resize((GetSystemMetrics(SM_CXSCREEN) * 0.375), GetSystemMetrics(SM_CYSCREEN));
  41.     wordAppBlank.Move(((GetSystemMetrics(SM_CXSCREEN) * 0.375) + 1), 0);
  42.     wordAppBlank.SetVisible(TRUE);
  43.     wordAppBlank.Activate();
Jul 18 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.