Jump to content

RichEdit UDF


ProgAndy
 Share

Recommended Posts

  • Replies 98
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

I propose the following code for _GUICtrlRichEdit_SetFontName():

Func _GUICtrlRichEdit_SetFontName($hWnd, $hFontName, $iSelec = True)
    Local $tcharformat = DllStructCreate($tagCHARFORMAT2)
    DllStructSetData($tcharformat, 1, DllStructGetSize($tcharformat))   ; cbSize
    DllStructSetData($tcharformat, 2, $CFM_FACE)                                    ; dwMask
    DllStructSetData($tcharformat, 9, $hFontName)                               ; szFaceName
    Local $wParam
    If $iSelec Then
        $wParam = $SCF_SELECTION
    Else
        $wParam = $SCF_ALL
    EndIf
    Return _SendMessage($hWnd, $EM_SETCHARFORMAT, $wParam, DllStructGetPtr($tcharformat))
EndFunc

This is per my reading of MSDN.

The $iSelec change would affect other functions where $iSelec is a parameter.

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

OK, i will do that.

I could also change documentation of this param, that it will only work with the SCF_ constants :)

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

  • 7 months later...
  • 7 months later...

The download link is broken I think.

Anyone have GuiRichEdit.au3 ?

Oh, and are active forms (checkbox or radio) possible in a RichEdit object? Can this be done by using OLE objects?

Edited by nooby
Link to comment
Share on other sites

  • 1 month later...

I don't know how to add JPG,PNG... images to RichEdit as the function 'ReadBmpToRtf' in the example script of '_GUICtrlRichEdit_CanPaste'.

So i use GDIPlus to help me.

$lImage -> path of imagefile

$hRichEdit -> handle of RichEdit

_GUICtrlRichEdit_AppendImage($lImage, $hRichEdit)

_GUICtrlRichEdit_AppendImageEx($lImage, $hRichEdit)

#Include <GDIPlus.au3>
_GDIPlus_Startup()

Func _GUICtrlRichEdit_AppendImage($lImage, $hRichEdit)
    Local $hImage
    If IsPtr($lImage) Or IsInt($lImage) Then
        $hImage = $lImage
    Else
        $hImage = _GDIPlus_ImageLoadFromFile($lImage)
    EndIf
    Local $hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage), _
    $iWidth = _GDIPlus_ImageGetWidth($hImage), _
    $iHeight = _GDIPlus_ImageGetHeight($hImage), _
    $iBitCount = _GDIPlus_ImageGetBitCount($hImage), _
    $DIB_RGB_COLORS = 0, _
    $tBMI = DllStructCreate($tagBITMAPINFO)
    If $iBitCount = 0 Then $iBitCount = 1
    DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4)
    DllStructSetData($tBMI, "Width", $iWidth)
    DllStructSetData($tBMI, "Height", $iHeight)
    DllStructSetData($tBMI, "Planes", 1)
    DllStructSetData($tBMI, "BitCount", $iBitCount)

    Local $hDC = _WinAPI_GetDC(0), _
    $hCDC = _WinAPI_CreateCompatibleDC($hDC), _
    $aDIB = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'ptr', 0, 'ptr', DllStructGetPtr($tBMI), 'uint', $DIB_RGB_COLORS, 'ptr*', 0, 'ptr', 0, 'uint', 0)
    _WinAPI_SelectObject($hCDC, $aDIB[0])
    _WinAPI_GetDIBits($hDC, $hBmp, 0, $iHeight, $aDIB[4], DllStructGetPtr($tBMI), $DIB_RGB_COLORS)

    Local $tBits = DllStructCreate('byte[' & $iWidth * $iHeight * $iBitCount / 8 & ']', $aDIB[4]), _
    $lBuffer = DllStructGetData($tBits, 1)
    $tBits = 0
    _WinAPI_DeleteObject($aDIB[0])
    _WinAPI_DeleteDC($hCDC)
    _WinAPI_ReleaseDC(0, $hDC)
    _WinAPI_DeleteObject($hBmp)
    _GDIPlus_ImageDispose($hImage)

    _GUICtrlRichEdit_AppendText($hRichEdit, _
    '{\rtf1{\pict\wbitmap0\picw' & $iWidth & '\pich' & $iHeight & '\wbmbitspixel' & $iBitCount & '\wbmplanes1\wbmwidthbytes' & $iWidth * 2 & ' ' & _
    StringTrimLeft($lBuffer, 2) & '}}')
EndFunc

Func _GUICtrlRichEdit_AppendImageEx($lImage, $hRichEdit)
    Local $hBitmap
    If IsPtr($lImage) Or IsInt($lImage) Then
        $hBitmap = $lImage
    Else
        $hBitmap = _GDIPlus_BitmapCreateFromFile($lImage)
    EndIf

    Local $iWidth = _GDIPlus_ImageGetWidth($hBitmap), _
    $iHeight = _GDIPlus_ImageGetHeight($hBitmap)

    Local $tBitmapData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $iWidth, $iHeight, $GDIP_ILMREAD, $GDIP_PXF32ARGB), _
    $pScan0 = DllStructGetData($tBitmapData, 'Scan0'), _
    $iStride = DllStructGetData($tBitmapData, 'Stride')

    Local $tBitsData = DllStructCreate('BYTE [' & $iStride * $iHeight & ']', $pScan0)
    $lBitsData = DllStructGetData($tBitsData, 1)
    $tBitsData = 0
    _GDIPlus_BitmapUnlockBits($hBitmap, $tBitmapData)
    If IsString($lImage) Then _GDIPlus_BitmapDispose($hBitmap)

    _GUICtrlRichEdit_AppendText($hRichEdit, _
    '{\rtf1{\pict\wbitmap0\picw' & $iWidth & '\pich' & $iHeight & '\wbmbitspixel32\wbmplanes1\wbmwidthbytes' & $iWidth * 2 & ' ' & _
    StringTrimLeft($lBitsData, 2) & '}}')
EndFunc
Edited by whenBye
Link to comment
Share on other sites

I do not have a better solution since PNG/JPG-images require some quite difficult COM-objects and an activex-control if my memories are correct.

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

  • 3 weeks later...

Hello! You UDF is awesome, but I have one trouble with it.

I'm copying some text with MS Word' tables in RichEdit. Then I need to do search-replace with regular expressions in every text of RichEdit. But tables are crushing into plain text.

Is it possible to do regex-search-replaces in text that includes word tables using your UDF? Thanks.

Edited by Suppir
Link to comment
Share on other sites

I don't think RichEdit includes a RegEx-engine. You have to create something just the same way as you would do it for a normal edit.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

  • 5 months later...
  • 3 years later...
  • 6 months later...
  • Moderators

nyke0,

For some time this RichEdit UDF has been incorporated into the standard AutoIt UDFs - look for the _GUICtrlRichEdit_* functions in the Help file. :)

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

nyke0,

Download the current AutoIt Self Extracting Archive and you will find it inside. :)

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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