Page 1 of 11

Class RichEdit - update on 2015-04-14 (v0.1.05.00)

Posted: 17 Nov 2013, 03:40
by just me
!!! This scripts won't run properly with AHK ANSI !!!
Change History:
Edit on 2014-05-20:
  • Another sample tweaked by DigiDon can be found here.
Note: All AHK scripts must be stored as UTF-8 with BOM! Also, you must set up a default printer! (THX, tmplinshi)

Well, that's my second attempt to make RichEdit controls available for AHK. This time it's based on the RICHEDIT50W control provided by Msftedit.dll. It does support some more features, but it is a Unicode control. I don't know whether it would work with AHK ANSI and actually didn't try. That's why AHK Unicode is required.

The project is built up of four files, three schripts and a RTF sample file:
  1. Class_RichEdit.ahk - the class definition.
  2. Class_RichEditDlgs.ahk - some common dialogs used in the sample script. It's not actually needed, but might make things a bit easier.
  3. RichEdit_sample.ahk - a "how to use" sample script.
  4. Test.rtf - a formatted RTF sample file.
Compared to my first attempt I've added some more formatting features like paragraph numbering, paragraph indentation, justified alignment, and so on, which are visible supported by the now used preregistered class. Also, I revised the "WYSIWYG" (wrap as printed) and printing code. It seems to give more precise results now. The sample script is a quick transcription of the former one. It won't win a price on a AHK programmers contest. Maybe someone is interested to spend a nice Toolbar to demonstrate more up-to-date programming techniques; it would be highly appreciated.

If I'll ever find time and power to write some kind of documentation, I'll do it. It's a rather hard job for me, because English, as you might have noticed, is not my native tongue. Until then I ask you for looking at the sample script and the marginal inline documentation.

Enough said, pictures speak louder than words:
RichEdit.png
Class_RichEdit.ahk v0.1.05.00:
I proudly present my first attempt to set up a GitHub repository to manage one of my scripts, so you'll find all the needed parts at GitHub. ;)

:arrow: Look at the sources on GitHub.
:arrow: Dowload from GitHub.

Re: Class RichEdit - rich edit control for AHK (Unicode)

Posted: 17 Nov 2013, 11:36
by arcticir
This is very useful. Thanks.

Re: Class RichEdit - rich edit control for AHK (Unicode)

Posted: 18 Nov 2013, 05:42
by Learning one
Great job just me! Thanks for sharing! ;)

Re: Class RichEdit - rich edit control for AHK (Unicode)

Posted: 18 Nov 2013, 06:22
by fredchf
+1 :)

Re: Class RichEdit - rich edit control for AHK (Unicode)

Posted: 19 Nov 2013, 02:12
by Johnny R
Is it possible to transfer the script to AHK (ANSI)?

Re: Class RichEdit - rich edit control for AHK (Unicode)

Posted: 19 Nov 2013, 05:20
by just me
... but it is a Unicode control. I don't know whether it would work with AHK ANSI and actually didn't try. ...
It might work with AHK 1.1 (ANSI) after some modifications, but I'm not interested in trying it. The most important advantage of AHK (ANSI) was/is that it is providing more backward compatibility with AHK 1.0. AHK v2, which I'm impatiently waiting for, won't support ANSI any more. So it's time to switch to AHK (Unicode). If you have some scripts or functions causing problems with the Unicode version you cannot solve on your own, just ask for help. I'm sure you'll get all the help you need in this forum, as far it isn't about Bots.

Re: Class RichEdit - rich edit control for AHK (Unicode)

Posted: 19 Nov 2013, 12:44
by Johnny R
I'm not interested in trying it
I'm not interested in your interests. I'm interested in help. Thank you.

Re: Class RichEdit - rich edit control for AHK (Unicode)

Posted: 20 Nov 2013, 01:38
by just me
If you have some scripts or functions causing problems with the Unicode version you cannot solve on your own, just ask for help. I'm sure you'll get all the help you need in this forum, as far it isn't about Bots.

Re: Class RichEdit - rich edit control for AHK (Unicode)

Posted: 23 Nov 2013, 14:11
by Johnny R
Using AHK (ANSI), I have problems in opening and saving files, look here:
Image
Image

Re: Class RichEdit - rich edit control for AHK (Unicode)

Posted: 24 Nov 2013, 00:49
by just me
... So it's time to switch to AHK (Unicode). ...
You didn't, so the problems are not related to the Unicode version (of AHK). This might be solved by adding , "UTF-16" to all StrPut/StrGet() statements in FileDlg() contained in Class_RichEditDlgs.ahk. But it would be 'a drop in the bucket' / 'ein Tropfen auf den heißen Stein'.

Re: Class RichEdit - rich edit control for AHK (Unicode)

Posted: 24 Nov 2013, 05:16
by Johnny R
This might be solved by adding , "UTF-16" to all StrPut/StrGet() statements in FileDlg() contained in Class_RichEditDlgs.ahk.
Open/Save is now OK. Thank You! Now I have a problem with "Find". The Script does not find Strings in the rtf-file...

Image

Re: Class RichEdit - rich edit control for AHK (Unicode)

Posted: 25 Nov 2013, 01:10
by just me
... The Script does not find Strings in the rtf-file...
Yes, of course. You'll find the reason in Class_RichEditDlgs.ahk again, this time in FindText() and FindTextProc(). There are only two statements dealing with strings in this methods:
  • FindText() -> Buf := Text
  • FindTextProc() -> Find := StrGet(NumGet(L + Offset, 0, "UPtr"))
Both Buf and Find must contain Unicode ("UTF-16") strings. Maybe it will solve the problem.

BTW:
ANSI3.png
*All good things come in threes.*

Re: Class RichEdit - rich edit control for AHK (Unicode)

Posted: 25 Nov 2013, 12:49
by Johnny R
I resign. It's too difficult for me...

Re: Class RichEdit - rich edit control for AHK (Unicode)

Posted: 26 Nov 2013, 07:32
by nnnik
Maybe I'll try.

Re: Class RichEdit - rich edit control for AHK (Unicode)

Posted: 26 Nov 2013, 12:55
by nnnik
fu:
Error in #Include file ClassRichEdit.ahk
This DllCall requires a prior VarSetCapacity specifically:
269: Return DllCall("Comctl32.dll\DefSubclassProc", "Ptr", This, "UInt", M, "Ptr", W, "Ptr", L)
But works in AHK Unicode

Re: Class RichEdit - rich edit control for AHK (Unicode)

Posted: 27 Nov 2013, 00:26
by just me
I cannot reproduce this error (AHK 1.1.13.01 (ANSI) - Win 7 Prof. x64)

Re: Class RichEdit - rich edit control for AHK (Unicode)

Posted: 27 Nov 2013, 02:34
by nnnik
Newest Version Ansi x86 XP Prof SP3

Re: Class RichEdit - rich edit control for AHK (Unicode)

Posted: 28 Nov 2013, 00:49
by just me
Well, what are you trying to do before you get this error?

Re: Class RichEdit - rich edit control for AHK (Unicode)

Posted: 29 Nov 2013, 00:21
by oldbrother
"Choose Font" is not working. My system: XP PRO SP3
1.jpg

Re: Class RichEdit - rich edit control for AHK (Unicode)

Posted: 29 Nov 2013, 05:29
by just me
oldbrother,

thanks for reporting. This will be fixed tomorrow.