Jump to content

How to hide chars in _GUICtrlRichEdit


 Share

Go to solution Solved by ioa747,

Recommended Posts

Hello to all,

i show dropped filepathes in a _GUICtrlRichEdit.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#include <GuiRichEdit.au3>
#include <URLFriendly.au3>
#include <WinAPISys.au3>
#include <Array.au3>
#include <String.au3>

Global Const $ES_NOOLEDRAGDROP = 0x08
Global Const $tagDROPFILES = $tagNMHDR & ";handle hDrop;long cp;bool fProtected"

Global $sSavePath = @ScriptDir & '\Rezeptsammlung.rtf'
Global $sTitle = 'FileDropBox', $oldText, $newText

Global $hGUI = GUICreate($sTitle, 600, 400, -1, 100)
Global $hRichEdit = _GUICtrlRichEdit_Create($hGUI, "", 10, 10, 580, 380, BitOR($ES_NOOLEDRAGDROP, $ES_MULTILINE, $ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))
_GUICtrlRichEdit_AutoDetectURL($hRichEdit, True)
_GUICtrlRichEdit_StreamFromFile($hRichEdit, $sSavePath)
_WinAPI_DragAcceptFiles($hRichEdit)
_GUICtrlRichEdit_SetEventMask($hRichEdit, BitOR($ENM_DROPFILES, $ENM_LINK))
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
WinMove($hGUI, '', @DesktopWidth - 610, @DesktopHeight - 320, 610, 300)
GUISetState()
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Gui_EVENT_CLOSE
            _GUICtrlRichEdit_Deselect($hRichEdit)
            $sSavePath = @ScriptDir & '\Rezeptsammlung.rtf'
            ConsoleWrite($sSavePath & @CRLF)
            _GUICtrlRichEdit_StreamToFile($hRichEdit, $sSavePath)
            _GUICtrlRichEdit_Destroy($hRichEdit)     ; needed unless script crashes
            GUIDelete()
            ExitLoop
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg, $wParam
    Local $hWndFrom, $iCode, $tNMHDR, $aFileList, $tDropFiles, $hDrop, $tEnLink, $cpMin, $cpMax, $tMsgFilter
    ;    Local $hWndFrom, $iCode, $tNMHDR,
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hRichEdit
            Switch $iCode
                Case $EN_DROPFILES
                    ;Droped File Names extrahieren
                    $tDropFiles = DllStructCreate($tagDROPFILES, $lParam)
                    $hDrop = DllStructGetData($tDropFiles, "hDrop")
                    $aFileList = _WinAPI_DragQueryFileEx($hDrop, 0)
                    ;$sFileString = " File:" & _ArrayToString($aFileList, @CRLF & " File:", 1) & " "
                    For $i = 1 To $aFileList[0]
                        _GUICtrlRichEdit_SetSel($hWndFrom, -1, -1)
                        _GUICtrlRichEdit_InsertText($hRichEdit, 'File:\\' & _URLEncode($aFileList[$i]) & @CRLF)
                        ;_GUICtrlRichEdit_InsertText($hRichEdit,   'File: ' & $aFileList[$i] &@CRLF )
                    Next
                    Return 1
                Case $iCode = $EN_LINK
                    $tMsgFilter = DllStructCreate($tagMSGFILTER, $lParam)
                    If DllStructGetData($tMsgFilter, "msg") = $WM_LBUTTONUP Then
                        $tEnLink = DllStructCreate($tagENLINK, $lParam)
                        $cpMin = DllStructGetData($tEnLink, "cpMin")
                        $cpMax = DllStructGetData($tEnLink, "cpMax")
                        $sLink = _URLDecode(StringReplace(_GUICtrlRichEdit_GetTextInRange($hRichEdit, $cpMin, $cpMax), 'File:\\', ''))
                        ConsoleWrite($sLink & @CRLF)
                        If FileExists($sLink) Then ShellExecute($sLink)
                    EndIf
            EndSwitch
    EndSwitch
    Return $Gui_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY


Func WM_SIZE($hWndGUI, $MsgID, $wParam, $lParam)
    Local $iWidth = _WinAPI_LoWord($lParam)
    Local $iHeight = _WinAPI_HiWord($lParam)
    ; _WinAPI_MoveWindow($hRichEdit, 0, 0, $iWidth, $iHeight)
    _WinAPI_MoveWindow($hRichEdit, 4, 4, $iWidth - 8, $iHeight - 8)
    ; Return $hGui_RUNDEFMSG
    Return 0 ; "an application should return zero if it processes this message" (MSDN)
EndFunc   ;==>WM_SIZE

i use _URLEncode() and _URLDecode to get and save correct links. But i don't like to these %20 in the shown filename. How can i insert hidden text. 

Every help is welcome, (auto)Bert

Rezeptsammlung.rtf

Edited by AutoBert
Link to comment
Share on other sites

try this may bee help

