Shoutbox

Rich text format extract using Interop - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Rich text format extract using Interop (/showthread.php?tid=93431)

Rich text format extract using Interop by aztectrev on 01-04-2010 at 07:40 PM

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.:|
RE: Rich text format extract using Interop by matty on 01-26-2010 at 03:09 PM

Are you trying to get the raw rtf text?


RE: Rich text format extract using Interop by aztectrev on 01-26-2010 at 04:18 PM

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


RE: Rich text format extract using Interop by matty on 01-26-2010 at 04:25 PM

Ok first thing first you dont want to use || when calling the function. You want to use |.


RE: Rich text format extract using Interop by aztectrev on 01-26-2010 at 04:37 PM

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
RE: Rich text format extract using Interop by matty on 01-26-2010 at 05:49 PM

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


RE: Rich text format extract using Interop by aztectrev on 01-26-2010 at 06:22 PM

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


RE: Rich text format extract using Interop by matty on 01-26-2010 at 06:36 PM

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));
}

RE: Rich text format extract using Interop by aztectrev on 01-26-2010 at 06:38 PM

THANKS! your a genius. :D

I can finish my script now:D:D:D:D


RE: Rich text format extract using Interop by matty on 01-26-2010 at 07:47 PM

No problem, glad I could help.