Jump to content

Edit control with text color


Recommended Posts

I have been searching everywhere trying to make it so I can set the color/font on my Edit control, not of the whole thing but individual bits of text like with a selstart/sellength sort of thing. It's one of these deals - GUICtrlCreateEdit. (OK not sure if that is actually a RICHedit but I don't care how it works or what control is used, I just want to see a working multiline box with text and color.)

I keep seeing stuff about active-x edit controls but whenever I try to use the examples they crash, usually any time there is a "with" directive or quite ofter I keep getting multiple declarations of const's and functions like _sendMessage(), that in itself is not a big deal to troubleshoot but I don't know what to do about the `with object` stuff... Anyway I would really like to see a working example of an edit control with different text color that doesn't just crash when I try the example.

Thanks in advance

[size="1"][font="Lucida Console"]My ScriptsTrue multi-threaded ping[/font][/size]

Link to comment
Share on other sites

  • Moderators

Fr0zT,

GUICtrlCreateEdit produces a standard edit control. To have coloured sections of text, you need a RichEdit control as created by the GUIRichEdit UDF - look in the Help file to get details of all the functions available.

There are plenty of working examples on the forum. :blink:

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

I assume when you say the "Help File" you mean like F1 Help? Cause when I search for GUIRichEdit in there nothing comes up.

I have downloaded several GUIRichEdit UDF's but still nothing works. Here is an example of the crash I get when I try to run the examples. I was hoping to find an example that doesn't require massive debugging just to look at because whenever I get into this sort of thing I have to modify my includes files which causes problems with other apps I'm working on...

Basic Example:

Opt("MustDeclareVars", 1)
#include <GUIConstants.au3>
#include <GuiRichEdit.au3>

_Main()

