Jump to content
Sign in to follow this  

Send Controlmessages to a Window (not a AutoIt-Gui)

Recommended Posts

I want to comunicate with the Scintilla-Control in Notepad++.

The GUICtrl* Functions ar related only to AutoIt-Gui's, not to external Program-Windows.

ControlCommand() does not provide enought parameters (like various dll-calls, lparam, wparam, ...).

David Barrett once had suggested such a Function:


Is this possible, or forbidden for security-reasons or impossible by design?


Share this post

Link to post
Share on other sites

I want to build a helpertool for notepad++, to interact with, while possibly the computer is used too for other activities, so it is a bad idea (i think), to send keystrokes or use the clipboard. Thats why i want to use controlmessages.

At my first atempt notepad++ crashes, now ihave something, particular working, but i get no data back:

Global $NPPhwnd, $NPPselected

$NPPhwnd = WinGetHandle("[Active;CLASS:Notepad++]")
Local $ScintillaClassNameNN = ControlGetFocus($NPPhwnd)
Local $ScintillaHwnd = ControlGetHandle($NPPhwnd,"",$ScintillaClassNameNN)


    Local $iLen, $sBuf, $ret, $sText
    $iLen = DllCall("user32.dll", "long", "SendMessageW", "long", $Sci, "int", $SCI_GETSELTEXT, "int", 0, "int", 0)
    If @error Then Return -1
    $sBuf = DllStructCreate("char[" & $iLen[0] & "]")
    If @error Then Return -2
    ;DllStructSetData($sBuf, 1, "abcdefghijklmnopqrstuvwxyz")
    $ret = DllCall("user32.dll", "long", "SendMessageW", "long", $Sci, "int", $SCI_GETSELTEXT, "int", 0, "ptr", DllStructGetPtr($sBuf))
    If @error Then Return -3
    $sText = DllStructGetData($sBuf, 1)
    $sBuf = 0
    If @error Then Return -4
    Return $sText

Run it from nppExec after selecting some text:

"Path_to_AutoIt\AutoIt3.exe" /ErrorStdout "$(FULL_CURRENT_PATH)"

Returnvalue ($sText) is empty, should contain the selected text.

Edited by Raik

Share this post

Link to post
Share on other sites

It seems that some Scintilla-Messages do work only within the same Process, especially the ones, witch use structs. :(

Any idea about this?


Maybe i have to use WM_COPYDATA like this: https://autoit.de/index.php/Thread/6438-WinAPI-PostMessage-string/?postID=47622#post47622 ?

Edited by Raik

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  

  • Create New...