First off many thanks for taking the time to help the idiotic me.
Sean wrote:
You did it completely wrong. It's a great mystery how you reached the posted code from the mentioned VB code. Do you understand the VB code?
...... Owned

..... That was the first thought that crossed my mind after reading your post, and i deserve it. No excuses for me (except maybe the standard ones like "it was late" and so on ...).
To answer your question if I understood the VB code I can honsetly say Yes/No, since I never worked with VB, except when adapting vb scripts to ahk (sucessfully till now i might add!), and concerning COM, well that was my first try into the field, that I didn't touch, even with a 10 foot pole, till now.
Believe it or not, but your solution was the first thing i tried, minus the VarSetCapacity and the NumGet part of course. Since that didn't work I came up with that piece of code. It went down something like this:
- They create the Com objects before using them, so lets do it like this too --> COM_CreateObject
- send EM_GETOLEINTERFACE --> ok the same
- hm setting one object to the recieved lparam pointer and then using it like an ITextDocument object --> msdn says the sendmsg returns a IRichEditOle and to get ITextDocument use QueryInterface --> total mess
- and so on ..
After I got that it didnt work, and I thought i adapted it right and the only thing wrong here was the params of COM_CreateObject, and thats how this mess came to be.
Sean wrote:
Anyway, there exist two ways to obtain
IRichEidtOle/ITextDocument interface.
Only for RichEdit controls in the same AHK/thread,
Code:
COM_Init()
VarSetCapacity(lp,4,0)
SendMessage, 1084,, &lp,, ahk_id %hwndRichEdit%
preo := NumGet(lp) ; IRichEditOle
; ptom := COM_QueryInterface(preo, "{8CC497C0-A1DF-11CE-8098-00AA0047BE5D}"), COM_Release(preo)
With your solution I managed to make it work, so heres the working code with many thanks to Sean:
Just run this, select some part of the text then press button!
Code:
; requires corrupts richedit implementation:
; http://www.autohotkey.com/forum/ntopic49028.html
;
Gui Add, Button, ym gtest1, test1
Gui Show, +hide w500 h500, RichEdit demo
If A_OSVersion = WIN_95
cGUI("Add", REdit1, 10, 40, 480, 450, "RICHEDIT")
Else
cGUI("Add", REdit1, 10, 40, 480, 450, "RichEdit20A")
cRichEdit(REdit1, "Text", "Test string to illustrate how to use the `nText Object Model")
COM_Init()
Gui Show
Return
test1:
VarSetCapacity(lp,4,0)
SendMessage, 1084,, &lp,, ahk_id %REdit1%
preo := NumGet(lp)
ptom := COM_QueryInterface(preo, "{8CC497C0-A1DF-11CE-8098-00AA0047BE5D}")
COM_Release(preo)
ptr := COM_Invoke(ptom, "Range", 5, 11)
ptf := COM_Invoke(ptr, "Font")
COM_Invoke(ptf, "ForeColor", "0x000000FF")
COM_Invoke(ptr, "FindText", "object", "1073741823", "2")
COM_Invoke(ptf, "ForeColor", "0x0000FF00")
COM_Release(ptf)
COM_Release(ptr)
COM_Release(ptom)
Return
GuiClose:
COM_Term()
If (REdit1)
cRichEdit(REdit1, "Destroy")
Gui, %A_Gui%:Destroy
cGUI("FreeDlls", NULL)
ExitApp
Return
#Include cGUI.ahk
#Include cRichEdit.ahk