;~ File:\\C:\Users\(len)Bert\Downloads\Rezepte\Falafel-Sandwich.pdf
;~ File:\\C:\Users\(len)Bert\Downloads\Rezepte\Erbsen-Kartoffel-Püree%20mit%20pochiertem%20Ei.pdf
Local $Str = "File:\\C:\Users\(len)Bert\Downloads\Rezepte\Erbsen-Kartoffel-Püree%20mit%20pochiertem%20Ei.mp4"


Local $fileName = CharReplace($Str)
MsgBox(4096, "$fileName", $fileName)

;~ or just
$fileName = StringReplace($Str, "%20", "-")
MsgBox(4096, "$fileName", $fileName)


;----------------------------------------------------------------------------------------
Func CharReplace($String) ; Replace %xx escapes
    Local $iPosition, $iChar, $NewString

    $NewString = $String
    While 1
        $iPosition = StringInStr($NewString, "%")
        If $iPosition > 0 Then
            $iChar = StringMid($NewString, $iPosition + 1, 2)
            ConsoleWrite(" -- %" & $iChar & "=" & Chr(Dec($iChar)))
            $NewString = StringReplace($NewString, "%" & $iChar, Chr(Dec($iChar)))
        Else
            ExitLoop
        EndIf
    WEnd

    ConsoleWrite("" & @CRLF)

    $NewString = StringReplace($NewString, "�", "-")
    Return $NewString


EndFunc   ;==>CharReplace
;-------------------------------------------------------------------------------

 

https://www.w3schools.com/tags/ref_urlencode.ASP

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

13 hours ago, ioa747 said:

;~ or just $fileName = StringReplace($Str, "%20", "-")

Nice idea, but the linked filename is wrong.  And as i didn't know is '-' original or encoded, i couldn't decode correct,

;~ File:\\C:\Users\(len)Bert\Downloads\Rezepte\Falafel-Sandwich.pdf
;~ File:\\C:\Users\(len)Bert\Downloads\Rezepte\Erbsen-Kartoffel-Püree%20mit%20pochiertem%20Ei.pdf
Local $Str = "File:\\C:\Users\(len)Bert\Downloads\Rezepte\Erbsen-Kartoffel-Püree%20mit%20pochiertem%20Ei.mp4"


Local $fileName = CharReplace($Str)
MsgBox(4096, "$fileName", $fileName) 

;~ or just
;$fileName = StringReplace($Str, "%20", "-")
ShellExecute($fileName)


;----------------------------------------------------------------------------------------
Func CharReplace($String) ; Replace %xx escapes
    Local $iPosition, $iChar, $NewString

    $NewString = $String
    While 1
        $iPosition = StringInStr($NewString, "%")
        If $iPosition > 0 Then
            $iChar = StringMid($NewString, $iPosition + 1, 2)
            ConsoleWrite(" -- %" & $iChar & "=" & Chr(Dec($iChar)))
            $NewString = StringReplace($NewString, "%" & $iChar, Chr(Dec($iChar)))
        Else
            ExitLoop
        EndIf
    WEnd

    ConsoleWrite("" & @CRLF)

    $NewString = StringReplace($NewString, "�", "-")
    Return $NewString


EndFunc   ;==>CharReplace

i changed encoding: 'space' => '_' and decoding '_' => 'space'. I have no files with '_' in this folder, so no problems. Looks nicer as '%20'' 

 

But i want also hide 'File: \\' '  so i tested:

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


Global Const $ES_NOOLEDRAGDROP = 0x08
Global Const $tagDROPFILES = $tagNMHDR & ";handle hDrop;long cp;bool fProtected"
Global $g_idLblMsg, $g_hRichEdit, $newText, $oldText


Example()

Func Example()
    Local $hGui = GUICreate("RichEdit Get/Set CharColor (v" & @AutoItVersion & ")", 320, 350, -1, -1)
    $g_hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 10, 10, 300, 220, _
            BitOR($ES_NOOLEDRAGDROP, $ES_MULTILINE, $ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))
    $g_idLblMsg = GUICtrlCreateLabel("", 10, 235, 300, 60)
    Local $idBtnNext = GUICtrlCreateButton("Next", 270, 310, 40, 30)
    _GUICtrlRichEdit_AutoDetectURL($g_hRichEdit, True)
    _WinAPI_DragAcceptFiles($g_hRichEdit)
    _GUICtrlRichEdit_SetEventMask($g_hRichEdit, BitOR($ENM_DROPFILES, $ENM_LINK))

    GUISetState(@SW_SHOW)

    _GUICtrlRichEdit_SetText($g_hRichEdit, "File:\\C:\Users\(len)Bert\Downloads\Rezepte\Erbsen-Kartoffel-Püree_mit_pochiertem_Ei.mp4")
    Local $iMsg, $iStep = 0
    While True
        #cs
        $newText = _GUICtrlRichEdit_GetText($g_hRichEdit)
            If $newText <> $oldText Then
                _FriendlyHide()
                $oldText = $newText
            EndIf
        #ce
        $iMsg = GUIGetMsg()
        Select
            Case $iMsg = $GUI_EVENT_CLOSE
                _GUICtrlRichEdit_Destroy($g_hRichEdit)                 ; needed unless script crashes
                ; GUIDelete()   ; is OK too
                Exit
            Case $iMsg = $idBtnNext
                $iStep += 1
                Switch $iStep
                    Case 1
                        Report("1. Initial setting")
                    Case 2
                        Report("Trying to write in white color on white background")
                        Sleep(2000)
                        Report(_FriendlyHide('_'))
                        Report("2. Setting is now")
                    Case 3
                        _GUICtrlRichEdit_SetSel($g_hRichEdit, 1, 5)
                        _GUICtrlRichEdit_SetCharColor($g_hRichEdit, "sys")
                        Report("3. Background of a few characters changed")
                    Case 4
                        _GUICtrlRichEdit_Deselect($g_hRichEdit)
                        ; Stream all text to the Desktop so you can look at settings in Word
                        _GUICtrlRichEdit_StreamToFile($g_hRichEdit, @DesktopDir & "\gcre.rtf")
                        Report("4. Written to file")
                        GUICtrlSetState($idBtnNext, $GUI_DISABLE)
                EndSwitch
        EndSelect
    WEnd
