Sign in to follow this  
Followers 0
Dolemite50

SendMessage with SciTE?

6 posts in this topic

Hello,

I am trying to send Scintilla key commands to SciTE but not having any luck. I have the SciLexer.dll in the scriptDir and think I have tried every combination:

#include <SendMessage.au3>
Opt("WinSearchChildren", 1)
Opt("WinTitleMatchMode", 4)
$hScite = WinGetHandle("classname=SciTEWindow")
$hSciteDirector = WinGetHandle("DirectorExtension")
Global Const $SCI_GETLINE=2153

Attempts -->

$sRet= _SendMessage($hScite, $SCI_GETLINE, 0, 0, 0)
$sRet= _SendMessage($hScite, $SCI_GETLINE)
$sRet= _SendMessage($hScite, 2153, 0, 0, 0)
$sRet= _SendMessage($hScite, 2153)

$sRet= _SendMessage($hSciteDirector, $SCI_GETLINE, 0, 0, 0)
$sRet= _SendMessage($hSciteDirector, $SCI_GETLINE)
$sRet= _SendMessage($hSciteDirector, 2153, 0, 0, 0)
$sRet= _SendMessage($$SciteDirector, 2153)

$sRet= _SendMessageA($hScite, $SCI_GETLINE, 0, 0, 0)
$sRet= _SendMessageA($hScite, $SCI_GETLINE)
$sRet= _SendMessageA($hScite, 2153, 0, 0, 0)
$sRet= _SendMessageA($hScite, 2153)

$sRet= _SendMessageA($hSciteDirector, $SCI_GETLINE, 0, 0, 0)
$sRet= _SendMessageA($hSciteDirector, $SCI_GETLINE)
$sRet= _SendMessageA($hSciteDirector, 2153, 0, 0, 0)
$sRet= _SendMessageA($hSciteDirector, 2153)

ConsoleWrite($sRet & @CRLF); --Returns 0 for all attempts

When I set the return value to 1 or 2 it returns the handles and msg fine but I've been unable to get any code to work.

I've checked into _SciLexer.au3 and it's pretty slick but I could only get the commands to work on the user-created editor.

I tried to break down it's functions and recreate the DllCalls they are using with the same combinations but still no love. I assume that my problem is with the hwnd variable I am using because it looks like the _SciLexer UDF is using the return from a createWinEx func rather than scite's hwnd. I got desperate and attempted the same:

Local $wp = 0, $lp = 0
Global $user32 = DllOpen("user32.dll")
Global $SciDLL = DllOpen("SciLexer.dll"); ALSO --> Global $SciDLL = DllOpen(@ScriptDir & "\SciLexer.dll")

; (swapping $hScite and $hSciteDirector):
$ret = DllCall($user32, "long", "GetWindowLong", "hwnd", $hSciteDirector, "int", -6)
$sRet1= DllCall($SciDLL, "long", "SendMessage", "long", $ret[0], "int", $SCI_GETLINE, "int", $wp, "int", $lp)
$sRet2= _SendMessage($ret[0], $SCI_GETLINE)
$sRet3= _SendMessageA($ret[0], $SCI_GETLINE)

ConsoleWrite($ret[0] & @CRLF); --> 4194304
ConsoleWrite($ret[1] & @CRLF); --> 0x01B40134

ConsoleWrite($sRet1 & @CRLF); --> 0
ConsoleWrite($sRet2 & @CRLF); --> 0
ConsoleWrite($sRet3 & @CRLF); --> 0

DllClose("user32.dll")
DllClose("SciLexer.dll")
DllClose(@ScriptDir & "\SciLexer.dll")
...

I'd show a few more desperate attempts but I'm probably about to run the server out of ink.

Any help?

Thanks a lot!

I'm at a loss, any help would be much appreciated.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You can only send messages to the control it self, not just to the entire window.

$hScite = WinGetHandle("classname=SciTEWindow")

Returns the handle to the whole window.

Also, opening the scilexer.dll and doing nothing with it, doesnt matter.

btw, you dont have to open the dll, because your window doesn't own the control.

Edited by Kip

Share this post


Link to post
Share on other sites

Hello,

I am trying to send Scintilla key commands to SciTE but not having any luck. I have the SciLexer.dll in the scriptDir and think I have tried every combination:

I assume you have SciTE open with a text file you want to get information from. The first thing is to get the handle to the editor something like this

opt("WinTitleMatchMode",2)
$hScite = ControlGetHandle("SciTE [","","[CLASS:Scintilla;INSTANCE:1]");

Then if you want to get the text of a particular line you have a problem. You can find the length of a line by sending a message. I don't see how you can get the line the way you might think you could. To get the text of a line there is a message $SCI_GETLINE, which you know, but you have to pass it the line number (first is 0) and the address of a buffer where it can write the result. If the editor is part of your program this is not a problem, but since it isn't (if I understand what you are trying to do) then the program which has the editor cannot write to the memory owned by your program. If you are communicating with Scite then I suggest you read the SciTE-LUA interface i n SciTE help. I had a quick look and it would seem that to get the text of a line the process would be to mark the line as selected then send a message to copy that text to the clipboard and then you can get that text.

If I'm off track just tell me, or if what I say is wrong I'm sure someone will tell me, and if I don't make sense then let me know that as well :)


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Thanks guys!

I'm sorry that it's taken me awhile to get back to this post. I think I see what I need to do now, target the control instead of the sciteHnd or Director's.

I'm looking forward to trying it out and I'll let you know how it goes.

Thanks again!

Share this post


Link to post
Share on other sites

Something to play with: ( You need scilexer.au3 )

; NOTICE: I haver placed the following line in SciLexer.au3 to make it 
; behave with the latest stable version of AutoIt:=
; #include <WindowsConstants.au3> ;Failed on latest release (3.3.0,0) without it 

#include <SendMessage.au3>
#include <_SciLexer.au3>
_Main()
func dbg($msg, $erl=@ScriptLineNumber, $error=@error, $extended=@extended)
    ConsoleWrite('(' & $erl & ') (' & $error & '(' & $extended & ')' & $msg & @CRLF)
EndFunc
Func _Main()
    Opt("WinTitleMatchMode", 4)
    $hwndctl = ControlGetHandle("[CLASS:SciTEWindow]", "", "Scintilla1")
    If not $hwndctl <> 0 then dbg("ERROR: $hwndctl:=" & $hwndctl)   
    dbg("Sci_VisibleLines():=" & Sci_VisibleLines($hwndctl))
    
    ; Getting text accros the process boundary is dangerous and did not work
    ; with this implementation of Sci_getText
    ;dbg("Crashing?")
    ;sleep(2000)
    ;CRASHING dbg("Sci_getText:=" & @crlf & Sci_getText($hwndctl))
    
    dbg("Sci_GetLenght():=" & Sci_GetLenght($hwndctl))
    
EndFunc

My output when testing against a scite window with the sample code:

>Running:(3.3.0.0):C:\Program Files\AutoIt3\autoit3.exe "G:\tools\autoit\udfs\Test-scintilla.au3"   
(21) (0(0)Sci_VisibleLines():=30
(27) (0(0)Sci_GetLenght():=1034
+>21:18:26 AutoIT3.exe ended.rc:0
+>21:18:27 AutoIt3Wrapper Finished
>Exit code: 0   Time: 5.065

Share this post


Link to post
Share on other sites

here are the implementaions of GetText / SetText to use accross process boundaries:

http://www.autoitscript.com/forum/index.php?showtopic=89199

It's easier with ControlSetText / GetText, just look at Jos' post: http://www.autoitscript.com/forum/index.ph...st&p=641310


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0