Help:Visual C++6 - How to run a wordprocessor in a dialog based application

  • 12 years ago
    Can anybody help me? I am trying to find a way to start/launch a word processor(MS Works or MS Word word processor) in a MS Visual C++6 dialog based application. I have tried the following statement but it has failed to locate the application file: WinExe("c:\Program Files\Microsoft Works\WksWP",SW_SHOW);//WksWP is for the MS Works wordprocessor. or WinExec("WksWP",SW_SHOW); If anybody can tell me how to launch a word processor, I will be greateful. Thanks Chong Kim.

  • 12 years ago

    Hi Chong,

    If you want to run Office Word from your app not in your app, there are two ways :

    1. As you said running Word executable file(winword.exe). I can use the following :

    ShellExecute( NULL, "open", "E:\\Microsoft Office 2007 Enterprise\\Office12\\winword.exe", NULL, NULL, SW_SHOW ); // 'E:\Microsoft Office 2007 Enterprise\Office12' is the office installation path

    But how can you find the path on your client to run the 'winword.exe' file? There is an article on MSDN that demonstrates that(it's not a simple work!) : How To Find the Path and Version of an Office Application from Visual C++

    2. Using Office Automation : you just need a small(easy) part of this big concept, running the Word! If you want to know how to use office automation in your MFC apps, see an example on MSDN : HOWTO: Use Microsoft Foundation Classes (MFC) to Automate Word and Create a Mail Merge for Mailing Labels

    Just note that, if you're using Office 2007, you should include 'msword.h' (instead the one used in the example), this header file will be generated automatically by VC++ in your application folder. The code that you need to run the Word 2007 is :

    (in this example, a button(BUTT_TEST)'s click event handler contains the code)

    #include "msword.h"

    ...

    void CTestDlg::OnBUTT_TEST()

    {

    _Application oApp;

    //Start Word.

    if(!oApp.CreateDispatch("Word.Application",NULL))

    {

    AfxMessageBox(
    "Unable to start Word.");
    return;

    }

     

    oApp.SetVisible(TRUE);  // show the Word's window

    }

  • 12 years ago

    Hi Mohammad, thanks for helping me out once again.  You are a good friend!!  By the way, I have found a way to launch a word processor file rather easily.  All you have to do is to have a word file first and then use ShellExecute as follows:

    ShellExecute (NULL, "open", "testfile.wps",..) ;

    This will opent the testfile.wps with MS Works word processor.  Make sure that testfile.wps has been created by MS Works word processor.  Otherwise MS Works word processor will find it corrupt and fail to open it.

    Thanks again, Mohammad

     

    By the way, do you know how to disable all the "Save as ..." and etc except "Save" in MS Works word processor for example?  When I use ShellExecute(NULL,"open","testfile.wps",...), I like to ensure that testfile.wps can be saved as testfile.wps alone.  So if you know how to disable some of these saving as functions in MS Works word processor, I will be really grateful!

    Best regards

    Chong 

  • 12 years ago

    Hi dear Chong,

    I never worked with MS Works, even never know about that since you said about it!!

    Anyway, If you mean to remove some of types in save as dialog, I didn't do that and don't know how to do, but here is something :

    We should have control on the external program(Word or Works), like with passing a parameter when opening the program/document with 'ShellExecute()' or like with Automation for Word. For example if we don't want user  change the document, we can open the document as read only.

    Do you have anything to help making progress in this problem?(do you have any clues?) Confused

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“If debugging is the process of removing software bugs, then programming must be the process of putting them in.” - Edsger Dijkstra