Shoutbox

[Ask]RichEdit Control and Syntax Color - 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: [Ask]RichEdit Control and Syntax Color (/showthread.php?tid=91809)

[Ask]RichEdit Control and Syntax Color by Lén on 08-09-2009 at 04:44 PM

Hi,

I've search for a while and i still haven't found any informations about it.

How can I colorize a list of key words in real time in a RichEdit Control
inside a PlusWnd ?

need help Thanks


RE: [Ask]RichEdit Control and Syntax Color by matty on 08-10-2009 at 08:10 PM

You need to use the following function: http://mpscripts.net/docs/ref-pluswnd-richedit_setcharformat.php


RE: [Ask]RichEdit Control and Syntax Color by Lén on 08-10-2009 at 08:24 PM

yeah i know but i really don't know how to:
- do it in real time
- color just a word that i defined.

I know that this function can color a Selection, but how to select a defined word ? imagine i 've a long text ! with a loop it will tke a lot of time !



So is RegExp object can be used, or any other method ?


RE: [Ask]RichEdit Control and Syntax Color by matty on 08-10-2009 at 08:27 PM

Take a look at this: http://msdn.microsoft.com/en-us/library/bb761661%28VS.85%29.aspx

That lets you select the text then you can change the color using the Plus! function.


RE: [Ask]RichEdit Control and Syntax Color by Lén on 08-10-2009 at 08:33 PM

could you give me an exemple please ? i'm not at ease with the MSDN help :D


RE: [Ask]RichEdit Control and Syntax Color by matty on 08-11-2009 at 12:47 PM

Javascript code:
var EM_SETSEL = 0xb1;
 
function OnWindowIdEvent_EditTextChanged( pPlusWnd, sControlId ) {
    if ( sControlId === 'MyRichEditControl' ) {
        var hObjWnd = pPlusWnd.GetControlHandle ( sControlId );
        Interop.Call( 'user32', 'SendMessageW', hObjWnd, EM_SETSEL, 0, 10 );
    }
}


This is just an example on how to select text. What are you trying to highlight? Code?
You also need to make sure the control in the XML has the following set:
XML code:
<Attributes><TextMode>Rich Text</TextMode></Attributes>


[no subject] by Lén on 08-11-2009 at 03:20 PM

i am trying to highliht key word such as "def, if, else ..." to do a window whis syntax colorizing.

I try this and give you feedback.

EDIT: here's my XML:

code:
<Control xsi:type="RichEditControl" Id="txtMessage">
     <Position Top="15" Width="350" Height="350" Left="5"/>
          <Caption>Script</Caption>
          <Attributes>
               <TextMode>Rich Text</TextMode>
               <WantReturn>true</WantReturn>
           </Attributes>
</Control>

Here's your function:
code:
function OnWndScriptEnvEvent_EditTextChanged( pPlusWnd, sControlId ) {
    if ( sControlId === 'txtMessage' ) {
        var hObjWnd = pPlusWnd.GetControlHandle ( sControlId );
        Interop.Call( 'user32', 'SendMessageW', hObjWnd, EM_SETSEL, 0, 10 );
    }
}

It always replace what i'm typing, so there is just one letter written ... but i can change this letter because it's selected.


What i'm looking for is like the Messenger Plus! Script Editor, i mean when i type "if" in the editor, it's autamatically blue colored ...
I think that the editor is a RichEdit, so i can do that too, or not ?

EDIT2:
Do you know if <WantTabs> work with msn plus! and richedit ? because when i delete <WantReturn> pushing Enter doesn't work.
I want to use TAB to do a \t (like in Scripting Environment of MSN plus!).
RE: [Ask]RichEdit Control and Syntax Color by matty on 08-11-2009 at 04:59 PM

The reason it is constantly overwriting what you type is because it is selecting the first 10 characters when a change is made. I was simply showing you an example of how to select text. From that point you can use the Plus! function I first told you about to set the colour.


RE: [Ask]RichEdit Control and Syntax Color by Lén on 08-11-2009 at 05:52 PM

oh yeah i finnaly understand ^^

but, how can search in the text my keyword ?
for exemple def:

code:
function OnWndScriptEnvEvent_EditTextChanged( pPlusWnd, sControlId ) {
    if ( sControlId === 'txtMessage' ) {
            sMessage = EnvWindow.GetControlText("txtMessage")       
             var hObjWnd = pPlusWnd.GetControlHandle (sControlId);
            for (i = 0; i < sMessage.length+1; i++){
            if(sMessage.charAt(i)=="d"){
                for (j = i+1; j < sMessage.length+1; j++){
                    if(sMessage.charAt(j)=="e"){
                        for (h = j+1; h < sMessage.length+1;h++){
                            if(sMessage.charAt(h)=="f"){
                                Interop.Call('user32', 'SendMessageW', hObjWnd, EM_SETSEL, i, h);
                                MyWindow.RichEdit_SetCharFormat("txtMessage",true,-1,-1,-1,-1,-1,0x00ff0000,"");

                            }
                        }
                    }
                }
            }
        }
    }
}

Have I to do that for every keyword :o ???

EDIT: How to Unselect my text after it has been replaced ?
EDIT: I found that and it work pretty good, but i still ask how can i unselect the texte after it has been colored ^^
code:
function OnWndScriptEnvEvent_EditTextChanged( pPlusWnd, sControlId ) {
    if ( sControlId === 'txtMessage' ) {
            sMessage = EnvWindow.GetControlText("txtMessage")       
        var hObjWnd = pPlusWnd.GetControlHandle (sControlId);
        i = sMessage.indexOf("def",0)
        if(sMessage.charAt(i+1)=="e" && sMessage.charAt(i+2)=="f"){
            Interop.Call('user32', 'SendMessageW', hObjWnd, EM_SETSEL, i,i+3);
            EnvWindow.RichEdit_SetCharFormat("txtMessage",true,-1,-1,-1,-1,-1,0x00ff0000,"");
            }
    }
}

EDIT: i've found it tu unselect:
code:
Interop.Call('user32', 'SendMessageW', hObjWnd, EM_SETSEL, -1,-1);

but i'm scared of how mani "loop for" i will use to do a global... 'cause this method juste replace the first "def" entry.
RE: [Ask]RichEdit Control and Syntax Color by matty on 08-11-2009 at 06:37 PM

Honestly this is really a horrible way of doing it. There is a "CodeEditControl" but it only supports JScript text highlighting.


RE: [Ask]RichEdit Control and Syntax Color by Lén on 08-11-2009 at 07:17 PM

ok thanks for the great help :D

I'm doing it for ruby
here's my V1: http://www.msgplus.net/scripts/view/557-RubyColor/

this question was for the V2 with a complete RUBY IDE ^^