EndFunc   ;==>Example

Func Report($sMsg)
    Local $iColor = _GUICtrlRichEdit_GetCharColor($g_hRichEdit)
    Local $aRet = _ColorGetRGB($iColor)
    $sMsg = $sMsg & @CRLF & @CRLF & $aRet[0] & ";" & $aRet[1] & ";" & $aRet[2] & " Color=0x" & Hex($iColor)
    GUICtrlSetData($g_idLblMsg, $sMsg)
EndFunc   ;==>Report

Func _FriendlyHide($sToHide = 'File:\\')
    Local $iFPosStart, $sCol, $iLen = StringLen($sToHide)
    ;ConsoleWrite($sToHide & ' ' & $iLen & @CRLF)
    If $newText = '' Then $newText = _GUICtrlRichEdit_GetText($g_hRichEdit)
    $iFPosStart = 1
    Do
        $iFPosStart = StringInStr(_GUICtrlRichEdit_GetText($g_hRichEdit), $sToHide, 0, $iFPosStart)
        If $iFPosStart <> 0 Then
            _GUICtrlRichEdit_SetSel($g_hRichEdit, $iFPosStart - 1, $iFPosStart - 1 + $iLen)

            $sCol = 'FFFFFF'
            ConsoleWrite(_GUICtrlRichEdit_SetCharColor($g_hRichEdit, $sCol)& @CRLF)
            $iFPosStart += $iLen
        EndIf
    Until $iFPosStart = 0
    _GUICtrlRichEdit_Deselect($g_hRichEdit)
EndFunc   ;==>_FriendlyHide
;#ce

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg, $wParam
    Local $hWndFrom, $iCode, $tNMHDR, $aFileList, $tDropFiles, $hDrop, $tEnLink, $cpMin, $cpMax, $tMsgFilter
    ;    Local $hWndFrom, $iCode, $tNMHDR,
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $g_hRichEdit
            Switch $iCode
                Case $EN_DROPFILES
                    ;Droped File Names extrahieren
                    $tDropFiles = DllStructCreate($tagDROPFILES, $lParam)
                    $hDrop = DllStructGetData($tDropFiles, "hDrop")
                    $aFileList = _WinAPI_DragQueryFileEx($hDrop, 0)
                    ;$sFileString = " File:" & _ArrayToString($aFileList, @CRLF & " File:", 1) & " "
                    For $i = 1 To $aFileList[0]
                        _GUICtrlRichEdit_SetSel($hWndFrom, -1, -1)
                        _GUICtrlRichEdit_InsertText($g_hRichEdit, 'File:\\' & StringReplace($aFileList[$i], ' ', '_') & @CRLF)
                        ;_GUICtrlRichEdit_InsertText($hRichEdit,   'File: ' & $aFileList[$i] &@CRLF )
                    Next
                    Return 1
                Case $iCode = $EN_LINK
                    $tMsgFilter = DllStructCreate($tagMSGFILTER, $lParam)
                    If DllStructGetData($tMsgFilter, "msg") = $WM_LBUTTONUP Then
                        $tEnLink = DllStructCreate($tagENLINK, $lParam)
                        $cpMin = DllStructGetData($tEnLink, "cpMin")
                        $cpMax = DllStructGetData($tEnLink, "cpMax")
                        $sLink = StringReplace(StringReplace(_GUICtrlRichEdit_GetTextInRange($g_hRichEdit, $cpMin, $cpMax), 'File:\\', ''), '_', ' ')
                        ConsoleWrite($sLink & @CRLF)
                        If FileExists($sLink) Then ShellExecute($sLink)
                    EndIf
            EndSwitch
    EndSwitch
    Return $Gui_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

and i don't know what's wrong in the func _FriendlyHide , i can assign $sCol in Range from '000000' to 'FFFFFF' but nothing char color didn't change.  

Edited by AutoBert
Link to comment
Share on other sites

  • Solution

try it and adjust it  :)

#include <MsgBoxConstants.au3>

FixIt(@ScriptDir & "\Rezeptsammlung.rtf")

