AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[Library] Edit v1.1 - Update/Control any Edit control
Goto page 1, 2  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
jballi



Joined: 01 Oct 2005
Posts: 747
Location: Texas, USA

PostPosted: Sat Feb 27, 2010 2:54 am    Post subject: [Library] Edit v1.1 - Update/Control any Edit control Reply with quote

Introduction
Although not as robust as the Rich Edit control, the standard Edit control is a lightweight and surprisingly powerful control for managing text. Inspired by the Edit mini-library created by Lexikos and the HiEditor library created by majkinetor, the Edit library was created to help bring the Edit control out of it's inferiority shell.


Screenshots
A couple of screenshots from the examples...





The Code
The pertinent files are as follows:
Issues/Considerations
  • Examples. Most of the example scripts can make real changes to real data. Use care when running these scripts.

  • Documentation. It's getting better but I'm a still a Natural Docs newbie. It's going to take a little while for me to adjust to the Natural Docs style.

References
The following posts were helpful in the creation of this library. Thanks to the original authors.

Scripts that use the Edit library:

---------------------------------------------------------------------------
Release Notes

v0.1 (Preview)
Original release.

v0.2 (Preview)
- The Edit_CharFromPos function has been rewritten to support controls with more than 65,536 characters and/or more than 65,536 lines of text.
- Added Drag & Drop example (thanks Laszlo)

v1.0
- Removed Edit_GetThumb function. Could not get the EM_GETTHUMB message to work on an Edit control. Most documentation implies that the message is for the RichEdit control.

v1.1
- Fix: Edit_Edit_PosFromChar function modified to correctly return a negative number if the requested character is outside the edit control.
- Added the Edit_TTSGUI (Preview) add-on function to show a Text-To-Speech player for any edit control. Includes a plethora of options. Requires the COM library.
- Added the Edit_SpellCheckGUI (Preview) add-on function. Requires the Spell library.
- Updated examples.


Last edited by jballi on Thu Jun 23, 2011 12:17 am; edited 11 times in total
Back to top
View user's profile Send private message Send e-mail
entropic



Joined: 21 Dec 2008
Posts: 181

PostPosted: Sat Feb 27, 2010 4:17 am    Post subject: Reply with quote

Very cool, thank you!
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4710
Location: Boulder, CO

PostPosted: Sat Feb 27, 2010 3:54 pm    Post subject: Reply with quote

You could drag text in- and between edit controls. Most of the useful messages are also described there.
Back to top
View user's profile Send private message
jballi



Joined: 01 Oct 2005
Posts: 747
Location: Texas, USA

PostPosted: Sun Feb 28, 2010 9:31 am    Post subject: Reply with quote

Laszlo wrote:
You could drag text in- and between edit controls. Most of the useful messages are also described there.

Sound cool. I'll check it out. Thanks. Smile
Back to top
View user's profile Send private message Send e-mail
jballi



Joined: 01 Oct 2005
Posts: 747
Location: Texas, USA

PostPosted: Sat Mar 06, 2010 1:03 am    Post subject: Reply with quote

v0.2 (Preview)
Minor updates. See the bottom of the first post for a list of changes.
Back to top
View user's profile Send private message Send e-mail
jballi



Joined: 01 Oct 2005
Posts: 747
Location: Texas, USA

PostPosted: Sun Apr 11, 2010 1:32 am    Post subject: Reply with quote

v1.0
Superficial changes only. No need to download if you have v0.2 already. See the bottom of the first post for a list of changes.
Back to top
View user's profile Send private message Send e-mail
Lexikos



Joined: 17 Oct 2006
Posts: 7295
Location: Australia

PostPosted: Sun Apr 11, 2010 2:28 am    Post subject: Reply with quote

Well done.
jballi wrote:
Missing messages include EM_GETSELTEXT, EM_GETTEXTRANGE, and EM_FINDTEXT. ... Although the substitute code/messages are very capable, they are not quite as efficient (memory and/or speed) as the messages they replace (if they existed).
FYI, MSDN explicitly states these messages are for rich edit controls. They're not supposed to work for edit controls.
Back to top
View user's profile Send private message Visit poster's website
jballi



Joined: 01 Oct 2005
Posts: 747
Location: Texas, USA

PostPosted: Sun Apr 11, 2010 4:08 am    Post subject: Reply with quote

Lexikos wrote:
jballi wrote:
Missing messages include EM_GETSELTEXT, EM_GETTEXTRANGE, and EM_FINDTEXT. ... Although the substitute code/messages are very capable, they are not quite as efficient (memory and/or speed) as the messages they replace (if they existed).
FYI, MSDN explicitly states these messages are for rich edit controls. They're not supposed to work for edit controls.

Of course. I was just trying to get across that these messages are needed for the Edit control and that the library provides fantabulous Wink substitutes. I'll try to rewrite this section to avoid confusion. Thank you for your feedback. Smile
Back to top
View user's profile Send private message Send e-mail
XYZ



