Skip to content
⌘ NSIS Forum Archive

Swap STATIC control with RichEdit20W

13 posts

Endy-kun#

Swap STATIC control with RichEdit20W

Hey guys. Default directory page in MUI has a STATIC control at the top and I can pass some text to it via MUI_DIRECTORYPAGE_TEXT_TOP.

If I will swap that control to RichEdit20W, how do I make the text passed to it actually "rich"? Text doesn't have to be picked up from a file, like in case of license, but can say make it bold or change the color?

Or making my own page with nsdialogs would be a better idea?
Anders#
First off, you can change the control with Resource Hacker and apply it with ChangeUI OR you can create a window at run time.

I believe the nsDialogs example in the latest NSIS v3 has a RichEdit example you can look at that sets rich text.

If you need a directory page with the disk space stuff then it is better to use the built-in page but you can probably get close with a custom page.
Endy-kun#
Yes I already did that. I just discovered that simply passing rft-formatted text actually works, but it stops working (displays as plaintext) as soon as I set Unicode true...

For example adding Unicode true... to nsdialogs' example breaks it as well. I don't remember ever touching nsdialogs plugin binaries.

Should I pass a unicode string somehow? How would I do that?
Endy-kun#
I am on win7 sp1 x64. just reinstalled fresh latest stable nsis. adding Unicode true to the example.nsi of nsdialogs results in this:
Anders#
Unicode + RTF is rather annoying.

For whatever reason it seems you cannot have UTF-16 encoded RTF text data.

It seems like you must encode it in a specific codepage or use escaped codepoints:
RE the question about Unicode in RTF, the user needs to encode the Unicode characters either in a codepage (see \charsetN) or as Unicode values using \uN. These control words are defined in the RTF spec, which is here: http://www.microsoft.com/downloads/d...DisplayLang=en
This page claims you can UTF-8 encode it but I don't know if that means you can put raw UTF-8 data in the RTF stream.

If all you care about is plain ASCII RTF text (but possibly with escaped Unicode characters) then you have two options:

A) Use the ANSI RichEd control + NSD_SetText
nsDialogs::CreateControl "${__NSD_RichEdit_CLASS_20A}" "${__NSD_RichEdit_STYLE}" "${__NSD_RichEdit_EXSTYLE}" 1 1 -2 -2 ""
Pop $9
${NSD_SetText} $9 "{\rtf1 ... " 
B) Set ASCII RTF text (with escaped Unicode codepoints) with a RichEdit v3 (Win2000+/ME) message:
!define /IfNDef /Math EM_SETTEXTEX ${WM_USER} + 97
System::Call 'USER32::SendMessage(p$9,i${EM_SETTEXTEX}, *l0, ms)' "{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0{\b\u54861?\u51652?\u50689?}\par}" 
If you are loading RTF from a file you should use EM_STREAMIN instead, you can find examples by searching this forum.
Endy-kun#
Hey. Thanks for your answer! Tried both of the solutions, both work good enough. Next time I'll have to simply give up on rtf...
Endy-kun#
It seems string passed via SendMessage is restricted to 1024bytes. Anything beyond that is cutoff. Can I make it at least double of that?
Anders#
That is the NSIS string limit.

You can go beyond it but where would you get the string from in the first place?
Endy-kun#
Oh I haven't decided yet because I wasn't sure what is going on. This seems to be good enough:

!define /file variable_vor_sendmessage "resources\myfile.rtf"
System::Call 'USER32::SendMessage(p$9,i${EM_SETTEXTEX}, *l0, ms)' "{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0{\b\u54861?\u51652?\u50689?}\par}" 
P.S.
1024 bytes seems to be plenty, but with all that rtf bloat it really isn't...
Endy-kun#
ouch, obviously that variable in my example goes instead of the text in the 2nd line, I forgot to replace it...
Anders#
I already told you, if you want to load from a file you should use EM_STREAMIN. You can use EM_SETTEXTEX if you allocate some memory and read the file into it (+one zero character) and pass that as "p$mymem" instead of "ms" in my above example.
Endy-kun#
Yes I saw your code that uses EM_STREAMIN with a file you get via FileOpen.
But I have an impression that this works on runtime and I need to supply the actual file I am opening. My example was supposed to be compile-time