;----------------------------------------------------------------------------------------
Func FixIt($FilePath)
    ; Read the current script file into an array using the filepath.
    Local $aArray = FileReadToArray($FilePath)
    Local $iLineCount = @extended
    Local $NewTxt
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "", "There was an error reading the file. @error: " & @error)
    Else
        For $i = 0 To $iLineCount - 1 ; Loop through the array.

            Local $fldrslt_pos = StringInStr($aArray[$i], '{\fldrslt{File:\\\\')

            If $fldrslt_pos > 1 Then
                Local $StringA = StringLeft($aArray[$i], $fldrslt_pos)
                Local $StringB = StringTrimLeft($aArray[$i], $fldrslt_pos)
                ConsoleWrite("A: " & $StringA & @CRLF)
                ConsoleWrite("B: " & $StringB & @CRLF)
                $StringB = StringReplace($StringB, "File:\\\\", "")
                $StringB = StringReplace($StringB, "%20", " ")
                ConsoleWrite(">> " & $StringB & @CRLF & @CRLF)
                $NewTxt &= $StringA & $StringB
            Else
                $NewTxt &= $aArray[$i]
            EndIf
        Next
    EndIf

    Local $hFileOpen = FileOpen($FilePath, 266)
    If $hFileOpen = -1 Then
        Return SetError(1, 0, "")
    EndIf
    FileWrite($hFileOpen, $NewTxt)
    FileClose($hFileOpen)

EndFunc   ;==>FixIt

 

I know that I know nothing

Link to comment
Share on other sites

I  have inserted your Func: FixIt, but as expected it help for the saved files. As i need to show the Links in the GUI i use

_GUICtrlRichEdit_AutoDetectURL($hRichEdit, True)

and so i have to insert each new dropped file with

'File:\\' & StringReplace($aFileList[$i], ' ', '_')

and this is visible until next exit.

Actual script:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#include <GuiRichEdit.au3>
#include <URLFriendly.au3>
#include <WinAPISys.au3>
#include <Array.au3>
#include <String.au3>

Global Const $ES_NOOLEDRAGDROP = 0x08
Global Const $tagDROPFILES = $tagNMHDR & ";handle hDrop;long cp;bool fProtected"

Global $sSavePath = @ScriptDir & '\Rezeptsammlung.rtf'
Global $sTitle = 'FileDropBox', $oldText, $newText

Global $hGUI = GUICreate($sTitle, 600, 400, -1, 100)
Global $hRichEdit = _GUICtrlRichEdit_Create($hGUI, "", 10, 10, 580, 380, BitOR($ES_NOOLEDRAGDROP, $ES_MULTILINE, $ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))
_GUICtrlRichEdit_AutoDetectURL($hRichEdit, True)
FixIt(@ScriptDir & "\Rezeptsammlung.rtf")
_GUICtrlRichEdit_StreamFromFile($hRichEdit, $sSavePath)
_WinAPI_DragAcceptFiles($hRichEdit)
_GUICtrlRichEdit_SetEventMask($hRichEdit, BitOR($ENM_DROPFILES, $ENM_LINK))
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
WinMove($hGUI, '', @DesktopWidth - 610, @DesktopHeight - 320, 610, 300)
GUISetState()
;_AnimateTitle($hGUI, $sTitle, 50, 100)
While 1
    #cs
    $newText = _GUICtrlRichEdit_GetText($hRichEdit)
    If $newText <> $oldText Then
        _FriendlyHide()
        $oldText = $newText
    EndIf
    #ce
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Gui_EVENT_CLOSE
            _GUICtrlRichEdit_Deselect($hRichEdit)
            $sSavePath = @ScriptDir & '\Rezeptsammlung.rtf'
            ConsoleWrite($sSavePath & @CRLF)
            _GUICtrlRichEdit_StreamToFile($hRichEdit, $sSavePath)
            _GUICtrlRichEdit_Destroy($hRichEdit)     ; needed unless script crashes
            GUIDelete()
            ExitLoop
    EndSwitch
WEnd

;#cs
Func _FriendlyHide($sToHide = 'File:\\') ;Parse the richtext for friendly words
    Local $iFPosStart, $sCol, $iLen = StringLen($sToHide)
    ConsoleWrite($sToHide & ' ' & $iLen & @CRLF)
    If $newText = '' Then $newText = _GUICtrlRichEdit_GetText($hRichEdit)
    $iFPosStart = 1
    Do
        $iFPosStart = StringInStr($newText, '%20', 0, $iFPosStart)
        If $iFPosStart <> 0 Then
            _GUICtrlRichEdit_SetSel($hRichEdit, $iFPosStart - 1, $iFPosStart - 1 + $iLen)

            $sCol = '111111'
            _GUICtrlRichEdit_SetCharColor($hRichEdit, $sCol)
            $iFPosStart += $iLen
        EndIf
    Until $iFPosStart = 0
