Announcement

Collapse
No announcement yet.

RichEdit with nsDialogs?

Collapse
X
 
  • 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:
    nsDialogs::CreateControl /NOUNLOAD RICHEDIT_CLASS ${WS_VISIBLE}|${WS_CHILD}|${WS_TABSTOP}|${WS_VSCROLL}|${ES_MULTILINE}|${ES_WANTRETURN} ${__NSD_Text_EXSTYLE0 10u 10090u ''

    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

    Comment


    • #3
      Thanks, RichEdit20A worked.

      Comment


      • #4
        Hi!

        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.

        Brad.

        Comment


        • #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

          Comment


          • #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...

            Comment


            • #7
              its the same message (http://msdn2.microsoft.com/en-us/lib...02(VS.85).aspx )

              just use SF_RTF (2)

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

              Comment


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

                Comment


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

                  http://nsis.sourceforge.net/External_License_file

                  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.

                  Comment


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

                    code:

                    nsDialogs::CreateControl /NOUNLOAD "RichEdit20A" ${WS_VISIBLE}|${WS_CHILD}|\
                    ${WS_TABSTOP}|${WS_VSCROLL}|${ES_MULTILINE}|\
                    ${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?

                    Brad.

                    Comment


                    • #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 == ""
                              
                      ClearErrors
                              System
                      ::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
                              System
                      ::Call 'kernel32::GetFileSize(i r0, i 0) i .r1'
                              
                      System::Alloc $1
                              Pop 
                      $2
                              
                              
                      ;read the file into memory
                              System
                      ::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
                          
                      ${EndIf}
                          
                          ;
                      White backgroundblack text
                          SetCtlColors $txtLicense 0x000000 0x00FFFFFF
                          
                          SendMessage $txtLicense 
                      ${WM_SETTEXT0 $LicFile

                          
                      exit:
                      !
                      macroend 
                      Then, deallocate the memory when the installer closes:

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

                      Comment


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

                        Comment


                        • #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?

                          Comment


                          • #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

                            Comment


                            • #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.

                              Comment

                              Working...
                              X
                              😀
                              🥰
                              🤢
                              😎
                              😡
                              👍
                              👎