[Ask]RichEdit Control and Syntax Color |
Author: |
Message: |
Lén
Junior Member
Posts: 16
35 / /
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 |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
Joined: Dec 2002
Status: Away
|
RE: [Ask]RichEdit Control and Syntax Color
|
|
08-10-2009 08:10 PM |
|
|
Lén
Junior Member
Posts: 16
35 / /
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 |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
Joined: Dec 2002
Status: Away
|
|
08-10-2009 08:27 PM |
|
|
Lén
Junior Member
Posts: 16
35 / /
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
|
|
08-10-2009 08:33 PM |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
Joined: Dec 2002
Status: Away
|
RE: [Ask]RichEdit Control and Syntax Color
js 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 |
|
|
Lén
Junior Member
Posts: 16
35 / /
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 |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
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 |
|
|
Lén
Junior Member
Posts: 16
35 / /
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=="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=="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 ???
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 |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
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 |
|
|
Pages: (2):
« First
[ 1 ]
2
»
Last »
|
|