EndFunc   ;==>_FriendlyHide
;#ce

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg, $wParam
    Local $hWndFrom, $iCode, $tNMHDR, $aFileList, $tDropFiles, $hDrop, $tEnLink, $cpMin, $cpMax, $tMsgFilter, $iPos
    ;    Local $hWndFrom, $iCode, $tNMHDR,
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hRichEdit
            Switch $iCode
                Case $EN_DROPFILES
                    ;Droped File Names extrahieren
                    $tDropFiles = DllStructCreate($tagDROPFILES, $lParam)
                    $hDrop = DllStructGetData($tDropFiles, "hDrop")
                    $aFileList = _WinAPI_DragQueryFileEx($hDrop, 0)
                    ;$sFileString = " File:" & _ArrayToString($aFileList, @CRLF & " File:", 1) & " "
                    For $i = 1 To $aFileList[0]
                        _GUICtrlRichEdit_SetSel($hWndFrom, -1, -1)
                        _GUICtrlRichEdit_InsertText($hRichEdit, 'File:\\' & StringReplace($aFileList[$i], ' ', '_')& @CRLF)
                    Next
                    Return 1
                Case $iCode = $EN_LINK
                    ;ConsoleWrite('$EN_LINK' & @CRLF)
                    $tMsgFilter = DllStructCreate($tagMSGFILTER, $lParam)
                    If DllStructGetData($tMsgFilter, "msg") = $WM_LBUTTONUP Then
                        $tEnLink = DllStructCreate($tagENLINK, $lParam)
                        $cpMin = DllStructGetData($tEnLink, "cpMin")
                        $cpMax = DllStructGetData($tEnLink, "cpMax")
                        $sLink = StringReplace(StringReplace(_GUICtrlRichEdit_GetTextInRange($hRichEdit, $cpMin, $cpMax), 'File:\\', ''), '_', ' ')
                        #cs
                        Do
                            ConsoleWrite('Pos: ', $iPos = StringInStr($sLink,':')&@CRLF)
                            If StringLeft($sLink, 1) = '\' Then StringTrimLeft($sLink, 1)
                        Until $iPos = 2
                        #ce
                         ConsoleWrite($sLink & @CRLF)
                        If FileExists($sLink) Then ShellExecute($sLink)
                    EndIf
            EndSwitch
    EndSwitch
    Return $Gui_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY


Func WM_SIZE($hWndGUI, $MsgID, $wParam, $lParam)
    Local $iWidth = _WinAPI_LoWord($lParam)
    Local $iHeight = _WinAPI_HiWord($lParam)
    ; _WinAPI_MoveWindow($hRichEdit, 0, 0, $iWidth, $iHeight)
    _WinAPI_MoveWindow($hRichEdit, 4, 4, $iWidth - 8, $iHeight - 8)
    ; Return $hGui_RUNDEFMSG
    Return 0 ; "an application should return zero if it processes this message" (MSDN)
EndFunc   ;==>WM_SIZE

Func _AnimateTitle($hGUI, $sTitle, $iBuf, $iDelay)
    $sTitle = StringSplit($sTitle, "")
    For $i = $iBuf To 0 Step -1
        WinSetTitle($hGUI, "", _StringRepeat(" ", $i) & $sTitle[1])
        Sleep($iDelay)
    Next
    Local $s
    For $i = 1 To $sTitle[0]
        $s &= $sTitle[$i]
        WinSetTitle($hGUI, "", $s)
        Sleep($iDelay)
    Next
EndFunc   ;==>_AnimateTitle


;----------------------------------------------------------------------------------------
Func FixIt($FilePath)
    ; Read the current script file into an array using the filepath.
    Local $aArray = FileReadToArray($FilePath)
    Local $iLineCount = @extended
    Local $NewTxt
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "", "There was an error reading the file. @error: " & @error)
    Else
        For $i = 0 To $iLineCount - 1 ; Loop through the array.

            Local $fldrslt_pos = StringInStr($aArray[$i], '{\fldrslt{File:\\\\')

            If $fldrslt_pos > 1 Then
                Local $StringA = StringLeft($aArray[$i], $fldrslt_pos)
                Local $StringB = StringTrimLeft($aArray[$i], $fldrslt_pos)
                ConsoleWrite("A: " & $StringA & @CRLF)
                ConsoleWrite("B: " & $StringB & @CRLF)
                $StringB = StringReplace($StringB, "File:\\\\", "")
                $StringB = StringReplace($StringB, "_", " ")
                ConsoleWrite(">> " & $StringB & @CRLF & @CRLF)
                $NewTxt &= $StringA & $StringB
            Else
                $NewTxt &= $aArray[$i]
            EndIf
        Next
    EndIf

    Local $hFileOpen = FileOpen($FilePath, 266)
    If $hFileOpen = -1 Then
        Return SetError(1, 0, "")
    EndIf
    FileWrite($hFileOpen, $NewTxt)
    FileClose($hFileOpen)

EndFunc   ;==>FixIt

 

Link to comment
Share on other sites

This has nothing to do with your script but with the generated .rtf file.

Could be in the end, or even in another script (when the .rtf file was created) ,  it  check the .rtf file and fix the text of the link, and not the link itself

edit:

after experimenter i see thats product .rtf with out escape char

I also noticed that the .rtf has a different code page (if you open the .rtf with the notepad)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#include <GuiRichEdit.au3>
;~ #include <URLFriendly.au3>
#include <WinAPISys.au3>
#include <Array.au3>
#include <String.au3>

