Jump to content

Recommended Posts

Posted (edited)

Today I get an issue with _GUICtrlRichEdit_StreamFromFile  function.

 

#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    Local $hGui, $iMsg, $idBtnNext, $iStep = 0, $idLblMsg, $hRichEdit
    $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")", 320, 350, -1, -1)
    $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, _
            BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    $idLblMsg = GUICtrlCreateLabel("", 10, 235, 300, 60)
    $idBtnNext = GUICtrlCreateButton("Next", 270, 310, 40, 30)
    GUISetState(@SW_SHOW)

    _GUICtrlRichEdit_StreamFromFile($hRichEdit, @ScriptDir & "\wzor.rtf")
    While True
        $iMsg = GUIGetMsg()
        Select
            Case $iMsg = $GUI_EVENT_CLOSE
                _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes
                ; GUIDelete()   ; is OK too
                Exit
        EndSelect
    WEnd
EndFunc   ;==>Example

as this function load my RTF file as:

  Quote

??????????????????????????????????????????????????????????????4????????????????????‰??????

 

When I made some further test with:
 

MsgBox(0, '', FileGetEncoding(@scriptdir & '\wzor.rtf'))

Then I get 1024 == $FO_UTF16_LE_NOBOM (1024) = Use Unicode UTF16 Little Endian (without BOM) reading and writing mode.
 

So I look inside

_GUICtrlRichEdit_StreamFromFile()

Then I must change this:

$hFile = FileOpen($sFileSpec, $FO_READ )

to

$hFile = FileOpen($sFileSpec, $FO_READ  + $FO_UTF8 )

 

And it start to works correctly (in my case).

 

wzor.rtf

Edited by Melba23
Amended title

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Moderators
Posted

mLipok,

How about a less dramatic title? I expect better from someone with your experience.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

That's odd: if the file encoding is indeed UTF16-LE, why open it in UTF8 mode? And how can this mode work at all in this case?

Looks like there's another glitch in either FileGetEncoding or FileOpen.

  Reveal hidden contents

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted

I guess it could be changes that Jon made to FileOpen().

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Maybe he reused code parts from IPB v4.* :evil:

  Reveal hidden contents

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted (edited)
  On 7/13/2015 at 12:28 PM, Melba23 said:

mLipok,

How about a less dramatic title? I expect better from someone with your experience.

M23

Excuse Me.
I realize that sometimes I'm too few diplomatic.

 

EDIT:
But as you remember I used a Question Mark in my thread title
.

EDIT2:
I promise to pay more attention to the way of expression.

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Moderators
Posted

mLipok,

How did you save the file you tried to read? When I save the file from within the script, clear the RichEdit and then re-read the file it works without problem:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiRichEdit.au3>

$sFile = @ScriptDir & "\Test.rtf"

$hGui = GUICreate("Test", 500, 500)
$hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test to show mLipok that it works and there is no bug.", 10, 10, 480, 300, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
$cSave = GUICtrlCreateButton("Save", 10, 460, 80, 30)
$cRead = GUICtrlCreateButton("Read", 150, 460, 80, 30)
GUICtrlSetState($cRead, $GUI_DISABLE)

GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $cSave

            _GUICtrlRichEdit_StreamToFile($hRichEdit, $sFile)
            _GUICtrlRichEdit_SetSel($hRichEdit, 0, -1)
            _GUICtrlRichEdit_ReplaceText($hRichEdit, "")
            GUICtrlSetState($cRead, $GUI_ENABLE)
        Case $cRead

            _GUICtrlRichEdit_StreamFromFile($hRichEdit, $sFile)
        Case $GUI_EVENT_CLOSE
            _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes
            Exit
    EndSwitch
WEnd

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

It was long time age when I create this file.
It was made by Copy Paste from some other app (old TxTextcontrol embended in some CRM system) to Wordpad .

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

hmm...

I made further test.

First I open WordPad and made  test.rtf (EDIT: I just type some Polish diacratic characters to the empty document and save them)

After that I make this following testing script:

#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    Local $hGui, $iMsg, $idBtnNext, $iStep = 0, $idLblMsg, $hRichEdit
    $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")", 320, 350, -1, -1)
    $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, _
            BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    $idLblMsg = GUICtrlCreateLabel("", 10, 235, 300, 60)
    $idBtnNext = GUICtrlCreateButton("Next", 270, 310, 40, 30)
    GUISetState(@SW_SHOW)

    Local $sRTF_FileFullPath = @ScriptDir & "\test.rtf"
    MsgBox(0, '', FileGetEncoding($sRTF_FileFullPath))
    _GUICtrlRichEdit_StreamFromFile($hRichEdit, $sRTF_FileFullPath)
    While True
        $iMsg = GUIGetMsg()
        Select
            Case $iMsg = $GUI_EVENT_CLOSE
                ExitLoop
        EndSelect
    WEnd


;~  Local $hFile = FileOpen($sRTF_FileFullPath, $fo_READ + $FO_UTF8)
    Local $hFile = FileOpen($sRTF_FileFullPath, $fo_READ + $FO_UTF8_NOBOM )
    Local $sRTFContent = FileRead($hFile)
    FileClose($hFile)
    MsgBox(0, '', $sRTFContent)

    _GUICtrlRichEdit_StreamFromVar($hRichEdit, $sRTFContent)
    While True
        $iMsg = GUIGetMsg()
        Select
            Case $iMsg = $GUI_EVENT_CLOSE
                _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes
                ; GUIDelete()   ; is OK too
                ExitLoop
        EndSelect
    WEnd

EndFunc   ;==>Example

 

As you can see 

MsgBox(0, '', FileGetEncoding($sRTF_FileFullPath))

is recognized as $FO_BINARY (16)

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Administrators
Posted (edited)

Sublime Text opens that as binary as well. It's because it has a null at the end of it I think.

7b5c 7274 6631 5c61 6e73 695c 616e 7369
6370 6731 3235 305c 6465 6666 305c 6465
666c 616e 6731 3034 357b 5c66 6f6e 7474
626c 7b5c 6630 5c66 6e69 6c5c 6663 6861
7273 6574 3233 3820 4361 6c69 6272 693b
7d7b 5c66 315c 666e 696c 5c66 6368 6172
7365 7430 2043 616c 6962 7269 3b7d 7d0d
0a7b 5c2a 5c67 656e 6572 6174 6f72 204d
7366 7465 6469 7420 352e 3431 2e32 312e
3235 3130 3b7d 5c76 6965 776b 696e 6434
5c75 6331 5c70 6172 645c 7361 3230 305c
736c 3237 365c 736c 6d75 6c74 315c 6630
5c66 7332 325c 2762 395c 2739 635c 2765
365c 2765 615c 2739 635c 2762 665c 2766
335c 2762 335c 2766 315c 6c61 6e67 3130
3333 5c66 315c 7061 720d 0a7d 0d0a 00

If that UDF is always designed to read just rtf files it probably needs a similar modification from the first post to ensure it reads in UTF8_NOBOM

Edited by Jon

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...