No announcement yet.

RichEdit with nsDialogs?

  • Filter
  • Time
  • Show
Clear All
new posts

  • RichEdit with nsDialogs?

    I can't seem to figure out how to add a RichEdit control with nsDialogs. I've tried

    PHP Code:

    Pop $txtLicense 
    But nothing shows. I tried looking at the MUI2 header files, but those are no cakewalk to read. I also glanced at the nsDialogs source files, but that lead me no closer to an answer.

  • #2
    RICHEDIT_CLASS is not the real name, try "RICHEDIT" or "RichEdit20A"
    IntOp $PostCount $PostCount + 1


    • #3
      Thanks, RichEdit20A worked.


      • #4

        Now that I know how to create a richedit control using nsDialogs - thanks for that - how would I go about loading an .rtf file into the control using the system plugin?

        Thanks in advance.



        • #5
          Are you a developer who uses NSIS to distribute your application? Are you a Winamp plug-in developer who wants to use NSIS to distribute your plug-in? Have suggestions for other people like you? This is the place.
          IntOp $PostCount $PostCount + 1


          • #6
            Thanks for your response, Anders.

            The thread you've linked to though has example code that, as best as I can tell, only streams text into the control. Is there any [easy] way to load an actual Rich Text File into the control? I've tried googling for a Windows API command that can do it, but with no luck...


            • #7
              its the same message ( )

              just use SF_RTF (2)

              and easy? there is no such thing when the system plugin is involved
              IntOp $PostCount $PostCount + 1


              • #8
                Thanks again! I'll give it a go....


                • #9
                  I just use this to load the RTF data. The article states '.txt' files, but RTF are just text files with funky formatting.


                  Also, if you want a thin border on the RichEdit box, just use the WS_EX_STATICEDGE flag instead of __NSD_Text_EXSTYLE.

                  Here's the full code I use:

                  PHP Code:
                  ;License textbox (rich text)

                  nsDialogs::CreateControl /NOUNLOAD "RichEdit20A"  ${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS}|${WS_TABSTOP}|${ES_READONLY}|${WS_VSCROLL}|${ES_MULTILINE}|${ES_WANTRETURN} ${WS_EX_STATICEDGE0 10u 10090u ''

                  Pop $txtLicense
                  ;load the license from file
                  !insertmacro addLicense 
                  Last edited by vbguy; 11 March 2008, 14:15.


                  • #10
                    Thanks for your help, vbguy! Here's my code:


                    nsDialogs::CreateControl /NOUNLOAD "RichEdit20A" ${WS_VISIBLE}|${WS_CHILD}|\
                    ${ES_WANTRETURN} ${WS_EX_STATICEDGE} 0 15u 100% 80u ""
                    Pop $CONTROL
                    File "/oname=$PLUGINSDIR\Readme.rtf" "Resources\Readme.rtf"
                    System::Call "kernel32::CreateFile(t '$PLUGINSDIR\Readme.rtf', i ${GENERIC_READ}, \
                    i ${FILE_SHARE_READ}, i 0, i ${OPEN_EXISTING}, i 0, i 0) i .r0"
                    System::Call "kernel32::GetFileSize(i r0, i 0) i .r1"
                    MessageBox MB_OK "$1"
                    IntOp $1 $1 + 1
                    System::Alloc $1
                    Pop $2
                    System::Call "kernel32::ReadFile(i r0, i r2, i r1, *i .r3, i 0)"
                    System::Call "kernel32::CloseHandle(i r0)"
                    SendMessage $CONTROL ${WM_SETTEXT} $CONTROL $2
                    System::Free $2

                    Unfortunately, it doesn't display all of the RTF file. I'm guessing this is because of the value that GetFileSize returns, and the additional bytes used for the formatting of the RTF file. I tried using EM_STREAMIN as Anders suggested, but I'm completely lost with that bit of code.... Any further ideas?



                    • #11
                      You need to replace the hwnd to point to your added text box (or rich text box):

                      PHP Code:
                      Var txtLicense ;textbox handle
                      Var LicFile ;pointer to the license file in memory

                      !macro addLicense
                      ${If} $LicFile == ""
                      ::Call 'kernel32::CreateFile(t "$PLUGINSDIR\\EULA.rtf", i 0x80000000, i 1, i 0, i 3, i 0, i 0) i .r0'
                      IfErrors exit
                      allocate memory for the file
                      ::Call 'kernel32::GetFileSize(i r0, i 0) i .r1'
                      System::Alloc $1
                      ;read the file into memory
                      ::Call 'kernel32::ReadFile(i r0, i r2, i r1, *i .r3, i 0)'
                      System::Call 'kernel32::CloseHandle(i r0)'
                      Push $2            ;Push the License memory location to stack
                              Pop $LicFile 
                      ;Pop the License memory loc to the variable LicFile
                      White backgroundblack text
                          SetCtlColors $txtLicense 0x000000 0x00FFFFFF
                          SendMessage $txtLicense 
                      ${WM_SETTEXT0 $LicFile

                      Then, deallocate the memory when the installer closes:

                      PHP Code:
                      Function .onGUIEnd
                      ::Free $LicFile ;clear the memory allocated for the license file


                      • #12
                        vbguy: you can't use WM_SETTEXT, it seems to work for some simple rtf files, but not everything
                        IntOp $PostCount $PostCount + 1


                        • #13
                          Thanks for your help guys.

                          Anders, any chance you could give us some example code that streams an .rtf file into a richtext control using EM_STREAMIN? Please? Before I lose any more hair?


                          • #14
                            no, can't make it work, I end up with the same problem as WM_SETTEXT, the file will not load 100%
                            IntOp $PostCount $PostCount + 1


                            • #15
                              Originally posted by Anders
                              vbguy: you can't use WM_SETTEXT, it seems to work for some simple rtf files, but not everything
                              You're right, it would likely fail if embedded images. I'd also like to see an example using streaming (if you have time).

                              Edit: Where in the MUI2 code is the RTF data loaded for the standard license page? Is it done using a C/C++ plugin, or is the file loaded using NSIS code?

                              Couldn't we just hijack the default code and apply it to the newly created RichEdit box?
                              Last edited by vbguy; 11 March 2008, 23:15.