#include-once #AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 #include ;; #include #include #include #include #include #include #include #include #include ; Fehlende Konstanten ;https://autoit.de/thread/87954-richedit-verlinken-einer-datei-per-drag-and-drop/?postID=709978#post709978 Global Const $AURL_ENABLEURL = 1 ; füe $EM_AUTOURLDETECT Global Const $AURL_ENABLEDRIVELETTERS = 16 ; für $EM_AUTOURLDETECT Global Const $ECOOP_OR = 2 ; für $EM_SETOPTIONS Global Const $ECO_SELECTIONBAR = 0x01000000 ; für $EM_SETOPTIONS Global Const $ES_NOOLEDRAGDROP = 0x08 ; RichEdit Controlstyle Global Const $SES_HYPERLINKTOOLTIPS = 8 ; für $EM_SETEDITSTYLE Global Const $tagENDROPFILES = $tagNMHDR & ";handle hDrop;long cp;bool fProtected" ; für $EN_DROPFILES ;Global Const $tagDROPFILES = $tagNMHDR & ";handle hDrop;long cp;bool fProtected" #Region FileInstall and other directories Global $g_sAppInit = @AppDataDir & '\GuiRichEditPlus\Init' ;Fileinstall for ex. ;dummy (=SHellexute-) printer and his source If Not FileExists($g_sAppInit) Then DirCreate($g_sAppInit) Global $sPRNexe = $g_sAppInit & '\RTF_SHellExPrint.exe ' Global $g_sAppWork = @AppDataDir & '\GuiRichEditPlus\Work.TMP' If Not FileExists($g_sAppWork) Then DirCreate($g_sAppWork) ;ShellExecute($g_sAppInit Global $g_sAppIcons = @AppDataDir & '\GuiRichEditPlus\Icons' If Not FileExists($g_sAppIcons) Then DirCreate($g_sAppIcons) Global $g_sAppExamples = @AppDataDir & '\GuiRichEditPlus\Examples' If Not FileExists($g_sAppExamples) Then DirCreate($g_sAppExamples) #EndRegion FileInstall and other directories ;eränzende globalen Vars Global $g_sSavePath, $g_sVersNr Global $g_bSaveIt = False ;False: no MasgBox|True: a MsgBox remembers to save Global $g_REDebug = False ;True console output for degbug reasons Global $g_bEncode = False ;False = Spave > '_' |True = Encodes a string to be URL-friendly Practical Encoding (Encode only what is necessary) Global $g_sAllowedExt = 'Au3,txt,rtf,pdf,ico,jpg,png,mp3,mp4' ;Allowed file-extensions autoshellexecute on dblClick ;new func's Func _GUICtrlRichEdit_insertFileLink($hWnd, $sFile, $sDisplay, $bCRLF = False, $bEncode = $g_bEncode) ;autor autoBert $sDisplay = ' ' & $sDisplay & ' ' If $g_REDebug Then ConsoleWrite('insertFileLink: ' & $sFile & @TAB & $sDisplay & @CRLF) If Not FileExists(StringReplace($sFile, '_', ' ')) And _ ;For those people which uses this simplest encoding in main-script (nobody? and me) Not FileExists($sFile) Then Return SetError(1, 1, '') $sFile = StringReplace('File:\' & $sFile, '\', '\\\\') If $bEncode Then $sFile = _URLEncode($sFile) Else ; $sFile = StringReplace($sFile, '_', ' ') EndIf Local $sText Local Const $sbinEnd = '}}' Local Const $sbinLink = '{\field{\*\fldinst{HYPERLINK "' Local Const $sbinDisplay = '{\fldrslt\ul\cf1 ' Local Const $sbinEndLine = '\ul0\cf0}}\f0\fs17 ' Local $sLink = "{\rtf1" & $sbinLink & $sFile & '"' & $sbinEnd & $sbinDisplay & $sDisplay & $sbinEndLine & $sbinEnd & $sbinEnd If $bCRLF Then $sLink &= '\par\par}' & @CRLF Local $iRet = _GUICtrlRichEdit_InsertText($hWnd, $sLink) Local $iExt = @extended If $bCRLF Then _GUICtrlRichEdit_InsertText($hWnd, @CRLF) If $g_REDebug Then ConsoleWrite($sLink & @TAB & $iRet & '|' & $iExt & @CRLF) If $iRet Then Return SetError($iRet, $iExt, $iRet) Else Return SetError($iRet, $iExt, $sLink) EndIf EndFunc ;==>_GUICtrlRichEdit_insertFileLink Func _GUICtrlRichEdit_insertLink($hWnd, $sURL, $sDisplay, $bCRLF = False, $bEncode = $g_bEncode) #cs can be used for all links, if not work for files use _GUICtrlRichEdit_insertFileLink ;autor autoBert #ce $sDisplay = ' ' & $sDisplay & ' ' If $g_REDebug Then ConsoleWrite('insertLink: ' & $sURL & @TAB & $sDisplay & @CRLF) Local Const $aLinks[4] = ['HTTP:', 'FTP:', 'www.', 'HINT:'] Local $sMode = '/\' For $i = 0 To 3 If StringInStr($sURL, $aLinks[$i]) Then $sMode = '\/' Next If $sMode = '\/' Then $sURL = StringReplace($sURL, '\', '/') Else $sURL = StringReplace($sURL, '/', '\') $sURL = StringReplace('File:\' & $sURL, '\', '\\\\') EndIf If $bEncode Then $sURL = _URLEncode($sURL) Else ; $sURL = StringReplace($sURL, '_', ' ') EndIf Local $sText Local Const $sbinEnd = '}}' Local Const $sbinLink = '{\field{\*\fldinst{HYPERLINK "' Local Const $sbinDisplay = '{\fldrslt\ul\cf1' Local Const $sbinEndLine = '\ul0\cf0}}\f0\fs17' Local $sLink = "{\rtf1" & $sbinLink & $sURL & '"' & $sbinEnd & $sbinDisplay & $sDisplay & $sbinEndLine & $sbinEnd & $sbinEnd If $bCRLF Then $sLink &= '\par\par}' & @CRLF Local $iRet = _GUICtrlRichEdit_InsertText($hWnd, $sLink) Local $iExt = @extended If $bCRLF Then _GUICtrlRichEdit_InsertText($hWnd, @CRLF) If $g_REDebug Then ConsoleWrite($sURL & @TAB & $iRet & '|' & $iExt & @CRLF) If $iRet Then Return SetError($iRet, $iExt, $iRet) Else Return SetError($iRet, $iExt, $sURL) EndIf EndFunc ;==>_GUICtrlRichEdit_insertLink Func _GUICtrlRichEdit_GetLink($hWnd, $wParam, $lParam, $bEncode = $g_bEncode) ;autor autoBert If $g_REDebug Then ConsoleWrite('GetFileLink: ' & $wParam & '|' & $lParam & '|' & $g_bEncode & @CRLF) Local $tEnLink, $cpMin, $cpMax, $sLink, $sDisplay, $aSplit $tEnLink = DllStructCreate($tagENLINK, $lParam) $cpMin = DllStructGetData($tEnLink, "cpMin") $cpMax = DllStructGetData($tEnLink, "cpMax") $sLink = _GUICtrlRichEdit_GetTextInRange($hWnd, $cpMin, $cpMax) If $g_REDebug Then ConsoleWrite('Link raw: :' & $sLink & @CRLF) $sLink = StringReplace($sLink, 'File:', '') If $bEncode Then $sLink = _URLDecode($sLink) Else ;$sLink = StringReplace($sLink, '_', ' ') EndIf $sLink = _RemoveTrailingBackslash('\' & $sLink) ;ConsoleWrite('\ Removed: ' & @extended & @CRLF) If $g_REDebug Then ConsoleWrite('link decoded: ' & $sLink & @CRLF) If FileExists($sLink) Then Return SetError(1, 0, $sLink) Else Return SetError(0, 9998, $sLink) EndIf ;If $g_REDebug Then EndFunc ;==>_GUICtrlRichEdit_GetLink Func _RemoveTrailingBackslash($sText) ;needed for _GUICtrlRichEdit_GetFileLink and maybe otherwhere ;autor autoBert Local $iPos, $iReplaced Do $iPos = StringInStr($sText, '\') If $iPos < 2 Then $sText = StringReplace($sText, '\', '', 1) If Not @error Then $iReplaced += 1 EndIf Until $iPos > 1 Return SetError(0, $iReplaced, $sText) EndFunc ;==>_RemoveTrailingBackslash Func _GUICtrlRichEdit_Save($hWnd, $sPath = $g_sSavePath, $bSaveIt = True) ;autor autoBert If Not $bSaveIt Then $bSaveIt = _GUICtrlRichEdit_IsModified($hWnd) ;If _GUICtrlRichEdit_GetLineCount($hWnd) = 0 Then Return SetError(True, 7777, 0) ;not a real error 7777 = nothing to do Local $sRet, $iExt If not $bSaveIt Then If MsgBox(BitOR($MB_ICONQUESTION, $MB_YESNO), 'Save before Exit', 'Without changes are be lost!', 0, $hWnd) = $IDYes Then $bSaveIt = True EndIf If $bSaveIt Then ;include already exiting Filechecking _GUICtrlRichEdit_Deselect($hWnd) $sRet = _GUICtrlRichEdit_StreamToFile($hWnd, $sPath, False, $SFF_PLAINRTF, 1031) ;, BitOR($FO_OVERWRITE, $FO_CREATEPATH,$FO_ANSI )) $iExt = @error Else $sRet = False $iExt = 9999 EndIf ;If $g_REDebug Then ConsoleWrite(@ScriptLineNumber & @TAB & $g_sSavePath & @TAB & 'Saved: ' & $sRet & @TAB & $iExt & @CRLF) Return SetError($sRet, $iExt, $sRet) EndFunc ;==>_GUICtrlRichEdit_Save Func _GUICtrlRichEdit_Print($hWnd, $sPath = $g_sSavePath) ;autor autoBert Local $sRet Local $sRTF_Name = $sPath ;_GetPrintFileName($sPath) ;MsgBox(0, 'Print', $sRTF_Name) _GUICtrlRichEdit_Deselect($hWnd) ;If _GUICtrlRichEdit_GetLineCount($hWnd) = 0 Then Return SetError(True, 7777, 0) ;not a real error 7777 = nothing to do $sRet = _GUICtrlRichEdit_StreamToFile($hWnd, $sPath, False, $SFF_PLAINRTF, 1031) ;, BitOR($FO_OVERWRITE, $FO_CREATEPATH,$FO_ANSI)) If $g_REDebug Then ConsoleWrite(@ScriptLineNumber & ': ' & $sRet & '|' & @error & @CRLF) If @error Then Return SetError(@error, @error, $sRTF_Name) If Not FileExists($sPRNexe) Then MsgBox(BitOR($MB_ICONERROR, $MB_TASKMODAL), 'Print', $sPRNexe & 'not found!', 0, $hWnd) ;_ShowBusy() ;Local $sArchiv = @ScriptDir & '\Archiv' ;ConsoleWrite($sArchiv & @CRLF) Local $sPrint = StringFormat('%s "" "" "Print" @SW_HIDE', $sRTF_Name) Local $iPid = Run($sPRNexe & $sPrint, "", @SW_HIDE) if $g_REDebug Then ConsoleWrite('RTF_SHellExPrint.exe ' & $sPrint & ' Ret: ' & Int($iPid) & '|' & @error & @CRLF) ;#cs While ProcessExists($iPid) Sleep(100) WEnd Return SetError($iPid, 8888, '') ;error code noch "normen" EndFunc ;==>_GUICtrlRichEdit_Print Func _GetPrintFileName($sText) Local $iPos = StringInStr($sText, '\', 0, -1) Local $sRet = StringMid($sText, $iPos + 1) ;$iPos = StringInStr($sRet, '.', 0, -1) $sText = StringReplace($sText, $sRet, '~PRN~' & $sRet) ;MsgBox(64, '', $sText, 20) Return SetError(0, $iPos, $sText) EndFunc ;==>_GetPrintFileName #Region Files from @UEZ Func _GUICtrlRichEdit_InsertBitmap($hWnd, $sFile, $sFormatFunctions = "\", $sBitmapFunctions = "\", $iBgColor = Default) ;coded by UEZ build 2016-02-16 # https://www.autoitscript.com/forum/topic/180635-how-to-insert-picture-to-rich-edit/?do=findComment&comment=1296908 If Not FileExists($sFile) Then Return SetError(0, 0, 1) If Not _WinAPI_IsClassName($hWnd, $__g_sRTFClassName) Then Return SetError(0, 0, 2) _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile($sFile) If @error Then _GDIPlus_Shutdown() Return SetError(0, 0, 3) EndIf Local Const $aDim = _GDIPlus_ImageGetDimension($hImage) Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($aDim[0], $aDim[1]), $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap) If $iBgColor = Default Then $iBgColor = 0xFF000000 + _WinAPI_SwitchColor(_GUICtrlRichEdit_GetBkColor($hWnd)) EndIf _GDIPlus_GraphicsClear($hGfx, $iBgColor) _GDIPlus_GraphicsDrawImageRect($hGfx, $hImage, 0, 0, $aDim[0], $aDim[1]) _GDIPlus_GraphicsDispose($hGfx) Local $binStream = _GDIPlus_StreamImage2BinaryString($hBitmap, "BMP") If @error Then _GDIPlus_ImageDispose($hImage) _GDIPlus_ImageDispose($hBitmap) _GDIPlus_Shutdown() Return SetError(0, 0, 4) EndIf Local $binBmp = StringMid($binStream, 31) Local Const $binRtf = "{\rtf1\viewkind4" & $sFormatFunctions & " {\pict{\*\picprop}" & $sBitmapFunctions & "dibitmap " & $binBmp & "}\par}" ;check out http://www.biblioscape.com/rtf15_spec.htm _GUICtrlRichEdit_AppendText($hWnd, $binRtf) $binStream = 0 $binBmp = 0 _GDIPlus_ImageDispose($hImage) _GDIPlus_ImageDispose($hBitmap) _GDIPlus_Shutdown() Return 1 EndFunc ;==>_GUICtrlRichEdit_InsertBitmap Func _GDIPlus_StreamImage2BinaryString($hBitmap, $sFormat = "JPG", $iQuality = 80, $bSave = False, $sFileName = @ScriptDir & "\Converted.jpg") ;coded by UEZ 2013 build 2014-01-25 (based on the code by Andreik) Local $sImgCLSID, $tGUID, $tParams, $tData Switch $sFormat Case "JPG" $sImgCLSID = _GDIPlus_EncodersGetCLSID($sFormat) $tGUID = _WinAPI_GUIDFromString($sImgCLSID) $tData = DllStructCreate("int Quality") DllStructSetData($tData, "Quality", $iQuality) ;quality 0-100 Local $pData = DllStructGetPtr($tData) $tParams = _GDIPlus_ParamInit(1) _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData) Case "PNG", "BMP", "GIF", "TIF" $sImgCLSID = _GDIPlus_EncodersGetCLSID($sFormat) $tGUID = _WinAPI_GUIDFromString($sImgCLSID) Case Else Return SetError(1, 0, 0) EndSwitch Local $hStream = _WinAPI_CreateStreamOnHGlobal() ;http://msdn.microsoft.com/en-us/library/ms864401.aspx If @error Then Return SetError(2, 0, 0) _GDIPlus_ImageSaveToStream($hBitmap, $hStream, DllStructGetPtr($tGUID), DllStructGetPtr($tParams)) If @error Then Return SetError(3, 0, 0) Local $hMemory = _WinAPI_GetHGlobalFromStream($hStream) ;http://msdn.microsoft.com/en-us/library/aa911736.aspx If @error Then Return SetError(4, 0, 0) Local $iMemSize = _MemGlobalSize($hMemory) If Not $iMemSize Then Return SetError(5, 0, 0) Local $pMem = _MemGlobalLock($hMemory) $tData = DllStructCreate("byte[" & $iMemSize & "]", $pMem) Local $bData = DllStructGetData($tData, 1) _WinAPI_ReleaseStream($hStream) ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221473(v=vs.85).aspx _MemGlobalFree($hMemory) If $bSave Then Local $hFile = FileOpen($sFileName, 18) If @error Then Return SetError(6, 0, $bData) FileWrite($hFile, $bData) FileClose($hFile) EndIf Return $bData EndFunc ;==>_GDIPlus_StreamImage2BinaryString #EndRegion Files from @UEZ #Region Files from Corgano Func _GUICtrlRichEdit_AppendTextEx($RichEdit, $text, $font = "Arial", $color = "000000", $size = 12, $bold = 0, $italic = 0, $strike = 0, $underline = 0) Local $command = "{\rtf1\ansi" Local $r, $g, $b, $ul[9] = ["8", '\ul', '\uldb', '\ulth', '\ulw', '\ulwave', '\uld', '\uldash', '\uldashd'] $text = StringReplace($text, '\', '\\') ;eingefügt autobert If $font <> "" Then $command &= "{\fonttbl\f0\f" & $font & ";}" If $color <> "" Then If StringLen($color) <> 6 And StringLen($color) = 8 Then Return SetError(1) $b = Dec(StringRight($color, 2)) If @error Then SetError(1, 1) $color = StringTrimRight($color, 2) $g = Dec(StringRight($color, 2)) If @error Then SetError(1, 2) $color = StringTrimRight($color, 2) $r = Dec(StringRight($color, 2)) If @error Then SetError(1, 3) If $r + $b + $g > 0 Then $command &= "{\colortbl;\red" & $r & "\green" & $g & "\blue" & $b & ";}\cf1" EndIf EndIf If $size Then $command &= "\fs" & Round($size * 2) & " " If $strike Then $command &= "\strike " If $italic Then $command &= "\i " If $bold Then $command &= "\b " If $underline > 0 And $underline < 9 Then $command &= $ul[$underline] & " " Return _GUICtrlRichEdit_AppendText($RichEdit, $command & StringReplace($text, @CRLF, "\line") & "}") EndFunc ;==>_GUICtrlRichEdit_AppendTextEx Func _GUICtrlRichEdit_InsertTextEx($RichEdit, $text, $font = "Arial", $color = "000000", $size = 12, $bold = 0, $italic = 0, $strike = 0, $underline = 0) #Autor Copy&Paste + Search&Replace from _GUICtrlRichEdit_AppendText Local $command = "{\rtf1\ansi" Local $r, $g, $b, $ul[9] = ["8", '\ul', '\uldb', '\ulth', '\ulw', '\ulwave', '\uld', '\uldash', '\uldashd'] $text = StringReplace($text, '\', '\\') ;eingefügt autobert If $font <> "" Then $command &= "{\fonttbl\f0\f" & $font & ";}" If $color <> "" Then If StringLen($color) <> 6 And StringLen($color) = 8 Then Return SetError(1) $b = Dec(StringRight($color, 2)) If @error Then SetError(1, 1) $color = StringTrimRight($color, 2) $g = Dec(StringRight($color, 2)) If @error Then SetError(1, 2) $color = StringTrimRight($color, 2) $r = Dec(StringRight($color, 2)) If @error Then SetError(1, 3) If $r + $b + $g > 0 Then $command &= "{\colortbl;\red" & $r & "\green" & $g & "\blue" & $b & ";}\cf1" EndIf EndIf If $size Then $command &= "\fs" & Round($size * 2) & " " If $strike Then $command &= "\strike " If $italic Then $command &= "\i " If $bold Then $command &= "\b " If $underline > 0 And $underline < 9 Then $command &= $ul[$underline] & " " Return _GUICtrlRichEdit_InsertText($RichEdit, $command & StringReplace($text, @CRLF, "\line") & "}") EndFunc ;==>_GUICtrlRichEdit_InsertTextEx #EndRegion Files from Corgano