Global Const $ES_NOOLEDRAGDROP = 0x08
Global Const $tagDROPFILES = $tagNMHDR & ";handle hDrop;long cp;bool fProtected"

Global $sSavePath = @ScriptDir & '\Rezeptsammlung.rtf'
Global $sTitle = 'FileDropBox', $oldText, $newText

Global $hGUI = GUICreate($sTitle, 600, 400, -1, 100)
Global $hRichEdit = _GUICtrlRichEdit_Create($hGUI, "", 10, 10, 580, 380, BitOR($ES_NOOLEDRAGDROP, $ES_MULTILINE, $ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))
_GUICtrlRichEdit_AutoDetectURL($hRichEdit, True)
;~ FixIt(@ScriptDir & "\Rezeptsammlung.rtf")
_GUICtrlRichEdit_StreamFromFile($hRichEdit, $sSavePath)
_WinAPI_DragAcceptFiles($hRichEdit)
_GUICtrlRichEdit_SetEventMask($hRichEdit, BitOR($ENM_DROPFILES, $ENM_LINK))
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
WinMove($hGUI, '', @DesktopWidth - 610, @DesktopHeight - 320, 610, 300)
GUISetState()
;_AnimateTitle($hGUI, $sTitle, 50, 100)
While 1
    #cs
    $newText = _GUICtrlRichEdit_GetText($hRichEdit)
    If $newText <> $oldText Then
        _FriendlyHide()
        $oldText = $newText
    EndIf
    #ce
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Gui_EVENT_CLOSE
            _GUICtrlRichEdit_Deselect($hRichEdit)
            $sSavePath = @ScriptDir & '\Rezeptsammlung.rtf'
            ConsoleWrite($sSavePath & @CRLF)
            _GUICtrlRichEdit_StreamToFile($hRichEdit, $sSavePath)
            _GUICtrlRichEdit_Destroy($hRichEdit)     ; needed unless script crashes
            GUIDelete()
            ExitLoop
    EndSwitch
WEnd

;#cs
Func _FriendlyHide($sToHide = 'File:\\') ;Parse the richtext for friendly words
    Local $iFPosStart, $sCol, $iLen = StringLen($sToHide)
    ConsoleWrite($sToHide & ' ' & $iLen & @CRLF)
    If $newText = '' Then $newText = _GUICtrlRichEdit_GetText($hRichEdit)
    $iFPosStart = 1
    Do
        $iFPosStart = StringInStr($newText, '%20', 0, $iFPosStart)
        If $iFPosStart <> 0 Then
            _GUICtrlRichEdit_SetSel($hRichEdit, $iFPosStart - 1, $iFPosStart - 1 + $iLen)

            $sCol = '111111'
            _GUICtrlRichEdit_SetCharColor($hRichEdit, $sCol)
            $iFPosStart += $iLen
        EndIf
    Until $iFPosStart = 0
EndFunc   ;==>_FriendlyHide
;#ce

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg, $wParam
    Local $hWndFrom, $iCode, $tNMHDR, $aFileList, $tDropFiles, $hDrop, $tEnLink, $cpMin, $cpMax, $tMsgFilter, $iPos
    ;    Local $hWndFrom, $iCode, $tNMHDR,
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hRichEdit
            Switch $iCode
                Case $EN_DROPFILES
                    ;Droped File Names extrahieren
                    $tDropFiles = DllStructCreate($tagDROPFILES, $lParam)
                    $hDrop = DllStructGetData($tDropFiles, "hDrop")
                    $aFileList = _WinAPI_DragQueryFileEx($hDrop, 0)
                    ;$sFileString = " File:" & _ArrayToString($aFileList, @CRLF & " File:", 1) & " "
                    For $i = 1 To $aFileList[0]
                        _GUICtrlRichEdit_SetSel($hWndFrom, -1, -1)
;~                         _GUICtrlRichEdit_InsertText($hRichEdit, 'File:\\' & StringReplace($aFileList[$i], ' ', '_')& @CRLF)
                        _GUICtrlRichEdit_InsertText($hRichEdit, 'File:\\' & $aFileList[$i] & @CRLF)
                    Next
                    Return 1
                Case $iCode = $EN_LINK
                    ;ConsoleWrite('$EN_LINK' & @CRLF)
                    $tMsgFilter = DllStructCreate($tagMSGFILTER, $lParam)
                    If DllStructGetData($tMsgFilter, "msg") = $WM_LBUTTONUP Then
                        $tEnLink = DllStructCreate($tagENLINK, $lParam)
                        $cpMin = DllStructGetData($tEnLink, "cpMin")
                        $cpMax = DllStructGetData($tEnLink, "cpMax")
