Jump to content

RichText Control, 31 functions!


Recommended Posts

Hi,

I composed this UDF while I was working on a project for James. Basicly because there were no UDF containing all functions.

So I took some functions from every corner of this forum, created some myself, and... Tadaaa!

Functions: (quite a view)

RichText_Create(ByRef $h_Gui, $x, $y, $width, $height, $v_styles = $DEFAULT_RICHTEXT_STYLE, $v_exstyles = $WS_EX_CLIENTEDGE)
 RichText_SetText($hRichText, $s_Text = "")
 RichText_InsertText($hRichText, $s_Text = "")
 RichText_AppendText($hRichText, $s_Text = "")
 RichText_GetText($hRichText, $Method=$RICHTEXT_ALL)
 RichText_GetLine($hRichText)
 RichText_GetSel($hRichText)
 RichText_SetSel($hRichText, $i_start, $i_end)
 RichText_GetLineCount($hRichText)
 RichText_GetLenght($hRichText)
 RichText_LineIndex($hRichText, $i_line = -1)
 RichText_LineLength($hRichText, $i_index = -1)
 RichText_Limit($hRichText, $hLimitTo)
 RichText_BkColor($hRichText, $iColor)
 RichText_GetFirstVisibleLine($hRichText)
 RichText_PosFromChar($hRichText, $iIndex)
 RichText_SetBkColor($hRichText, $hColor, $iSelec = True)
 RichText_SetBold($hRichText, $hBold = False, $iSelec = 0x01)
 RichText_SetColor($hRichText, $hColor, $iSelec = True)
 RichText_SetFontSize($hRichText, $Size , $iSelec = True)
 RichText_SetStrikeOut($hRichText, $hBold = False, $iSelec = 0x01)
 RichText_SetEventMask($hRichText, $hFunction)
 RichText_SetFont($hRichText, $hFontName, $iSelec = True)
 RichText_SetItalic($hRichText, $hBold = False, $iSelec = 0x01)
 RichText_SetReadOnly($hRichText $hBool = True)
 RichText_SetUnderline($hRichText, $hBold = False, $iSelec = 0x01)
 RichText_Undo($hRichText)
 RichText_SetTabStops($hRichText, $aTabStops)
 RichText_HideSelection($hRichText, $iState=True)
 RichText_PauseRedraw($hRichText)
 RichText_ResumeRedraw($hRichText)
 RichText_SetFormat($hRichText, $dwMask, $yHeight = 8, $yOffset = 0, _$crTextColor = 16711680, $bCharSet = 0, $bPitchAndFamily = 0, $szFaceName = "Sans Serif", _$wWeight = 400, $crBackColor = -1, $Underline = 0, $bUnderlineType = 0)

Above each function is the name of the author. If there isn't any: It's mine. ;)

Example: (Simple, but I like simple)

#Include <WindowsConstants.au3>
 #include <GuiConstantsEx.au3>
 #include <GuiRichEdit.au3>
 
 $GUI = GUICreate("bye",700,500)
     
     $hRichText = RichText_Create($GUI, 0, 0, 700, 500)
     RichText_InsertText($hRichText, "Hello everybody")
     
 GUISetState()
 
 RichText_SetSel($hRichText, 6, 11); Pos 6 to 11 is 'every'
 RichText_SetColor($hRichText, 0x0000FF, True); True = colorize selection, False = colorize all.  !!! Color codes is BGR !!!
 RichText_SetSel($hRichText, 0, 0); Set the selection to 0-0
 
 While 1
     If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
 WEnd

Now, dont let me hear anyone complain about how to create richtext controls! :D

GuiRichEdit.au3

Edited by Kip
Link to post
Share on other sites
  • Replies 47
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Nice collection!

Look here: http://www.autoitscript.com/forum/index.php?showtopic=79431&hl= ://http://www.autoitscript.com/forum/i...=79431&hl= ://http://www.autoitscript.com/forum/i...=79431&hl=

There is Win9x compatibilty code:

If FileExists(@SystemDir & "\Msftedit.dll") Then
    $dll = DllOpen("MSFTEDIT.DLL")
    $sRTFClassName = "RichEdit50W"
Else
    $dll = DllOpen("RICHED20.DLL")
    $sRTFClassName = "RichEdit20A"
EndIf

With this little addition it works also on older Win9x systems.

Edited by Zedna
Link to post
Share on other sites

Zedna, your code doesnt work. I changed it to:

If not FileExists(@SystemDir & "\RichEd20.dll") Then
and that works fine.

From MSDN:

Win 95 : Rich Edit 1.0 (Riched32.dll)

Win 98 : Rich Edit 1.0 (Riched32.dll) and 2.0 (Riched20.dll)

Win 2000 : Rich Edit 1.0 (Riched32.dll) and 3.0 (Riched20.dll)

Win ME : Rich Edit 1.0 (Riched32.dll) and 3.0 (Riched20.dll)

Win XP : Rich Edit 1.0 (Riched32.dll) and 3.0 (Riched20.dll)

Win XP SP1+: Rich Edit 1.0 (Riched32.dll) and 3.0 (Riched20.dll) and 4.1 (Msftedit.dll)

Win Vista : Rich Edit 1.0 (Riched32.dll) and 3.0 (Riched20.dll) and 4.1 (Msftedit.dll)

