home *** CD-ROM | disk | FTP | other *** search
- * DDEWORD1.PRG
- *
- * This simple program shows the basic steps
- * needed for FoxPro to access Microsoft's Word
- * acting as a DDE server. To see how it works,
- * single step through the code, reading the comments
- * as you go. It shows the use of DDEInitiate,
- * DDERequest, DDEPoke, DDETerminate and DDELastError.
-
- ****************************************************
-
- * The first thing we have to do is start a
- * conversation with the server. In this case,
- * we're going to "talk" to Microsoft Word.
-
- * To do this we start or "initiate" the conversation
- * by opening up a "channel" to Word. (Note, if
- * Word doesn't start on the next step, then either
- * start it manually and retry, or place it in your
- * MS-DOS path before starting Windows.)
-
- channel = DDEInitiate("WinWord", "System")
- ? "Channel is:", channel
-
- * This command will try and start Word if it isn't
- * already running and then tell it that it wants to
- * talk about "System". This is called the "topic"
- * of the conversation. Every conversaction is
- * about only one topic. Only certain topics are
- * understood by the server and only the server
- * documentation can tell you what those are. In
- * the case of Word, we are asking to talk about
- * a special topic called "System", which most
- * dde servers understand.
-
- * Let's ask Word what Topics are available.
- * We do this with the DDERequest command, like so:
-
- ? "<" + DDERequest(channel, "Topics") + ">"
-
- * Notice how the list includes the name "Document1".
- * If other files are open they'll be listed there too.
- * If we switch over to Word and open another document,
- * we can try again.
-
- ? "<" + DDERequest(channel, "Topics") + ">"
-
- * This time we get the newly opened document as well.
- * Notice how this is returned as a string with tabs
- * delimiting each "thing". Everything returned by a
- * simple DDERequest like this will be a string. Tabs
- * are used to delimit things within a row, and CR LF
- * pairs mark the end of each row (if there's more than
- * one).
-
- * In the simple DDERequests above, the second
- * parameter passed to the function is called the
- * "Item". The Item defines what this part of the
- * conversation is about. Remember that we already
- * know that the main topic of conversation is
- * "System". The Item is a sub-topic within
- * the main topic.
-
- * If we open a conversation on the document itself,
- * rather than "System", we can find out what is in
- * the document. This is done by retrieving the contents
- * of a special pre-defined Word bookmark called "\doc".
-
- chan2 = DDEInitiate("WinWord", "Document1")
- ? "<" + DDERequest(chan2, "\doc") + ">"
-
- * If we switch over to Word and put some text in there
- * we can verify that it is retrieved via DDE.
-
- wait window "Switch to Word and enter some text..."
- ? "<" + DDERequest(chan2, "\doc") + ">"
-
- * When we're finished with a conversation, we can
- * end it by using the "DDETerminate" function. I.e.
-
- ? DDETerminate(chan2)
- ? DDETerminate(channel)
-
- * Notice how all the DDE commands are actually
- * functions. I.e., they all return a value.
- * Typically this value will be .T. If an error
- * occurs, then .F. will be returned. You can then
- * use the DDELastError function to determine why it
- * failed. For example, if I now try and Poke to
- * the channel I just closed:
-
- ? "<" + DDERequest(channel, "Topics") + ">"
-
- * I get nothing returned. By checking DDELastError
-
- ? DDELastError()
-
- * and looking up the help entry for it, you can see
- * what went wrong (bad channel number).
-