;~                         $sLink = StringReplace(StringReplace(_GUICtrlRichEdit_GetTextInRange($hRichEdit, $cpMin, $cpMax), 'File:\\', ''), '_', ' ')
                        $sLink = StringReplace(_GUICtrlRichEdit_GetTextInRange($hRichEdit, $cpMin, $cpMax), 'File:\\', '')
                        #cs
                        Do
                            ConsoleWrite('Pos: ', $iPos = StringInStr($sLink,':')&@CRLF)
                            If StringLeft($sLink, 1) = '\' Then StringTrimLeft($sLink, 1)
                        Until $iPos = 2
                        #ce
                         ConsoleWrite($sLink & @CRLF)
                        If FileExists($sLink) Then ShellExecute($sLink)
                    EndIf
            EndSwitch
    EndSwitch
    Return $Gui_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY


Func WM_SIZE($hWndGUI, $MsgID, $wParam, $lParam)
    Local $iWidth = _WinAPI_LoWord($lParam)
    Local $iHeight = _WinAPI_HiWord($lParam)
    ; _WinAPI_MoveWindow($hRichEdit, 0, 0, $iWidth, $iHeight)
    _WinAPI_MoveWindow($hRichEdit, 4, 4, $iWidth - 8, $iHeight - 8)
    ; Return $hGui_RUNDEFMSG
    Return 0 ; "an application should return zero if it processes this message" (MSDN)
EndFunc   ;==>WM_SIZE

Func _AnimateTitle($hGUI, $sTitle, $iBuf, $iDelay)
    $sTitle = StringSplit($sTitle, "")
    For $i = $iBuf To 0 Step -1
        WinSetTitle($hGUI, "", _StringRepeat(" ", $i) & $sTitle[1])
        Sleep($iDelay)
    Next
    Local $s
    For $i = 1 To $sTitle[0]
        $s &= $sTitle[$i]
        WinSetTitle($hGUI, "", $s)
        Sleep($iDelay)
    Next
EndFunc   ;==>_AnimateTitle

I also found this

https://en.wikipedia.org/wiki/Rich_Text_Format

https://www.arcdev.hu/manuals/standard/rtf/rtfspeci.pdf


I'm sorry for unnecessarily bothering you

needs more research :shocked:

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

On 2/2/2023 at 12:44 AM, AutoBert said:

i don't like to these %20 in the shown filename

The space is definitely not allowed in urls. For a visual 'space' effect you might use the non-breaking space Chr(160) as a workaround
... and BTW forget these useless *code() funcs  :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#include <GuiRichEdit.au3>
#include <WinAPISys.au3>
#include <Array.au3>
#include <String.au3>

Global Const $ES_NOOLEDRAGDROP = 0x08
Global Const $tagDROPFILES = $tagNMHDR & ";handle hDrop;long cp;bool fProtected"

Global $sSavePath = @ScriptDir & '\Rezeptsammlung.txt' ;rtf'
Global $sTitle = 'FileDropBox', $oldText, $newText

Global $hGUI = GUICreate($sTitle, 600, 400, -1, 100)
Global $hRichEdit = _GUICtrlRichEdit_Create($hGUI, "", 10, 10, 580, 380, BitOR($ES_NOOLEDRAGDROP, $ES_MULTILINE, $ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))
_GUICtrlRichEdit_SetEventMask($hRichEdit, BitOR($ENM_DROPFILES, $ENM_LINK))
_GUICtrlRichEdit_AutoDetectURL($hRichEdit, True)
;_GUICtrlRichEdit_StreamFromFile($hRichEdit, $sSavePath)

_GUICtrlRichEdit_SetText($hRichEdit, FileRead($sSavePath))
_WinAPI_DragAcceptFiles($hRichEdit)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
WinMove($hGUI, '', @DesktopWidth - 610, @DesktopHeight - 320, 610, 300)
GUISetState()
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Gui_EVENT_CLOSE
            _GUICtrlRichEdit_Deselect($hRichEdit)
            ConsoleWrite($sSavePath & @CRLF)
           ; _GUICtrlRichEdit_StreamToFile($hRichEdit, $sSavePath)

$f = FileOpen($sSavePath, 8+2+128)
FileWrite($f, _GUICtrlRichEdit_GetText($hRichEdit))
FileClose($f)

            _GUICtrlRichEdit_Destroy($hRichEdit)     ; needed unless script crashes
            GUIDelete()
            ExitLoop
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg, $wParam
    Local $hWndFrom, $iCode, $tNMHDR, $aFileList, $tDropFiles, $hDrop, $tEnLink, $cpMin, $cpMax, $tMsgFilter
    ;    Local $hWndFrom, $iCode, $tNMHDR,
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hRichEdit
            Switch $iCode
                Case $EN_DROPFILES
                    ;Droped File Names extrahieren
                    $tDropFiles = DllStructCreate($tagDROPFILES, $lParam)
                    $hDrop = DllStructGetData($tDropFiles, "hDrop")
                    $aFileList = _WinAPI_DragQueryFileEx($hDrop, 0)
                    ;$sFileString = " File:" & _ArrayToString($aFileList, @CRLF & " File:", 1) & " "
                    For $i = 1 To $aFileList[0]
                        _GUICtrlRichEdit_SetSel($hWndFrom, -1, -1)
                        _GUICtrlRichEdit_InsertText($hRichEdit, 'File:\\' & StringReplace($aFileList[$i], ' ', Chr(160)) & @CRLF)
                    Next
                    Return 1
                Case $iCode = $EN_LINK
                    $tMsgFilter = DllStructCreate($tagMSGFILTER, $lParam)
                    If DllStructGetData($tMsgFilter, "msg") = $WM_LBUTTONUP Then
                        $tEnLink = DllStructCreate($tagENLINK, $lParam)
                        $cpMin = DllStructGetData($tEnLink, "cpMin")
                        $cpMax = DllStructGetData($tEnLink, "cpMax")
                       $sLink = StringReplace(StringReplace(_GUICtrlRichEdit_GetTextInRange($hRichEdit, $cpMin, $cpMax), 'File:\\', ''), Chr(160), ' ')
                        ConsoleWrite($sLink & @CRLF)
                        If FileExists($sLink) Then ShellExecute($sLink)
                    EndIf
            EndSwitch
    EndSwitch
    Return $Gui_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY


