What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Rich text format extract using Interop

Rich text format extract using Interop
Author: Message:
aztectrev
New Member
*


Posts: 8
– / Male / –
Joined: Jan 2010
O.P. Happy  Rich text format extract using Interop
I'm trying to get the RTF data out of a richeditcontrol. Couldn't find an easy way so i'm trying to use Interop.

so far i have:
code:
function OnWndMainEvent_CtrlClicked(PlusWnd, ControlId)
{
    if (ControlId == "BtnSend")
    {
        var SF_RTF = 0x2
        var SF_UNICODE = 0x10
        var WM_USER = 0x400
        var EM_STREAMOUT = (WM_USER + 74)
        var len = PlusWnd.GetControlText("CodeBox").length;
        var editStream = Interop.Allocate(24)
        editStream.WriteDWORD(0,0)
        editStream.WriteDWORD(8,0)
        editStream.WriteDWORD(16,Interop.GetCallbackPtr("EditStreamCallback"))
        var lResult = Interop.Call2("user32.dll", "SendMessageW", PlusWnd.GetControlHandle(ControlId), EM_STREAMOUT, SF_RTF || SF_UNICODE, editStream )
        Debug.Trace("result: " + lResult)
    }
}

function EditStreamCallback(dwCookie, lpBuff, cb, pcb)
{

}

I've probably done this all wrong so any help is appreciated.:|
01-04-2010 07:40 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Rich text format extract using Interop
Are you trying to get the raw rtf text?
01-26-2010 03:09 PM
Profile E-Mail PM Find Quote Report
aztectrev
New Member
*


Posts: 8
– / Male / –
Joined: Jan 2010
O.P. RE: Rich text format extract using Interop
Ye, i'm trying to get the rtf raw data out i can parse it and replace any color values with with ones used in msgplus and then send the message so the receiver will see the rich text
01-26-2010 04:18 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Rich text format extract using Interop
Ok first thing first you dont want to use || when calling the function. You want to use |.
01-26-2010 04:25 PM
Profile E-Mail PM Find Quote Report
aztectrev
New Member
*


Posts: 8
– / Male / –
Joined: Jan 2010
O.P. RE: Rich text format extract using Interop
ok, changing it doesnt make it work though. I have no idea what I need to change, bit that confused me most was

code:
        var editStream = Interop.Allocate(24)
        editStream.WriteDWORD(0,0)
        editStream.WriteDWORD(8,0)
        editStream.WriteDWORD(16,Interop.GetCallbackPtr("EditStreamCallback"))

Its probably wrong, as I copied it from documentation on msgplus along with using microsoft documentation.

I read that to retrieve the rtf text you need to use EM_STREAMOUT message which it then sends back to the calling program as an EditStreamCallback from which you can then get the string?

I made a window with a RichEditControl and been experimenting with it with no luck
01-26-2010 04:37 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Rich text format extract using Interop
The structure should only be 12 bytes in size.

I almost have it working... just give me a bit to post it and clean it up

This post was edited on 01-26-2010 at 06:32 PM by matty.
01-26-2010 05:49 PM
Profile E-Mail PM Find Quote Report
aztectrev
New Member
*


Posts: 8
– / Male / –
Joined: Jan 2010
O.P. Cool  RE: Rich text format extract using Interop
Thanks! :D, works great, the cookie matches. Looks like i wasn't far off from doing it myself*-), i would never have worked out what was wrong :|

Thanks for help so far (Y) Need one last thing before I can finish my script, sorry. The callback function returns a pointer to the buffer and the buffer length and no idea how to retrieve the string using script, not sure there is a way to access the pointer directly?


edited:
I've found the DataBloc::ReadString method

[string] ReadString(
    [number] Offset,
    [boolean,optional] ReadUnicode,
    [number,optional] Size
);

Just testing it

This post was edited on 01-26-2010 at 06:37 PM by aztectrev.
01-26-2010 06:22 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Rich text format extract using Interop
js code:
// variables
var SF_RTF = 0x2;
var SF_UNICODE = 0x10;
var WM_USER = 0x400;
var EM_STREAMOUT = (WM_USER + 74);

// did this just to make sure that function call smaller
var nFlags = SF_RTF | SF_UNICODE;

/*
// this was my testing
MsgPlus.CreateWnd('WndMain.xml', 'WndMain');
Debug.DebuggingWindowVisible = true;*/

function OnWndMainEvent_CtrlClicked(PlusWnd, ControlId) {
    // check which control is sending the event
    if (ControlId == 'BtnSend') {
        // create a variable to hold the handle of the rtf control
        var CodeBox_hWnd = PlusWnd.GetControlHandle('CodeBox');
        // print this handle to verify for later use
        Debug.Trace('CodeBox Handle: '+CodeBox_hWnd);
        // create our memory block for the EDITSTREAMCALLBACK
        var EDITSTREAMCALLBACK = Interop.Allocate(12);
            /* specify the application defined variable (simply to verify
               the rtf box is the one the function is relating to) */
            EDITSTREAMCALLBACK.WriteDWORD(0, CodeBox_hWnd);
            // get the callback pointer for our function
            EDITSTREAMCALLBACK.WriteDWORD(8, Interop.GetCallbackPtr('EditStreamCallback'));
        // send the message to the control
        // notice the use of Call not Call2; Call is for functions that return an INT, Call2 is to return a BSTR - http://mpscripts.net/docs/ref-interop-call2.php
        Interop.Call('user32', 'SendMessageW', CodeBox_hWnd, EM_STREAMOUT, nFlags, EDITSTREAMCALLBACK.DataPtr);
    }
}

function EditStreamCallback(dwCookie, lpBuff, cb, pcb) {
    // dwCookie should match the CodeBox control handle
    Debug.Trace ('dwCookie: '+dwCookie);
    // print the length of the raw rtf data
    Debug.Trace ('cb: '+cb);
    // define a datablock large enough to hold our data
    var lpsz = Interop.Allocate(cb+1);
    // copy the memory from the data buffer to our allocated memory block
    Interop.Call('kernel32', 'RtlMoveMemory', lpsz, lpBuff, lpsz.Size);
    // print out the result
    Debug.Trace(lpsz.ReadString(0, false));
}

This post was edited on 01-26-2010 at 06:39 PM by matty.
01-26-2010 06:36 PM
Profile E-Mail PM Find Quote Report
aztectrev
New Member
*


Posts: 8
– / Male / –
Joined: Jan 2010
O.P. Grin  RE: Rich text format extract using Interop
THANKS! your a genius. :D

I can finish my script now:D:D:D:D
01-26-2010 06:38 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Rich text format extract using Interop
No problem, glad I could help.
01-26-2010 07:47 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On