All windows versions (except 95) have Riched20.dll.

That means that Javascript_Freek eather has Win 95 or has deleted RichEd20.dll, right?

Edited by Kip
Link to post
Share on other sites

Here are some my older posts where I added this (similar) Win9x workaround:

http://www.autoitscript.com/forum/index.ph...st&p=422230

http://www.autoitscript.com/forum/index.ph...st&p=400217

If @OSTYPE = "WIN32_WINDOWS" Then; 95/98/Me
    DllOpen("RICHED20.DLL")
    $RTFClassName = "RichEdit20A"
Else; NT/2000/XP/2003/Vista 
    DllOpen("MSFTEDIT.DLL")
    $RTFClassName = "RichEdit50W"
EndIf

This was working fine on WIN98 and also on WINXP

Edited by Zedna
Link to post
Share on other sites

--------------------

AutoIt Error Start

--------------------

D:\Autoit\rich text.au3 (32) : ==> Missing separator character after keyword.:

RichText_SetFormat($hRichText, $dwMask, $yHeight = 8, $yOffset = 0, _$crTextColor = 16711680, $bCharSet = 0, $bPitchAndFamily = 0, $szFaceName = "Sans Serif", _$wWeight = 400, $crBackColor = -1, $Underline = 0, $bUnderlineType = 0)

RichText_SetFormat($hRichText, $dwMask, $yHeight = 8, $yOffset = 0, _^ ERROR

>Exit code: 1 Time: 1.957

-------------------

AutoIt Error End

-------------------

Website: www.cerescode.comForum: www.forum.cerescode.comIRC: irc.freenode.net , Channel: #Ceres--------------------Autoit Wrappers, Great additions to your script (Must See) (By: Valuater)Read It Befor Asking Question Click Here...--------------------Join Monoceres's Forums http://www.monoceres.se--------------------There are three kinds of people: Those who make things happen, those who watch things happen, and those who ask, ‘What happened?’” –Casey Stengel
Link to post
Share on other sites

--------------------

AutoIt Error Start

--------------------

D:\Autoit\rich text.au3 (32) : ==> Missing separator character after keyword.:

RichText_SetFormat($hRichText, $dwMask, $yHeight = 8, $yOffset = 0, _$crTextColor = 16711680, $bCharSet = 0, $bPitchAndFamily = 0, $szFaceName = "Sans Serif", _$wWeight = 400, $crBackColor = -1, $Underline = 0, $bUnderlineType = 0)

RichText_SetFormat($hRichText, $dwMask, $yHeight = 8, $yOffset = 0, _^ ERROR

>Exit code: 1 Time: 1.957

-------------------

AutoIt Error End

-------------------

Replace _$crTextColor with $crTextColor.
When the words fail... music speaks
Link to post
Share on other sites

Replace _$crTextColor with $crTextColor.

thanks for directing me to the direct code but this time it again gave me a error:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "D:\Autoit\rich text.au3"

D:\Autoit\rich text.au3 (32) : ==> Missing separator character after keyword.:

RichText_SetFormat($hRichText, $dwMask, $yHeight = 8, $yOffset = 0, $crTextColor = 16711680, $bCharSet = 0, $bPitchAndFamily = 0, $szFaceName = "Sans Serif", _$wWeight = 400, $crBackColor = -1, $Underline = 0, $bUnderlineType = 0)

RichText_SetFormat($hRichText, $dwMask, $yHeight = 8, $yOffset = 0, $crTextColor = 16711680, $bCharSet = 0, $bPitchAndFamily = 0, $szFaceName = "Sans Serif", _^ ERROR

>Exit code: 1 Time: 1.068

now how to resolve this error?>

Edited by ChromeFan
Website: www.cerescode.comForum: www.forum.cerescode.comIRC: irc.freenode.net , Channel: #Ceres--------------------Autoit Wrappers, Great additions to your script (Must See) (By: Valuater)Read It Befor Asking Question Click Here...--------------------Join Monoceres's Forums http://www.monoceres.se--------------------There are three kinds of people: Those who make things happen, those who watch things happen, and those who ask, ‘What happened?’” –Casey Stengel
Link to post
Share on other sites
  • Moderators

thanks for directing me to the direct code but this time it again gave me a error:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "D:\Autoit\rich text.au3"

D:\Autoit\rich text.au3 (32) : ==> Missing separator character after keyword.:

RichText_SetFormat($hRichText, $dwMask, $yHeight = 8, $yOffset = 0, $crTextColor = 16711680, $bCharSet = 0, $bPitchAndFamily = 0, $szFaceName = "Sans Serif", _$wWeight = 400, $crBackColor = -1, $Underline = 0, $bUnderlineType = 0)

RichText_SetFormat($hRichText, $dwMask, $yHeight = 8, $yOffset = 0, $crTextColor = 16711680, $bCharSet = 0, $bPitchAndFamily = 0, $szFaceName = "Sans Serif", _^ ERROR

>Exit code: 1 Time: 1.068

now how to resolve this error?>

Before posting in the forum on issues, read the output plane that you are actually posting here. It directly tells you the issue with the ^ sign. You can't have an underscore before your variable declaration $. Which is the same issue you had with the other post you made. Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...