Jump to content

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:

http://permalink.gmane.org/gmane.comp.windows.autoit.user/17713

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

 

AutoIt-Syntaxsheme for Proton & Phase5 * Firefox Addons by me (resizable Textarea 0.1d) (docked JS-Console 0.1.1)

Link to comment
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
Global CONST $SCI_GETSELTEXT = 2161

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

ConsoleWrite(SCI_GETSELTEXT($ScintillaHwnd))

Func SCI_GETSELTEXT($Sci)
    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
EndFunc

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

AutoIt-Syntaxsheme for Proton & Phase5 * Firefox Addons by me (resizable Textarea 0.1d) (docked JS-Console 0.1.1)

Link to comment
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?

PS:

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

AutoIt-Syntaxsheme for Proton & Phase5 * Firefox Addons by me (resizable Textarea 0.1d) (docked JS-Console 0.1.1)

Link to comment
Share on other sites

  • 4 weeks later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...