Operating Systems :: Windows :: OLE Automation for WordPad - Help!!! |
|||
| By: robi |
Date: 06/02/2003 00:00:00 |
Points: 25 | Status: Answered Quality : Excellent |
|
In my application i am required to display certain textual matter through WordPad. Now i want to control the format of the display. That is to say i want some portion of the text to be in bold, or say the font changed etc. I want this to be controlled from my application. I believe OLE Automation is a possible way out for this and i have achieved it for Microsoft Word. But I don't know how to do this with WordPad. I am coding in VC using MFC. Can somebody suggest me a solution to this. How do i achieve OLE Automation for WordPad/Notepad? |
|||
| By: VGR | Date: 06/02/2003 22:29:00 | Type : Comment |
|
| easy. Wordpad understands RTF build your file with text attributes in RTF and just open if programmatically (Shell(...) ) if wordpad is not assiciated with RTFs, the worst you'll end upo with is that Word will open i.s.o. Wordpad :D :D example of an RTF file (RTF is text, like Postscript, remember this) Ty: Contract is in bold Ty: Permanent is in italic {\rtf1\ansi\ansicpg1252\deff0\deflang1036{\fonttbl{\f0\fnil\fcharset0 Courier New;}} \viewkind4\uc1\pard\b\f0\fs20 Ty: Contract\b0\par Po: Project Manager/Delphi Developer\par [snip more lines ended with \par] \i Ty: Permanent\par \i0 next line begins here\par \par } it's rather easy... If you want to stick with OLE Automation, I may also help, though. |
|||
| By: robi | Date: 06/02/2003 23:14:00 | Type : Comment |
|
| I am coding in VC using MFC. I believe the solution you have given will serve my purpose but i am not sure of how to put this to use. Could you please explain with an example considering say i want to print a sample text as :- Help me use Rich Text Format in conjunction with MFC. Say "Help" and "Rich Text Format" in the above sample is to be in bold and say "MFC" in italic. I would appreciate it if u could demonstrate this example with a code snippet. |
|||
| By: robi | Date: 06/02/2003 23:59:00 | Type : Comment |
|
| Just ignore the comment above where I have asked for an example code. I have found the related information. I think that will meet my requirement. But still I would also like to know if OLE Automation is possible for WordPad/NotePad and how it can be achieved. Looking forward to hear regarding this. |
|||
| By: VGR | Date: 07/02/2003 07:05:00 | Type : Comment |
|
| it's just a text file to produce |
|||
| By: VGR | Date: 07/02/2003 20:05:00 | Type : Answer |
|
| I would suggest trying as you know how to make an OLE Automation client for Word (WinWord, CLSID xxxx), then try the same code on values taken from the Registry for WordPad. It may work. --reference : GUIDs are statistically unique numbers that can be used by the operating system or a programmer to reference an OLE object. A CLSID is a GUID that references a COM object that contains one or more interfaces. You declare a COM object inside a coclass, as described earlier in this chapter. CLSIDs are stored in the Registry. In this case, visiting the actual perpetrator in its native habitat is probably best. In the example explained here, I'm assuming that you have a copy of Word loaded on your system. To get started, use the Run menu on the Windows Taskbar to launch the RegEdit program that ships with Windows NT or Windows 95. To start the program, just type RegEdit in the Run box and click OK. The program is on your path. Once the program is open, Search through HKEY_CLASSES_ROOT for the Word.Basic entry, as shown in Figure 7. (If you don't have Word, you can look instead for one of the following entries: InternetExplorer.Application, Paint.Picture, or WordPad.Document.1) When you find Word.Basic, you can see that it's associated with the following CLSID: {000209FE-0000-0000-C000-000000000046} This unique class ID is inserted into the Registry of all machines that contain a valid, and properly installed, copy of Word for Windows. The only application that uses this ID is Word for Windows. It belongs uniquely to that application. Figure 7: If you run the Windows program REGEDIT.EXE, then you can see the registration database entry for Word.Basic under HKEY_CLASSES_ROOT. Now go further up HKEY_CLASSES_ROOT and look for the CLSID branch. Open it and search for the CLSID shown above. When you find it, you can see two entries associated with it: one is called LocalServer, or LocalServer32, and the other called ProgID. The ProgID is set to word.basic. The LocalServer32 entry looks something like this: C:\WINWORD\WINWORD.EXE /Automation If you look at this command, you can begin to grasp how Windows can translate the CLSID passed to CoCreateInstance or CoGetClassObject into the name of an executable. In particular, Windows looks up the CLSID in the Registry and then uses the LocalServer32 entry to find the directory and name of the executable or DLL you want to launch. The reason your are loading the DLL or executable is so you can access the COM objects that reside inside it. Having these kinds of entries in the registration database does not mean that the applications in question are necessarily Automation servers. For example, many applications with LocalServer and ProgID entries are not Automation servers. However, all Automation servers do have these two entries. Note, further, that this is a reference to the Automation server in Word, not a reference to Word as a generic application. It references an automation object inside Word, not Word itself. (The automation object is an instance of IDispatch. It was not created with the C++Builder ActiveX wizard and the ATL, but it has all the same attributes. Many, but not all, of the Word interfaces support both dual interfaces and dispinterfaces.) The same basic scenario outlined here takes place when you call CoGetClassObject or CoCreateInstanceEx and specify the CLSID of an object on another machine. In particular, Windows contacts the specified machine, asks it to look up the CLSID in the Registry, and then marshals information back and forth between the two machines. You will hear much more about this subject in the next chapter. |
|||
| By: robi | Date: 10/02/2003 13:36:00 | Type : Comment |
|
| Thanx. It was really helpful. |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








