Can I use AddModule for .rtf textfiles?

Started by John Montenigro, September 15, 2006, 01:55:55 PM

Previous topic - Next topic

John Montenigro

With regard to: what are the limits of “Project/Add Module”:

I have several .rtf files created in MSWord, each containing different Help topics. Currently, my app reads them during startup, and stores them until needed in a global array of flex strings.

I have one Help Form. It contains one RichText control and an OK command button. When I call the Help Form, I use the UserData parameter to indicate which text I want to display:
     nReturn = frmHelp_Show (hWndForm, %TRUE, %HLP_TOPIC1)    

The Help Form contains:
     FF_TEXTBOX_SETTEXT hWnd_frmHelp_richeditHelp, gHelpText$(UserData)
and except for not having word wrap, the text displays fine. (I didn't see any settings that would enable word-wrap. Did I miss something?)

I'm wondering if there might be a more direct method of getting the .rtf text into my application: Can I add an .rtf file as a Module, sort of the way a Resource file can be attached? If so, how would I access the text?

Am I right in thinking this is reasonable, or am I off track here?

TechSupport

You can "easily" store the RTF files in the resource file. Add a New Resource file to your application ("Project", "Add Resource Module"). Add code liek the following:

RTFHELP RCDATA DISCARDABLE "MYHELPFILE.RTF"


When you want to retrieve the rtf text from the resource file you will need to use code like the following:

   Local L1    As Long
   Local L2    As Long
   Local D1    As Dword
   Local nSize As Long
   Local sBuffer As String
   
   L1 = FindResource( App.hInstance, "RTFHELP", ByVal %RT_RCDATA )
   If L1 Then  
      nSize = SizeofResource( App.hInstance, L1 )
      L2 = LoadResource( App.hInstance, L1 )
      If L2 Then
         D1 = LockResource( L2 )
         sBuffer = Peek$( D1, nSize )
      End If
   End If
     
   FF_TextBox_SetText HWND_FORM1_RICHEDIT1, sBuffer


To make your RichEdit control wordwrap you should go into the "WindowStyles" property and uncheck the WS_HSCROLL and WS_AUTOHSCROLL properties. You may want to check the ES_READONLY property as well.

Hope this helps. See? I told you it was easy.  :)

John Montenigro

Quote from: TechSupportSee? I told you it was easy.  :)

Well, easy to incorporate, but not to understand. I've read through the WinApi.hlp file descriptions for the calls and their structures. Some of it's still a mystery to me (eventually I'll learn):
- What is the module that the help doc refers to?
- I would never have known about using it as a resource, that the resource needed to be locked, or that there would be an API call for it...
- App.hInstance - where does it get it's value from?

OK, so it took me some time (including distractions in the the form of work...), but now I'm using it and it's working perfectly. I have it set up as a string function that returns the RTF text fom the resource to a global. Each menu item calls the function for its RTF text, then brings up the help form. The help form fills the richedit control from the global string...

Thanks for the guidance!

-John