Func WM_SIZE($hWndGUI, $MsgID, $wParam, $lParam)
    Local $iWidth = _WinAPI_LoWord($lParam)
    Local $iHeight = _WinAPI_HiWord($lParam)
    ; _WinAPI_MoveWindow($hRichEdit, 0, 0, $iWidth, $iHeight)
    _WinAPI_MoveWindow($hRichEdit, 4, 4, $iWidth - 8, $iHeight - 8)
    ; Return $hGui_RUNDEFMSG
    Return 0 ; "an application should return zero if it processes this message" (MSDN)
EndFunc   ;==>WM_SIZE

 

Edited by mikell
.txt file used instead of .rtf
Link to comment
Share on other sites

3 hours ago, mikell said:

The space is definitely not allowed in urls.

As is drop filenames from my pc with win10 using NTFS-formated disks, they are allowed but the autodetect mode for urls break the links. I use meanwhile the "_" instead of space. 

The non-breaking space Chr(160) also confuses autodect and break the links.

I am meanwhile by other problem after reading

Quote

The equivalent of the following HTML:



<a href="https://www.google.com">Google</a>

for an RTF file is:



{\field{\*\fldinst HYPERLINK "http://www.google.com/"}{\fldrslt Google}}

https://stackoverflow.com/questions/2850575/what-is-the-rtf-syntax-for-a-hyperlink?noredirect=1&lq=1

i try to make funcs: _GUICtrlRichEdit_insertFileLink, _GUICtrlRichEdit_GetFileLink.

The inserting works but not correct. The _Get... must be done when the bugs are found.

These thread is solved. Maybe in a few day's a new thread is opened.

Link to comment
Share on other sites

On 2/3/2023 at 6:35 PM, mikell said:

... and BTW forget these useless *code() funcs  :)

if you mean the \*\ syntax for plain rtftext, yes it isn't nice.

BTW: My script works with RTF and these useless *code, but i didn't understand them really. Trial & error and Copy & paste from the plain rtftext does the job. 

Link to comment
Share on other sites

On 2/2/2023 at 12:44 AM, AutoBert said:

show dropped filepathes in a _GUICtrlRichEdit

I didn't know that you had a UDF in progress :) so I did a simple snippet allowing to drop filepathes in a richedit and get functional links in all cases

BTW as said Andreik in the other thread your script doesn't work for me if the filename contains underscore, plus sign, parenthesis and so on
The only way to solve this would be to use _URLEncode but this means some %** (which you don't like) characters included
BTW#2 for me, to have the $bCRLF = True var working in the _GUICtrlRichEdit_insertFileLink func I must use a little modif

; If $bCRLF Then $sLink &= '\par}' & @CRLF
    Local $iRet = _GUICtrlRichEdit_InsertText($hWnd, $sLink)
    If $bCRLF Then _GUICtrlRichEdit_AppendText($hWnd, @CRLF)

But this is not very important

 

Link to comment
Share on other sites

@mikellthese problems should be solved in https://www.autoitscript.com/forum/applications/core/interface/file/attachment.php?id=73122

6 hours ago, mikell said:

I didn't know that you had a UDF in progress :)

the idea to make a UDF cames later, After getting links with 'linkedfilename' 'displayname' i show cleaned displaynames without filepath and without any encoding. After inserting the 

_SendMessage($g_hRichEdit, $EM_SETEDITSTYLE, $SES_HYPERLINKTOOLTIPS, $SES_HYPERLINKTOOLTIPS)

  i see the complete linkpath as a tootip (for ex. 'File:\C:\Users\(len)Bert\Downloads\Rezepte\Wildsauerbraten mit Knöpfle und Rotkohl.pdf') , a doubleclick on the displayname (for ex. 'Wildsauerbraten mit Knöpfle und Rotkohl.pdf') opens the pdf 'C:\Users\(len)Bert\Downloads\Rezepte\Wildsauerbraten mit Knöpfle und Rotkohl.pdf'

evev when using encoding the displayed name is clean the %20 and others %xx  only annoying in the tooltips (for ex. 'File:\C:\Users\(len)Bert\Downloads\Rezepte\Wildsauerbraten%20mit%20Knöpfle%20und%20Rotkohl.pdf')

Please test and report problems (and also good news) in

 

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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