WINAMP.COM | Forums : Powered by vBulletin version 2.3.9 WINAMP.COM | Forums > Developer Center > NSIS Discussion > RichEdit with nsDialogs?
  Last Thread   Next Thread
Author
Thread Post New Thread    Post A Reply
vbguy
Junior Member

Registered: Jul 2006
From:

RichEdit with nsDialogs?

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

PHP:

nsDialogs
::CreateControl /NOUNLOAD RICHEDIT_CLASS  ${WS_VISIBLE}|${WS_CHILD}|${WS_TABSTOP}|${WS_VSCROLL}|${ES_MULTILINE}|${ES_WANTR
ETURN
} ${__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.

Quick Link | Report this post to a moderator | IP: Logged

vbguy is offline Old Post 03-08-2008 01:04 AM
Click Here to See the Profile for vbguy Click here to Send vbguy a Private Message Find more posts by vbguy Add vbguy to your buddy list Edit/Delete Message Reply w/Quote
Anders
Major Dude

Registered: Jun 2002
From: N/A

RICHEDIT_CLASS is not the real name, try "RICHEDIT" or "RichEdit20A"

__________________
IntOp $PostCount $PostCount + 1

Quick Link | Report this post to a moderator | IP: Logged

Anders is offline Old Post 03-08-2008 08:01 AM
Click Here to See the Profile for Anders Click here to Send Anders a Private Message Visit Anders's homepage! Find more posts by Anders Add Anders to your buddy list Edit/Delete Message Reply w/Quote
vbguy
Junior Member

Registered: Jul 2006
From:

Thanks, RichEdit20A worked.

Quick Link | Report this post to a moderator | IP: Logged

vbguy is offline Old Post 03-08-2008 08:18 AM
Click Here to See the Profile for vbguy Click here to Send vbguy a Private Message Find more posts by vbguy Add vbguy to your buddy list Edit/Delete Message Reply w/Quote
bradharding
Member

Registered: Sep 2003
From:

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.

Quick Link | Report this post to a moderator | IP: Logged

bradharding is offline Old Post 03-11-2008 07:15 AM
Click Here to See the Profile for bradharding Click here to Send bradharding a Private Message Visit bradharding's homepage! Find more posts by bradharding Add bradharding to your buddy list Edit/Delete Message Reply w/Quote
Anders
Major Dude

Registered: Jun 2002
From: N/A

http://forums.winamp.com/showthread...482#post1812482

__________________
IntOp $PostCount $PostCount + 1

Quick Link | Report this post to a moderator | IP: Logged

Anders is offline Old Post 03-11-2008 10:04 AM
Click Here to See the Profile for Anders Click here to Send Anders a Private Message Visit Anders's homepage! Find more posts by Anders Add Anders to your buddy list Edit/Delete Message Reply w/Quote
bradharding
Member

Registered: Sep 2003
From:

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

Quick Link | Report this post to a moderator | IP: Logged

bradharding is offline Old Post 03-11-2008 10:27 AM
Click Here to See the Profile for bradharding Click here to Send bradharding a Private Message Visit bradharding's homepage! Find more posts by bradharding Add bradharding to your buddy list Edit/Delete Message Reply w/Quote
Anders
Major Dude

Registered: Jun 2002
From: N/A

its the same message (http://msdn2.microsoft.com/en-us/li...302(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

Quick Link | Report this post to a moderator | IP: Logged

Anders is offline Old Post 03-11-2008 10:37 AM
Click Here to See the Profile for Anders Click here to Send Anders a Private Message Visit Anders's homepage! Find more posts by Anders Add Anders to your buddy list Edit/Delete Message Reply w/Quote
bradharding
Member

Registered: Sep 2003
From:

Talking

Thanks again! I'll give it a go....

Quick Link | Report this post to a moderator | IP: Logged

bradharding is offline Old Post 03-11-2008 10:45 AM
Click Here to See the Profile for bradharding Click here to Send bradharding a Private Message Visit bradharding's homepage! Find more posts by bradharding Add bradharding to your buddy list Edit/Delete Message Reply w/Quote
vbguy
Junior Member

Registered: Jul 2006
From:

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:

;License textbox (rich text)

nsDialogs::CreateControl /NOUNLOAD "RichEdit20A"   ${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS}|${WS_TABSTOP}|${ES_READONLY}|${WS_V
SCROLL
}|${ES_MULTILINE}|${ES_WANTRETURN} ${WS_EX_STATICEDGE} 0 10u 100% 90u ''

Pop $txtLicense
    
;load the license from file
!insertmacro addLicense

Last edited by vbguy on 03-11-2008 at 02:15 PM

Quick Link | Report this post to a moderator | IP: Logged

vbguy is offline Old Post 03-11-2008 11:51 AM
Click Here to See the Profile for vbguy Click here to Send vbguy a Private Message Find more posts by vbguy Add vbguy to your buddy list Edit/Delete Message Reply w/Quote
bradharding
Member

Registered: Sep 2003
From:

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.

Quick Link | Report this post to a moderator | IP: Logged

bradharding is offline Old Post 03-11-2008 09:36 PM
Click Here to See the Profile for bradharding Click here to Send bradharding a Private Message Visit bradharding's homepage! Find more posts by bradharding Add bradharding to your buddy list Edit/Delete Message Reply w/Quote
vbguy
Junior Member

Registered: Jul 2006
From:

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

PHP:

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:

PHP:

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

Quick Link | Report this post to a moderator | IP: Logged

vbguy is offline Old Post 03-11-2008 09:52 PM
Click Here to See the Profile for vbguy Click here to Send vbguy a Private Message Find more posts by vbguy Add vbguy to your buddy list Edit/Delete Message Reply w/Quote
Anders
Major Dude

Registered: Jun 2002
From: N/A

vbguy: you can't use WM_SETTEXT, it seems to work for some simple rtf files, but not everything

__________________
IntOp $PostCount $PostCount + 1

Quick Link | Report this post to a moderator | IP: Logged

Anders is offline Old Post 03-11-2008 10:01 PM
Click Here to See the Profile for Anders Click here to Send Anders a Private Message Visit Anders's homepage! Find more posts by Anders Add Anders to your buddy list Edit/Delete Message Reply w/Quote
bradharding
Member

Registered: Sep 2003
From:

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?

Quick Link | Report this post to a moderator | IP: Logged

bradharding is offline Old Post 03-11-2008 10:11 PM
Click Here to See the Profile for bradharding Click here to Send bradharding a Private Message Visit bradharding's homepage! Find more posts by bradharding Add bradharding to your buddy list Edit/Delete Message Reply w/Quote
Anders
Major Dude

Registered: Jun 2002
From: N/A

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

Quick Link | Report this post to a moderator | IP: Logged

Anders is offline Old Post 03-11-2008 10:39 PM
Click Here to See the Profile for Anders Click here to Send Anders a Private Message Visit Anders's homepage! Find more posts by Anders Add Anders to your buddy list Edit/Delete Message Reply w/Quote
vbguy
Junior Member

Registered: Jul 2006
From:

quote:
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 on 03-11-2008 at 11:15 PM

Quick Link | Report this post to a moderator | IP: Logged

vbguy is offline Old Post 03-11-2008 10:41 PM
Click Here to See the Profile for vbguy Click here to Send vbguy a Private Message Find more posts by vbguy Add vbguy to your buddy list Edit/Delete Message Reply w/Quote
bradharding
Member

Registered: Sep 2003
From:

Fixed! It's always something simple that's causing the problem isn't it?

All you have to do is use EM_EXLIMITTEXT to set the size of the rich text control!

code:
; Show the License. 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\${GNU_GENERAL_PUBLIC_LICENSE}.rtf" "Resources\${GNU_GENERAL_PUBLIC_LICENSE}.rtf" System::Call "kernel32::CreateFile(t '$PLUGINSDIR\${GNU_GENERAL_PUBLIC_LICENSE}.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" 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 ${EM_EXLIMITTEXT} 0 $1 SendMessage $CONTROL ${WM_SETTEXT} 0 $2 System::Free $2

Quick Link | Report this post to a moderator | IP: Logged

bradharding is offline Old Post 03-11-2008 11:20 PM
Click Here to See the Profile for bradharding Click here to Send bradharding a Private Message Visit bradharding's homepage! Find more posts by bradharding Add bradharding to your buddy list Edit/Delete Message Reply w/Quote
Anders
Major Dude

Registered: Jun 2002
From: N/A

that changes nothing, thats only the length, even a rtf file less than 300bytes will not load, atleast not for me

Attachment: test2.rtf.txt
This has been downloaded 228 time(s).

__________________
IntOp $PostCount $PostCount + 1

Quick Link | Report this post to a moderator | IP: Logged

Anders is offline Old Post 03-11-2008 11:55 PM
Click Here to See the Profile for Anders Click here to Send Anders a Private Message Visit Anders's homepage! Find more posts by Anders Add Anders to your buddy list Edit/Delete Message Reply w/Quote
bradharding
Member

Registered: Sep 2003
From:

That's strange. The RTF file I'm using is about 58Kb. Without sending that EM_EXLIMITTEXT message, it wouldn't display the last quarter of the file. With the message, it displays it fine.

Quick Link | Report this post to a moderator | IP: Logged

bradharding is offline Old Post 03-11-2008 11:59 PM
Click Here to See the Profile for bradharding Click here to Send bradharding a Private Message Visit bradharding's homepage! Find more posts by bradharding Add bradharding to your buddy list Edit/Delete Message Reply w/Quote
vbguy
Junior Member

Registered: Jul 2006
From:

quote:
Originally posted by Anders
that changes nothing, thats only the length, even a rtf file less than 300bytes will not load, atleast not for me


I just tested your file with the WM_SETTEXT method, and it works for me (even without EM_EXLIMITTEXT message).

Thanks, bradharding, for finding that flag.

Quick Link | Report this post to a moderator | IP: Logged

vbguy is offline Old Post 03-12-2008 12:02 AM
Click Here to See the Profile for vbguy Click here to Send vbguy a Private Message Find more posts by vbguy Add vbguy to your buddy list Edit/Delete Message Reply w/Quote
Anders
Major Dude

Registered: Jun 2002
From: N/A

alright, I think this works

code:
!define SF_RTF 2 !define EM_STREAMIN 1097 !define EM_EXLIMITTEXT 1077 Function lic FileOpen $4 "test.rtf" r FindWindow $0 "#32770" "" $HWNDPARENT GetDlgItem $0 $0 1000 SendMessage $0 ${EM_EXLIMITTEXT} 0 0x7fffffff System::Get /NoUnload "(i, i .R0, i .R1, i .R2) iss" Pop $2 System::Call /NoUnload "*(i 0, i 0, k r2) i .r3" System::Call /NoUnload "user32::SendMessage(i r0, i ${EM_STREAMIN}, i ${SF_RTF}, i r3) i.s" loop: Pop $0 StrCmp $0 "callback1" 0 done System::Call /NoUnload "kernel32::ReadFile(i $4, i $R0, i $R1, i $R2, i 0)" Push 0 # callback's return value System::Call /NoUnload "$2" goto loop done: System::Free $2 System::Free $3 FileClose $4 FunctionEnd

the code is a little bit longer than the WM_SETTEXT code, but it does not alloc the whole file at once, and does not know or care about the filesize at all

__________________
IntOp $PostCount $PostCount + 1

Quick Link | Report this post to a moderator | IP: Logged

Anders is offline Old Post 03-12-2008 12:30 AM
Click Here to See the Profile for Anders Click here to Send Anders a Private Message Visit Anders's homepage! Find more posts by Anders Add Anders to your buddy list Edit/Delete Message Reply w/Quote
vbguy
Junior Member

Registered: Jul 2006
From:

quote:
Originally posted by Anders
alright, I think this works

the code is a little bit longer than the WM_SETTEXT code, but it does not alloc the whole file at once, and does not know or care about the filesize at all


Sweet. Now that all this is known, maybe someone can submit it for inclusion into the nsDialogs.nsh header.

Quick Link | Report this post to a moderator | IP: Logged

vbguy is offline Old Post 03-12-2008 01:13 AM
Click Here to See the Profile for vbguy Click here to Send vbguy a Private Message Find more posts by vbguy Add vbguy to your buddy list Edit/Delete Message Reply w/Quote
kichik
M.I.A.
[NSIS Dev, Mod]

Registered: Oct 2001
From: Israel

You should.

__________________
NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius

Quick Link | Report this post to a moderator | IP: Logged

kichik is offline Old Post 03-16-2008 07:37 PM
Click Here to See the Profile for kichik Click here to Send kichik a Private Message Visit kichik's homepage! Find more posts by kichik Add kichik to your buddy list Edit/Delete Message Reply w/Quote
vbguy
Junior Member

Registered: Jul 2006
From:

quote:
Originally posted by kichik
You should.


I meant to include it as a built-in part of the nsDialogs. I could include it with my own nsDialogs.nsh file, but I'd just overwrite it the next time I updated to a newer official version.

Also, I think the community would benefit by having all the RichEdit particulars figured out in the nsDialogs.nsh.

I didn't mean to belittle your work.

If you were implying that I should do the work, then I would be glad to. I have just a couple of questions, though:

1. On what version of nsDialogs.nsh do I base my work? The latest svn version, or the latest "stable" version?

2. In what form do I post the results? A patch file or the full file?

3. Where do I post the results? Here, or is there another NSIS developer forum?

Quick Link | Report this post to a moderator | IP: Logged

vbguy is offline Old Post 03-17-2008 07:10 PM
Click Here to See the Profile for vbguy Click here to Send vbguy a Private Message Find more posts by vbguy Add vbguy to your buddy list Edit/Delete Message Reply w/Quote
kichik
M.I.A.
[NSIS Dev, Mod]

Registered: Oct 2001
From: Israel

I misread it as "maybe I should submit it for inclusion" and wanted to encourage you to do so by letting you know I will include it in the next version.

If you wish to make the change and submit it, you should base your work on the latest nsDialogs.nsh from Subversion. But even if you don't, this is not a fundamental change, so a patch for 2.35's version won't be hard to apply.

The best way is to submit a patch to patch tracker, but a full file would work as well.

__________________
NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius

Quick Link | Report this post to a moderator | IP: Logged

kichik is offline Old Post 03-17-2008 07:19 PM
Click Here to See the Profile for kichik Click here to Send kichik a Private Message Visit kichik's homepage! Find more posts by kichik Add kichik to your buddy list Edit/Delete Message Reply w/Quote
grundic
Junior Member

Registered: May 2009
From:

I made a test file:

PHP:

!include nsDialogs.nsh
!include LogicLib.nsh


OutFile test
.exe

Var Dialog
Var txtLicense


Page custom nsDialog

Function nsDialog
        nsDialogs
::Create 1018
    Pop $Dialog

    
${If} $Dialog == error
        Abort
    
${EndIf}
    
    
nsDialogs::CreateControl /NOUNLOAD RichEdit20A   ${WS_VISIBLE}|${WS_CHILD}|${WS_TABSTOP}|${WS_VSCROLL}|${ES_MULTILINE}|${ES_WANTR
ETURN
} ${__NSD_Text_EXSTYLE} 0 10u 100% 90u ''
        
Pop $txtLicense

        call lic
    nsDialogs
::Show
    
    
FunctionEnd

!define SF_RTF 2
!define EM_STREAMIN 1097
;!define EM_EXLIMITTEXT 1077
Function lic
         MessageBox MB_OK
"Inside function"
    
FileOpen $4 "test.rtf" r
    FindWindow
$0 "#32770" "" $HWNDPARENT
    GetDlgItem
$0 $0 1000
    SendMessage
$0 ${EM_EXLIMITTEXT} 0 0x7fffffff
    System
::Get /NoUnload "(i, i .R0, i .R1, i .R2) iss"
    
Pop $2
    System
::Call /NoUnload "*(i 0, i 0, k r2) i .r3"
    
System::Call /NoUnload "user32::SendMessage(i r0, i ${EM_STREAMIN}, i ${SF_RTF}, i r3) i.s"
    
loop:
        
Pop $0
        StrCmp
$0 "callback1" 0 done
        System
::Call /NoUnload "kernel32::ReadFile(i $4, i $R0, i $R1, i $R2, i 0)"
        
Push 0 # callback's return value
        
System::Call /NoUnload "$2"
        
goto loop
    done
:
    
System::Free $2
    System
::Free $3
    FileClose
$4
FunctionEnd

Section
       
SectionEnd



But nothing was shown in RichEdit. What am I doing wrong?
Also, anybody say how can I show custom text in RichEdit without using RTF file?

Thanks in advance!

Quick Link | Report this post to a moderator | IP: Logged

grundic is offline Old Post 05-12-2009 11:45 AM
Click Here to See the Profile for grundic Click here to Send grundic a Private Message Click Here to Email grundic Find more posts by grundic Add grundic to your buddy list Edit/Delete Message Reply w/Quote
grundic
Junior Member

Registered: May 2009
From:

Okay, I find a way to display RTF with aforementioned code. But now I got another problem: if I go back to page with custom RTF, then nothing is shown is RichEdit. I've found, that

PHP:

Pop
$0 ; <--- HERE!
        
MessageBox MB_OK $0
        StrCmp
$0 "callback1" 0 done
        System
::Call /NoUnload "kernel32::ReadFile(i $4, i $R0, i $R1, i $R2, i 0)"
        
Push 0 # callback's return value
        
System::Call /NoUnload "$2"
        
goto loop



Pop $0 returns 0

Can anybody help me to solve this issue?

Quick Link | Report this post to a moderator | IP: Logged

grundic is offline Old Post 05-22-2009 10:36 AM
Click Here to See the Profile for grundic Click here to Send grundic a Private Message Click Here to Email grundic Find more posts by grundic Add grundic to your buddy list Edit/Delete Message Reply w/Quote
grundic
Junior Member

Registered: May 2009
From:

I've found an other way to solve my problem

PHP:

...
...
...

Page custom CreatePageFinish

...
...
...

Function
CreatePageFinish

   
    nsDialogs
::Create /NOUNLOAD 1018
    Pop $DIALOG

    nsDialogs
::CreateControl /NOUNLOAD RichEdit20A   ${WS_VISIBLE}|${WS_CHILD}|${WS_TABSTOP}|${WS_VSCROLL}|${ES_MULTILINE}|${ES_WANTR
ETURN
}|${ES_READONLY} ${__NSD_Text_EXSTYLE} 0 0 100% 140 ''
    
Pop $RICHEDIT

    CustomLicense
::LoadFile "License.rtf" $RICHEDIT
    
;Call LoadLicense
            
    
### Radiobuton: auto install ###
    
${NSD_CreateRadioButton} 1 180 450 15 "Qick insall"
    
Pop $RADIO_AUTO
    
${NSD_CreateRadioButton} 1 210 450 15 "Custom install"
    
Pop $RADIO_MANUAL

    nsDialogs
::Show
FunctionEnd



Hope, it'll help someone.
Here is link to the plugin: URL submitted by user.

Quick Link | Report this post to a moderator | IP: Logged

grundic is offline Old Post 05-23-2009 08:01 AM
Click Here to See the Profile for grundic Click here to Send grundic a Private Message Click Here to Email grundic Find more posts by grundic Add grundic to your buddy list Edit/Delete Message Reply w/Quote
Animaether
Major Dude

Registered: Jun 2001
From:

for what it's worth - I think the actual problem is that callback1 rolls over to callback2 the next time your page is generated.

I'm not sure if there's an appropriate method to prevent that, but you can always make the "callback1" check more dynamic by Pop'ing it into a var first, then Push'ing it back onto the stack, and then compare against that var.

Here's a function + macro + define (I'll post to wiki after review from smarter people):

code:
/* Check if LoadRTFincluded is defined so that LoadRTF can't be included twice */ !ifndef LoadRTFincluded /* Defines used by LoadRTF */ !ifndef SF_RTF !define SF_RTF 2 !endif !ifndef EM_STREAMIN !define EM_STREAMIN 1097 !endif !ifndef EM_EXLIMITTEXT !define EM_EXLIMITTEXT 1077 !endif /* LoadRTF Main Function Inserted via macro for Installer vs Uninstaller Loads an RTF file into a RichEdit20a control Thanks to Anders for all the heavy work Define/Macro/Functionfication and a CallbackN tweak by Animaether Usage: Push Path-to-RTF-file Push HWND-of-RichEdit20A-control Call LoadRTF -or for uninstallers- Call un.LoadRTF */ !macro LoadRTFfunc Un Function ${Un}LoadRTF ; RichEdit20A.hwnd RTFilePath.string Exch $0 ; $0 RTFilePath.string ; $0 = RichEdit20A.hwnd Exch ; RTFilePath.string $0 Exch $1 ; $1 $0 ; $1 = RTFilePath.string Push $2 ; $2 $1 $0 ; $2 : Callback address Push $3 ; $3 $2 $1 $0 ; $3 : EDITSTREAM structure Push $4 ; $4 $3 $2 $1 $0 ; $4 : callbackN identifier from System plugin to check against Push $R0 ; $R0 $4 $3 $2 $1 $0 ; $R0 : Buffer that receives data from ReadFile() Push $R1 ; $R1 $R0 $4 $3 $@ $1 $0 ; $R1 : Maximum number of bytes to read using ReadFile() Push $R2 ; $R2 $R1 $R0 $4 $3 $@ $1 $0 ; $R2 : Number of bytes actually read using ReadFile() SendMessage $0 ${EM_EXLIMITTEXT} 0 0x7fffffff System::Get "(i, i .R0, i .R1, i .R2) iss" Pop $2 System::Call "*(i 0, i 0, k r2) i .r3" System::Call "user32::SendMessage(i r0, i ${EM_STREAMIN}, i ${SF_RTF}, i r3) i.s" Pop $4 Push $4 ClearErrors FileOpen $1 "$1" r ; $1 = RTFile.handle _loop: Pop $0 ; $0 = callbackN identifier from System plugin. StrCmp $0 "$4" 0 _done ; check if System plugin's callbackN matches the stored callbackN System::Call "kernel32::ReadFile(i $1, i $R0, i $R1, i $R2, i 0)" Push 0 # callback's return value System::Call "$2" goto _loop _done: FileClose $1 System::Free $3 System::Free $2 ; $R2 $R1 $R0 $4 $3 $2 $1 $0 Pop $R2 ; $R1 $R0 $4 $3 $2 $1 $0 Pop $R1 ; $R0 $4 $3 $2 $1 $0 Pop $R0 ; $4 $3 $2 $1 $0 Pop $4 ; $3 $2 $1 $0 Pop $3 ; $2 $1 $0 Pop $2 ; $1 $0 Pop $1 ; $0 Pop $0 ; -empty- FunctionEnd !macroend !insertmacro LoadRTFfunc "" !insertmacro LoadRTFfunc "un." /* LoadRTF Ease of use functions. Simplifies usage of LoadRTF. Usage: ${LoadRTF} "Path-to-RTF-file" HWND-of-RichEdit20A-control -or for uninstallers- ${un.LoadRTF} "Path-to-RTF-file" HWND-of-RichEdit20A-control */ !macro LoadRTF file hwnd Push "${file}" Push ${hwnd} Call LoadRTF !macroend !define LoadRTF `!insertmacro LoadRTF` !macro un.LoadRTF file hwnd Push "${file}" Push ${hwnd} Call un.LoadRTF !macroend !define un.LoadRTF `!insertmacro LoadRTF.un` /* define LoadRTFincluded so that LoadRTF can't be included twice */ !define LoadRTFincluded !endif


Usage is pretty simple. Presuming you have the above saved in "LoadRTF.nsh":
code:
!addplugindir "." !addincludedir "." !include "nsDialogs.nsh" !include "winmessages.nsh" !include "logiclib.nsh" !include "MUI2.nsh" !include "LoadRTF.nsh" OutFile "test.exe" var dialog var hwnd var null Page custom null ; just for testing Page custom test Page custom null ; just for testing Function .onInit InitPluginsDir FunctionEnd var RichEditControl Function test nsDialogs::Create 1018 Pop $dialog nsDialogs::CreateControl "RichEdit20A" \ "${DEFAULT_STYLES}|${WS_TABSTOP}|${WS_VSCROLL}|${ES_MULTILINE}|${ES_READONLY}" \ "${WS_EX_WINDOWEDGE}|${WS_EX_CLIENTEDGE}" \ 0 0 100% 100% "" Pop $RichEditControl SetOutPath "$PLUGINSDIR" File "helloworld.rtf" ${LoadRTF} "$PLUGINSDIR\helloworld.rtf" $RichEditControl nsDialogs::Show FunctionEnd Function null nsDialogs::Create 1018 Pop $dialog ${NSD_CreateLabel} 0 0 100% 8% "Dummy page." Pop $null nsDialogs::Show FunctionEnd Section SectionEnd


*crosses fingers*

Quick Link | Report this post to a moderator | IP: Logged

Animaether is offline Old Post 05-23-2009 08:50 PM
Click Here to See the Profile for Animaether Click here to Send Animaether a Private Message Find more posts by Animaether Add Animaether to your buddy list Edit/Delete Message Reply w/Quote
grundic
Junior Member

Registered: May 2009
From:

I've found more easy way (see my next post) to fix probkem with RTF.
But thanks anyway

Quick Link | Report this post to a moderator | IP: Logged

grundic is offline Old Post 05-25-2009 09:53 AM
Click Here to See the Profile for grundic Click here to Send grundic a Private Message Click Here to Email grundic Find more posts by grundic Add grundic to your buddy list Edit/Delete Message Reply w/Quote
Animaether
Major Dude

Registered: Jun 2001
From:

I know - it's just there for completeness sake and for those who can't, or don't want to, rely on plugins

Quick Link | Report this post to a moderator | IP: Logged

Animaether is offline Old Post 05-25-2009 11:14 AM
Click Here to See the Profile for Animaether Click here to Send Animaether a Private Message Find more posts by Animaether Add Animaether to your buddy list Edit/Delete Message Reply w/Quote
All times are GMT. The time now is 09:30 PM. Post New Thread    Post A Reply
  Last Thread   Next Thread
WINAMP.COM | Forums : Powered by vBulletin version 2.3.9 WINAMP.COM | Forums > Developer Center > NSIS Discussion > RichEdit with nsDialogs?
Show Printable Version
 | 
Email this Page
 | 
Subscribe to this Thread

Forum Jump:
 

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is off
vB code is ON
Smilies are ON
[IMG] code is ON