matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
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.
|
|