What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [Ask]RichEdit Control and Syntax Color

Pages: (2): « First [ 1 ] 2 » Last »
[Ask]RichEdit Control and Syntax Color
Author: Message:
Lén
Junior Member
**

Avatar

Posts: 16
34 / Male / Flag
Joined: Feb 2008
O.P. [Ask]RichEdit Control and Syntax Color
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

This post was edited on 08-09-2009 at 09:22 PM by Lén.
08-09-2009 04:44 PM
Profile PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: [Ask]RichEdit Control and Syntax Color
You need to use the following function: http://mpscripts.net/docs/ref-pluswnd-richedit_setcharformat.php
08-10-2009 08:10 PM
Profile E-Mail PM Find Quote Report
Lén
Junior Member
**

Avatar

Posts: 16
34 / Male / Flag
Joined: Feb 2008
O.P. RE: [Ask]RichEdit Control and Syntax Color
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 ?
08-10-2009 08:24 PM
Profile PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: [Ask]RichEdit Control and Syntax Color
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.
08-10-2009 08:27 PM
Profile E-Mail PM Find Quote Report
Lén
Junior Member
**

Avatar

Posts: 16
34 / Male / Flag
Joined: Feb 2008
O.P. RE: [Ask]RichEdit Control and Syntax Color
could you give me an exemple please ? i'm not at ease with the MSDN help :D

08-10-2009 08:33 PM
Profile PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: [Ask]RichEdit Control and Syntax Color
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>


This post was edited on 08-11-2009 at 12:50 PM by matty.
08-11-2009 12:47 PM
Profile E-Mail PM Find Quote Report
Lén
Junior Member
**

Avatar

Posts: 16
34 / Male / Flag
Joined: Feb 2008
O.P.
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!).

This post was edited on 08-11-2009 at 04:48 PM by Lén.
08-11-2009 03:20 PM
Profile PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: [Ask]RichEdit Control and Syntax Color
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.
08-11-2009 04:59 PM
Profile E-Mail PM Find Quote Report
Lén
Junior Member
**

Avatar

Posts: 16
34 / Male / Flag
Joined: Feb 2008
O.P. RE: [Ask]RichEdit Control and Syntax Color
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.

This post was edited on 08-11-2009 at 06:31 PM by Lén.
08-11-2009 05:52 PM
Profile PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: [Ask]RichEdit Control and Syntax Color
Honestly this is really a horrible way of doing it. There is a "CodeEditControl" but it only supports JScript text highlighting.
08-11-2009 06:37 PM
Profile E-Mail PM Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« 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