Func _Main()
    Local $hgui, $msg, $hRichEdit
    $hgui = GUICreate("Rich Edit Example", 900, 700)
    $hRichEdit = _GUICtrlRichEdit_Create($hgui, "", 10, 10, 880, 680, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    GUISetState()
    _GUICtrlRichEdit_StreamFromFile($hRichEdit, @ScriptDir & "\Notes.rtf")
    _GuiCtrlRichEdit_GotoCharPos($hRichEdit, 0)

    While 1
        $msg = GUIGetMsg()

        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit
        EndSelect
    WEnd


EndFunc   ;==>_Main

Errors I get...

>"E:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "E:\Program Files\AutoIt3\Include\Example.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams    
+>10:55:55 Starting AutoIt3Wrapper v.1.9.2
>Running AU3Check (1.54.14.0)  from:E:\Program Files\AutoIt3
E:\Program Files\AutoIt3\Include\ScrollBarConstants.au3(26,37) : ERROR: $SB_THUMBPOSITION previously declared as a 'Const'
Global Const $SB_THUMBPOSITION = 0x4
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
E:\Program Files\AutoIt3\Include\ScrollBarConstants.au3(27,34) : ERROR: $SB_THUMBTRACK previously declared as a 'Const'
Global Const $SB_THUMBTRACK = 0x5
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
E:\Program Files\AutoIt3\Include\ScrollBarConstants.au3(45,41) : ERROR: $OBJID_HSCROLL previously declared as a 'Const'
Global Const $OBJID_HSCROLL = 0xFFFFFFFA
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
E:\Program Files\AutoIt3\Include\ScrollBarConstants.au3(46,41) : ERROR: $OBJID_VSCROLL previously declared as a 'Const'
Global Const $OBJID_VSCROLL = 0xFFFFFFFB
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
E:\Program Files\AutoIt3\Include\ScrollBarConstants.au3(47,40) : ERROR: $OBJID_CLIENT previously declared as a 'Const'
Global Const $OBJID_CLIENT = 0xFFFFFFFC
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
E:\Program Files\AutoIt3\Include\GuiRichEdit.au3(4939,47) : WARNING: $EM_SETPASSWORDCHAR: possibly used before declaration.
        __GCR_SendMessage($hWnd, $EM_SETPASSWORDCHAR)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
E:\Program Files\AutoIt3\Include\SendMessage.au3(49,145) : ERROR: _SendMessage() already defined.
Func _SendMessage($hWnd, $iMsg, $wParam = 0, $lParam = 0, $iReturn = 0, $wParamType = "wparam", $lParamType = "lparam", $sReturnType = "lparam")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
E:\Program Files\AutoIt3\Include\SendMessage.au3(83,146) : ERROR: _SendMessageA() already defined.
Func _SendMessageA($hWnd, $iMsg, $wParam = 0, $lParam = 0, $iReturn = 0, $wParamType = "wparam", $lParamType = "lparam", $sReturnType = "lparam")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
E:\Program Files\AutoIt3\Include\GuiRichEdit.au3(4939,47) : ERROR: $EM_SETPASSWORDCHAR: undeclared global variable.
        __GCR_SendMessage($hWnd, $EM_SETPASSWORDCHAR)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
E:\Program Files\AutoIt3\Include\Example.au3 - 8 error(s), 1 warning(s)
!>10:55:55 AU3Check ended.rc:2
+>10:55:57 AutoIt3Wrapper Finished
>Exit code: 0    Time: 1.985

[size="1"][font="Lucida Console"]My ScriptsTrue multi-threaded ping[/font][/size]

Link to comment
Share on other sites

OK Despite my original fears I went and modified my include files, and now I have a working RichEdit control which I'm happy about. Problem is now all my other programs are crashing because I had to modify my includes. Frustrating. Why do all of these things always have to overlap one another. Why declare the same constants in multiple include files or have multiple includes with the same functions in them. We know the _sendMessage() function is in SendMessage.au3 so why do we need it in misc.au3 as well??? Why can't misc.au3 just include SendMessage.au3. Arggg! Anyway, I just had to vent that, I'm sure I'll get this figured out eventually. Now it's a chicken/egg dilemma, how to modify all of my includes so that all of my programs are happy.

Edited by Fr0zT

[size="1"][font="Lucida Console"]My ScriptsTrue multi-threaded ping[/font][/size]

Link to comment
Share on other sites

Runs fine, no errors and no crash on exit:

#include <GUIConstants.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)

_Main()

Func _Main()
    Local $hgui, $msg, $hRichEdit
    $hgui = GUICreate("Rich Edit Example", 900, 700)
    $hRichEdit = _GUICtrlRichEdit_Create($hgui, "", 10, 10, 880, 680, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    GUISetState()
    _GUICtrlRichEdit_StreamFromFile($hRichEdit, @ScriptDir & "\Test1.rtf")
    _GUICtrlRichEdit_GotoCharPos($hRichEdit, 0)

    While 1
        $msg = GUIGetMsg()

        Select
            Case $msg = $GUI_EVENT_CLOSE
                _GUICtrlRichEdit_Destroy($hRichEdit)
                Exit
        EndSelect
    WEnd
EndFunc   ;==>_Main

:blink:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

OK Despite my original fears I went and modified my include files, ...

Bad idea...

...and now I have a working RichEdit control which I'm happy about. Problem is now all my other programs are crashing because I had to modify my includes. Frustrating.

...as you discovered. :blink:

Why do all of these things always have to overlap one another. Why declare the same constants in multiple include files or have multiple includes with the same functions in them. We know the _sendMessage() function is in SendMessage.au3 so why do we need it in misc.au3 as well??? Why can't misc.au3 just include SendMessage.au3. Arggg!

There is no declaration of _SendMessage() in Misc.au3, unless you put it there (or have a REALLY old out-of-date copy).

Anyway, I just had to vent that, I'm sure I'll get this figured out eventually. Now it's a chicken/egg dilemma, how to modify all of my includes so that all of my programs are happy.

If you must modify a UDF, make a renamed copy first.

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I wish there was another way. My AutoIt3.exe say V3.3 so it's not crazy old... Seems like every time I want to use some custom UDF I have no choice but to modify all my other UDF's. Now I'm so entrenched I couldn't upgrade if I wanted to because if I tried a new version of AutoIt I would have to heavily modify all the existing UDF's. It's just the way it is, there is no clean install and it just works method. I would be happy to do a new install on another PC and try and run one of my apps and print out the pages of errors I would get from doing that.

[size="1"][font="Lucida Console"]My ScriptsTrue multi-threaded ping[/font][/size]

Link to comment
Share on other sites

  • Moderators

Seems like every time I want to use some custom UDF I have no choice but to modify all my other UDF's.

WTF! :P

Note to readers: As PsaltyDS has said - please do not do this. :blink: If you feel you must modify a UDF, then try doing it like this:

Step 1: Create a new folder to hold copies of the modifed UDFs - I would recommend that you do NOT put this folder in the AutoIt install folder (or it will get overwritten when you upgrade : ).

Step 2: Tell AutoIt about this folder. If you have SciTE4AutoIt3 you can use SciTEConfig - look for the User Include Dir input about 2/3 way down the dialog. If not (and why not? You can download it from here) then you need to add a key to the Registry as explained on the "Include" page of the Help file:

There is a special registry value that can be created at "HKEY_CURRENT_USER\Software\AutoIt v3\AutoIt" called "Include". It should be a REG_SZ (string) value.

CYA Note: Normal precautions are advised if modifying the registry. ;)

Step 3: Copy the affected UDFs into the new folder. It is a good idea to rename them to avoid confusion - UDF_Mod.au3 has worked for me on the very few occasions I have needed to do this.

Step 4: Use the modified UDFs as you would the standard ones - the syntax is the same with no need to specify the path if you have followed Step 2 above.

And that is all there is to do! You can now have a whole folder of modified, downloaded or personal UDFs available to use as easily as the standard set. :nuke:

Once again - please do NOT modify the standard set in the AutoIt3\Include folder.

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

Ya, good words of advice from Psalty and Melba, a guy should probably have multiple instances of UDF's located in different folders since many of them have overlapping constants and functions. Even these 2 lines of code generate 13 errors for me because of all the overlapping constants.

#include <StatusBarConstants.au3>

#include <ScrollBarConstants.au3>

If I wanted to use scrollbars and status bars at the same time I'm guessing I would need to modify these UDF's to play together nicely.

Anyway... I am happily playing with a richedit box now, but since I don't have these functions listed in my help file, I was wondering if someone knew a way to set the defaults on the control? I mean, I can select some text and set the font, but if I just wanted to set the font for the whole control, how would I do that? I have already tried setting the font on the control without a selection and it didn't do anything.

Thanks

[size="1"][font="Lucida Console"]My ScriptsTrue multi-threaded ping[/font][/size]

Link to comment
Share on other sites

...a guy should probably have multiple instances of UDF's located in different folders since many of them have overlapping constants and functions. Even these 2 lines of code generate 13 errors for me because of all the overlapping constants.

#include <StatusBarConstants.au3>

#include <ScrollBarConstants.au3>

If I wanted to use scrollbars and status bars at the same time I'm guessing I would need to modify these UDF's to play together nicely.

NO!

You seem determined not to get it. That only happens because you MADE it happen by poor practice. The include files packaged with AutoIt do not normally need to be modified and do not generally cause errors when used together. Those two UDFs DO NOT produce any errors together unless you modified them.

Anyway... I am happily playing with a richedit box now, but since I don't have these functions listed in my help file, I was wondering if someone knew a way to set the defaults on the control? I mean, I can select some text and set the font, but if I just wanted to set the font for the whole control, how would I do that? I have already tried setting the font on the control without a selection and it didn't do anything.

Are you asking how AutoIt might be modified to make your mangled environment work correctly, or are you now working with a normal AutoIt environment with unmodified UDFs?

Download the current version of AutoIt and fix your scripts. You really can't be helped until you do.

:blink:

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Moderators

Fr0zT,

You can download the current Help file contents here. Then you get all the functions in the UDF explained. ;)

As to your UDF situation, I would strongly suggest that you bite the bullet and make a user include folder as I explained above. Once you have your custom includes in there and renamed, all ( :P ) you have to do is amend the #include lines of your exisitng scripts to use these files rather than the standard files. You can then install newer versions of Autoit without problems and, maybe, gradually wean your current scripts to the standard #include files.

these 2 lines of code generate 13 errors for me because of all the overlapping constants.

#include <StatusBarConstants.au3>

#include <ScrollBarConstants.au3>

Not a single problem for me with the current versions..... :blink:

M23

Edit: Great minds, eh!

Edited by Melba23

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