Joined: 20 Mar 2010
Posts: 224

PostPosted: Sun Apr 11, 2010 2:06 pm    Post subject: Reply with quote

Quote:

[Library] Edit v1.0 - Update/Control any Edit control


thx a lot man
Back to top
View user's profile Send private message
TLM



Joined: 21 Aug 2006
Posts: 2926
Location: The Shell

PostPosted: Wed May 19, 2010 3:19 pm    Post subject: Reply with quote

Excellent Twisted Evil
_________________
paradigm.shift:=(•_•)┌П┐RTFM||^.*∞
Back to top
View user's profile Send private message
jballi



Joined: 01 Oct 2005
Posts: 747
Location: Texas, USA

PostPosted: Sun May 23, 2010 2:33 am    Post subject: Reply with quote

Smart Word Wrap Toggle For Notepad

One of the problems (read: pet peeves) with toggling Word Wrap in Notepad is that the program loses track of where you were in the document. It's not a big deal if you just opened the document or if you're working on the first few lines, but if you were working far into the document, it can be very irritating.

This script provide two basic features:
  1. Context-sensitive hotkey. This code will only fire if a Notepad window is active. Uses Ctrl+W (patterned after PSPad) but change it to whatever you want.

  2. Preserve caret position or selection. If typing just before the hotkey is used, you can resume typing immediately afterwards. If text was selected before the hotkey is used, the same text will be selected afterwards.

Here's the code (needs the Edit library of course):

Code:
;[=============]
;[  Ctrl+W     ]
;[  [Notepad]  ]
;[=============]
#IfWinActive ahk_class Notepad
^w::
#IfWinActive

;-- Get current handle to the Edit control
if Edit_GetActiveHandles(hEdit)
    {
    ;-- Get current select positions
    Edit_GetSel(hEdit,$StartSelPos,$EndSelPos)

    ;-- Toggle word wrap
    SendMessage 0x111,32,0  ;-- 0x111=WM_COMMAND

    ;-- Collect new handle to the Edit control
    Edit_GetActiveHandles(hEdit)

    ;-- Set caret
    Edit_SetSel(hEdit,$StartSelPos,$StartSelPos)
    Edit_ScrollCaret(hEdit)
        ;-- Initial selection and scroll.  This makes sure that the leftmost
        ;   position of the selection is showing.

    ;-- Re-select if necessary   
    if ($StartSelPos<>$EndSelPos)
        {
        Edit_SetSel(hEdit,$StartSelPos,$EndSelPos)

        ;-- Show as much of the selection as possible
        $FirstVisibleLine :=Edit_GetFirstVisibleLine(hEdit)
        $LastVisibleLine  :=Edit_GetLastVisibleLine(hEdit)
        $FirstSelectedLine:=Edit_LineFromChar(hEdit,$StartSelPos)
        $LastSelectedLine :=Edit_LineFromChar(hEdit,$EndSelPos)

        ;-- Last line showing?
        if ($LastSelectedLine>$LastVisibleLine)
            if ($LastSelectedLine-$LastVisibleLine<$FirstSelectedLine-$FirstVisibleLine)
                Edit_LineScroll(hEdit,0,($LastVisibleLine-$LastSelectedLine)*-1)
             else
                Edit_LineScroll(hEdit,0,($FirstVisibleLine-$FirstSelectedLine)*-1)
        }
    }

return

I hope that someone finds this useful.
Back to top
View user's profile Send private message Send e-mail
Wicked



Joined: 07 Jun 2008
Posts: 369

PostPosted: Sun May 23, 2010 5:05 am    Post subject: Reply with quote

I can't believe I've missed this up until this point!

Thank you for your hard work, jballi. It is much appreciated!
Back to top
View user's profile Send private message
jballi



Joined: 01 Oct 2005
Posts: 747
Location: Texas, USA

PostPosted: Mon May 24, 2010 12:17 am    Post subject: Reply with quote

v1.1
Minor bug fix plus a couple of new add-on functions. See the bottom of the first post for a list of changes.
Back to top
View user's profile Send private message Send e-mail
Mystiq



Joined: 08 Jan 2007
Posts: 83

PostPosted: Wed Aug 25, 2010 1:17 pm    Post subject: Reply with quote

This is exactly what i was looking for, lo and behold, someone had already made it! Smile

Thanks!
Back to top
View user's profile Send private message
tov
Guest





PostPosted: Fri Dec 03, 2010 11:29 am    Post subject: Reply with quote

Looks looks great Smile

I need my edit box to only hold 1000 lines of text, after that I want the top line to be removed and everything else scroll up.

The edit box is being constantly updated by a live stream, using 1000 lines will reduce the memory overhead needed.

I will have a play.. but : Can anyone point me in the right direction ??

Thanks
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group