Skip to content
⌘ NSIS Forum Archive

RichEdit with nsDialogs?

15 posts

vbguy#

RichEdit with nsDialogs?

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

nsDialogs::CreateControl /NOUNLOAD RICHEDIT_CLASS ${WS_VISIBLE}|${WS_CHILD}|${WS_TABSTOP}|${WS_VSCROLL}|${ES_MULTILINE}|${ES_WANTRETURN} ${__NSD_Text_EXSTYLE} 0 10u 100% 90u ''
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.
bradharding#
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.
Anders#
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.
bradharding#
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...
Anders#
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 😉
vbguy#edited
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:

;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_STATICEDGE} 0 10u 100% 90u ''
Pop $txtLicense
    
;load the license from file
!insertmacro addLicense 
bradharding#
Thanks for your help, vbguy! Here's my 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.
vbguy#
You need to replace the hwnd to point to your added text box (or rich text box):

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 background, black text
    SetCtlColors $txtLicense 0x000000 0x00FFFFFF
    
    SendMessage $txtLicense ${WM_SETTEXT} 0 $LicFile
    exit:
!macroend 
Then, deallocate the memory when the installer closes:

Function .onGUIEnd
    System::Free $LicFile ;clear the memory allocated for the license file
FunctionEnd 
Anders#
vbguy: you can't use WM_SETTEXT, it seems to work for some simple rtf files, but not everything
bradharding#
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? 😱
Anders#
no, can't make it work, I end up with the same problem as WM_SETTEXT, the file will not load 100%
vbguy#edited
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?