#include-once #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" ;eränzende globalen Vars Global $g_sSavePath Global $g_bSaveIt = False ;new func's Func _GUICtrlRichEdit_insertFileLink($hWnd, $sFile, $sDisplay, $bCRLF = False) ;autor autoBert If Not FileExists(StringReplace($sFile, '_', ' ')) Then Return SetError(1, 1, '') $sFile = StringReplace('File:\' & $sFile, '\', '\\\\') $sDisplay = StringReplace($sDisplay, '_', ' ') ConsoleWrite($sFile & @TAB & $sDisplay & @CRLF) 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}' & @CRLF Local $iRet = _GUICtrlRichEdit_InsertText($hWnd, $sLink) Local $iExt = @extended ConsoleWrite($sLink & @TAB & $iRet & '|' & $iExt & @CRLF) _GUICtrlRichEdit_StreamToVar($hWnd, $sText) ConsoleWrite($sText) If $iRet Then Return SetError($iRet, $iExt, $iRet) Else Return SetError($iRet, $iExt, $sLink) EndIf EndFunc ;==>_GUICtrlRichEdit_insertFileLink Func _GUICtrlRichEdit_GetFileLink($hWnd, $wParam, $lParam, $sRepl = '') ;autor autoBert Local $tEnLink, $cpMin, $cpMax, $sLink, $sDisplay, $aSplit $tEnLink = DllStructCreate($tagENLINK, $lParam) $cpMin = DllStructGetData($tEnLink, "cpMin") $cpMax = DllStructGetData($tEnLink, "cpMax") $sLink = StringReplace(StringReplace(_GUICtrlRichEdit_GetTextInRange($hWnd, $cpMin, $cpMax), 'File:', ''), '_', ' ') $sLink = _RemoveTrailingBackslash('\' & $sLink) ;ConsoleWrite('\ Removed: ' & @extended & @CRLF) ;ConsoleWrite($sLink & @CRLF) If FileExists($sLink) Then Return SetError(1, 0, $sLink) Else Return SetError(0, 9998, $sLink) EndIf EndFunc ;==>_GUICtrlRichEdit_GetFileLink 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 = $g_bSaveIt) ;autor autoBert Local $sRet, $iExt If $bSaveIt = False Then If MsgBox(BitOR($MB_ICONQUESTION, $MB_YESNO), 'Save before Exit?', 'Without changes are be lost!') = $IDYes Then $bSaveIt = True EndIf If $bSaveIt Then $sRet = _GUICtrlRichEdit_StreamToFile($hWnd, $sPath, False, $SFF_PLAINRTF) ; , 0, BitOR($FO_OVERWRITE, $FO_CREATEPATH, $FO_UTF16_LE) $iExt = @error Else $sRet = $bSaveIt $iExt = 9999 EndIf ConsoleWrite($g_sSavePath & @TAB & 'Saved: ' & $sRet & @TAB & $iExt & @CRLF) Return SetError($sRet, $iExt, $sRet) EndFunc ;==>_GUICtrlRichEdit_Save 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