_WinAPI_PostMessage + string

  • hallo ;)
    also zunächst das problem,
    ich möchte mit meinem programm, an ein anders programm einen text senden,
    aber nicht mit controlsend sondern mit postmessage!

    also hab ich mich mal schlau gemacht, im enlgischen forum habe ich ein beispiel für sendmessage gefunden, jedoch gehen damit nur nummern -_-
    @ MSDN lib hab ich folgendes gefunden:

    Spoiler anzeigen
    [autoit]

    #cs
    HANDLE WINAPI OpenProcess(
    __in DWORD dwDesiredAccess,
    __in BOOL bInheritHandle,
    __in DWORD dwProcessId
    );

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    The following table lists the process-specific access rights.

    [/autoit] [autoit][/autoit] [autoit]

    Value Meaning
    PROCESS_ALL_ACCESS All possible access rights for a process object.
    Windows Server 2003 and Windows XP/2000: The size of the PROCESS_ALL_ACCESS flag increased on Windows Server 2008 and Windows Vista. If an application compiled for Windows Server 2008 and Windows Vista is run on Windows Server 2003 or Windows XP/2000, the PROCESS_ALL_ACCESS flag is too large and the function specifying this flag fails with ERROR_ACCESS_DENIED. To avoid this problem, specify the minimum set of access rights required for the operation. If PROCESS_ALL_ACCESS must be used, set _WIN32_WINNT to the minimum operating system targeted by your application (for example, #define _WIN32_WINNT _WIN32_WINNT_WINXP). For more information, see Using the Windows Headers.
    PROCESS_CREATE_PROCESS (0x0080) Required to create a process.
    PROCESS_CREATE_THREAD (0x0002) Required to create a thread.
    PROCESS_DUP_HANDLE (0x0040) Required to duplicate a handle using DuplicateHandle.
    PROCESS_QUERY_INFORMATION (0x0400) Required to retrieve certain information about a process, such as its token, exit code, and priority class (see OpenProcessToken, GetExitCodeProcess, GetPriorityClass, and IsProcessInJob).
    PROCESS_QUERY_LIMITED_INFORMATION (0x1000) Required to retrieve certain information about a process (see QueryFullProcessImageName). A handle that has the PROCESS_QUERY_INFORMATION access right is automatically granted PROCESS_QUERY_LIMITED_INFORMATION.
    Windows Server 2003 and Windows XP/2000: This access right is not supported.
    PROCESS_SET_INFORMATION (0x0200) Required to set certain information about a process, such as its priority class (see SetPriorityClass).
    PROCESS_SET_QUOTA (0x0100) Required to set memory limits using SetProcessWorkingSetSize.
    PROCESS_SUSPEND_RESUME (0x0800) Required to suspend or resume a process.
    PROCESS_TERMINATE (0x0001) Required to terminate a process using TerminateProcess.
    PROCESS_VM_OPERATION (0x0008) Required to perform an operation on the address space of a process (see VirtualProtectEx and WriteProcessMemory).
    PROCESS_VM_READ (0x0010) Required to read memory in a process using ReadProcessMemory.
    PROCESS_VM_WRITE (0x0020) Required to write to memory in a process using WriteProcessMemory.
    SYNCHRONIZE (0x00100000L) Required to wait for the process to terminate using the wait functions.

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    bInheritHandle
    If this value is TRUE, processes created by this process will inherit the handle. Otherwise, the processes do not inherit this handle.

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    #ce
    $iaccess = bitor(0x0040,0x0010) ;) ich hab kein plan welches

    [/autoit] [autoit][/autoit] [autoit]

    $PID = ProcessExists("notepad.exe")
    $hproc = _WinAPI_OpenProcess($iaccess,false,$PID)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    #cs
    BOOL PostMessage(
    HWND hWnd,
    UINT Msg,
    WPARAM wParam,
    LPARAM lParam
    );

    [/autoit] [autoit][/autoit] [autoit]

    Parameters

    [/autoit] [autoit][/autoit] [autoit]

    hWnd
    [in]
    Microsoft Windows Vista and later. Message posting is subject to User Interface Privilege Isolation (UIPI). The thread of a process can post messages only to message queues of threads in processes of lesser or equal integrity level.

    [/autoit] [autoit][/autoit] [autoit]

    Handle to the window whose window procedure is to receive the message. The following values have special meanings.

    [/autoit] [autoit][/autoit] [autoit]

    HWND_BROADCAST
    The message is posted to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows. The message is not posted to child windows.
    NULL
    The function behaves like a call to PostThreadMessage with the dwThreadId parameter set to the identifier of the current thread.
    Msg
    [in] Specifies the message to be posted.
    wParam
    [in] Specifies additional message-specific information.
    lParam
    [in] Specifies additional message-specific information.

    [/autoit] [autoit][/autoit] [autoit]

    #ce

    [/autoit] [autoit][/autoit] [autoit]

    _WinAPI_PostMessage($hproc,"a",0,0) ; kp was die parameter machen ;)
    _WinAPI_CloseHandle($hproc)

    [/autoit]

    aber so funktioniert das ganze leider nicht -.-
    und irgendwie findet man hier im board nur die _winapi_processopen für memory read/write wobei da doch einfach nomadmemory.au3 gehen würd xD

    Einmal editiert, zuletzt von azunai (1. Juni 2008 um 21:34)

  • In Organize Includes wird es so gemacht: (mit SendMessage )

    Spoiler anzeigen
    [autoit]

    ; aus http://www.autoit.de/index.php?page…D=2659&pageNo=1
    GUICreate("") ; Es muss halt eine GUI geben :)
    GUIRegisterMsg($WM_COPYDATA, 'MY_WM_COPYDATA')
    ...
    ; Send command to SciTE
    Func SendSciTE_Command($My_Hwnd, $Scite_hwnd, $sCmd)
    $sCmd = ':' & $My_Dec_Hwnd & ':' & $sCmd
    ;ConsoleWrite('-->' & $sCmd & @LF)
    Local $CmdStruct = DllStructCreate('Char[' & StringLen($sCmd) + 1 & ']')
    DllStructSetData($CmdStruct, 1, $sCmd)
    Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr')
    DllStructSetData($COPYDATA, 1, 1)
    DllStructSetData($COPYDATA, 2, StringLen($sCmd) + 1)
    DllStructSetData($COPYDATA, 3, DllStructGetPtr($CmdStruct))
    DllCall('User32.dll', 'None', 'SendMessage', 'HWnd', $Scite_hwnd, _
    'Int', $WM_COPYDATA, 'HWnd', $My_Hwnd, _
    'Ptr', DllStructGetPtr($COPYDATA))
    EndFunc ;==>SendSciTE_Command

    [/autoit] [autoit][/autoit] [autoit]

    ; Received Data from SciTE
    Func MY_WM_COPYDATA($hWnd, $msg, $wParam, $lParam)
    Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr', $lParam)
    Local $SciTECmdLen = DllStructGetData($COPYDATA, 2)
    Local $CmdStruct = DllStructCreate('Char[255]', DllStructGetData($COPYDATA, 3))
    $SciTECmd = StringLeft(DllStructGetData($CmdStruct, 1), $SciTECmdLen)
    EndFunc ;==>MY_WM_COPYDATa

    [/autoit]


    Das kannst du doch so übernehmen in den Skripten. Du brauchst aber WindowHandles wie von GUICeate und WinGetHandle.
    //Edit: [Blockierte Grafik: http://friendsforever.foren-city.de/images/smiles/a084.gif]Das müsste mein 1000. Post sein :D
    Und ich habs net mal gemerkt ;(

    2 Mal editiert, zuletzt von progandy (2. Juni 2008 um 17:36)

  • So, hier allgemenigültig :) Incl Beispiel

    Spoiler anzeigen
    [autoit]

    #include <WIndowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $MyTitle = "GGUI"
    $otherTitle = "HHI"

    [/autoit] [autoit][/autoit] [autoit]

    ;##########################################
    ; Hier wird eine 2. GUI gestartet, damit man einfach testen kann Das Skript ist so ausgelegt, dass
    ; es 2 verschiedene Fenstertitel hat, je nachdem, ob das Skript mit Parameter ausgefufen wird
    If $CMDLINE[0] > 0 Then
    $MyTitle = "HHI"
    $otherTitle = "GGUI"
    Else
    ShellExecute(@ScriptFullPath,"2ndScript","","run")
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ;##########################################

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Global $COPYDATA_String ; Variable to Save CopyData

    [/autoit] [autoit][/autoit] [autoit]

    $GUI = GUICreate($MyTitle) ; Es muss halt eine GUI geben :)

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg($WM_COPYDATA, 'MY_WM_COPYDATA') ; Register GUIMessage

    [/autoit] [autoit][/autoit] [autoit]

    $GO = GUICtrlCreateButton("Send",100,100,200,60)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    WinWait($otherTitle) ; Auf das andere Fenster warten
    $Send_handle = WinGetHandle($otherTitle) ; Das Fnester-Handle holen

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    $msg = GUIGetMsg()
    If $msg = $GO Then
    _SendCopyDataString($GUI,$Send_handle,"Send String from "& $MyTitle & " To "& $otherTitle)
    ElseIf $msg = -3 Then
    Exit
    EndIf
    If $COPYDATA_String <> "" Then
    MsgBox(0, $MyTitle & "Received:" , $COPYDATA_String)
    $COPYDATA_String = ""
    EndIf
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    ; aus http://www.autoit.de/index.php?page…D=2659&pageNo=1
    ; Send string with WM_COPYDATA
    Func _SendCopyDataString($My_Hwnd, $Scite_hwnd, $sCmd)
    ;ConsoleWrite('-->' & $sCmd & @LF)
    Local $CmdStruct = DllStructCreate('Char[' & StringLen($sCmd) + 1 & ']')
    DllStructSetData($CmdStruct, 1, $sCmd)
    Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr')
    DllStructSetData($COPYDATA, 1, 1)
    DllStructSetData($COPYDATA, 2, StringLen($sCmd) + 1)
    DllStructSetData($COPYDATA, 3, DllStructGetPtr($CmdStruct))
    DllCall('User32.dll', 'None', 'SendMessage', 'HWnd', $Scite_hwnd, _
    'Int', $WM_COPYDATA, 'HWnd', $My_Hwnd, _
    'Ptr', DllStructGetPtr($COPYDATA))
    EndFunc ;==>SendSciTE_Command

    [/autoit] [autoit][/autoit] [autoit]

    ; Received Data from SciTE
    Func MY_WM_COPYDATA($hWnd, $msg, $wParam, $lParam)
    Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr', $lParam)
    Local $COPYDATA_StringLen = DllStructGetData($COPYDATA, 2)
    Local $CmdStruct = DllStructCreate('Char['&$COPYDATA_StringLen&']', DllStructGetData($COPYDATA, 3))
    $COPYDATA_String = StringLeft(DllStructGetData($CmdStruct, 1), $COPYDATA_StringLen)
    EndFunc ;==>MY_WM_COPYDATa

    [/autoit]
  • hm

    [autoit]

    dim $WM_COPYDATA

    [/autoit][autoit][/autoit][autoit]

    $GUI = GUICreate("blub") ; Es muss halt eine GUI geben :)
    GUIRegisterMsg($WM_COPYDATA, 'MY_WM_COPYDATA') ; Register GUIMessage

    [/autoit][autoit][/autoit][autoit]

    _SendCopyDataString($GUI,WinGetHandle("musik.txt - Editor"),"{enter}bla{enter}")

    [/autoit][autoit][/autoit][autoit][/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Func _SendCopyDataString($My_Hwnd, $Scite_hwnd, $sCmd)
    ;ConsoleWrite('-->' & $sCmd & @LF)
    Local $CmdStruct = DllStructCreate('Char[' & StringLen($sCmd) + 1 & ']')
    DllStructSetData($CmdStruct, 1, $sCmd)
    Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr')
    DllStructSetData($COPYDATA, 1, 1)
    DllStructSetData($COPYDATA, 2, StringLen($sCmd) + 1)
    DllStructSetData($COPYDATA, 3, DllStructGetPtr($CmdStruct))
    DllCall('User32.dll', 'None', 'SendMessage', 'HWnd', $Scite_hwnd, _
    'Int', $WM_COPYDATA, 'HWnd', $My_Hwnd, _
    'Ptr', DllStructGetPtr($COPYDATA))
    EndFunc

    Func MY_WM_COPYDATA($hWnd, $msg, $wParam, $lParam)
    Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr', $lParam)
    Local $COPYDATA_StringLen = DllStructGetData($COPYDATA, 2)
    Local $CmdStruct = DllStructCreate('Char['&$COPYDATA_StringLen&']', DllStructGetData($COPYDATA, 3))
    $COPYDATA_String = StringLeft(DllStructGetData($CmdStruct, 1), $COPYDATA_StringLen)
    EndFunc ;==>MY_WM_COPYDATa

    [/autoit]

    und warum geht das nun bitte nicht? xD

  • Ähm, dann musst du es wohl doch mit ControlSend machen.
    Es kommt auf das Programm an, ob es COPYDATA unterstützt. Der Editor tut das nicht :)

  • -.- xD
    ich such ja ne alternative zu copydata ;)
    daher ja _WinApi_PostMessage ;) nur ich weiß nicht wie ich das benutzten soll da ich keine hilfe/beispiele finde -_-

  • Welches Programm ist es denn? Mögliherweise lässt sich was senden, aber bei PostMessage/ SendMessage geht das nur, wenn das Ziel es auch unterstützt.

    Zitat


    also hab ich mich mal schlau gemacht, im enlgischen forum habe ich ein beispiel für sendmessage gefunden, jedoch gehen damit nur nummern -_-

    Welxhes Bsp? Kannst du mal den Link posten?

  • find den link nimmer, aber es hatte mit mem read zutun, dem zielprogramm wurde sozusagen einfach ne nummer gesendet welche dann zb ein A in das aktive feld schrieb

    jedoch ist das nicht sonderlich hilfreich gewesen -.-

    hat denn niemand auf der ganzen au3 welt jemals die befehler _winapi_postmessage() benutzt?????

  • So weit ich weiß, kann man mit PostMessage KEINEN Text senden und mit Sendmessage nur auf die angegebene Weise.

  • Ahh, so. Theroretisch sollte das so gehen:

    Spoiler anzeigen
    [autoit]

    Dim $Keys[0xFF+1]
    For $i = 1 To 0xFF
    $Chr = DllCall("user32.dll", "int", "MapVirtualKey", "int", $i, "int", 2)
    $Chr = StringLower(ChrW(BitAND($Chr[0], 0xFFFF)))
    $Keys[$i] = $Chr
    Next

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetVK($Chr)
    $Chr = String($Chr)
    For $i = 1 To 0xFF
    If $Keys[$i] = $Chr Then Return $i
    Next
    EndFunc
    Func _GetVKAsc($Asc)
    Return _GetVK(ChrW($Asc))
    EndFunc
    Func _VKDec2Hex($VK)
    If Not IsNumber($VK) Then Return SetError(1,0,0)
    Return Hex($VK,2)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    MsgBox(0, '', _VKDec2Hex(_GetVK("B")))

    [/autoit] [autoit][/autoit] [autoit]

    #include <WindowsConstants.au3>
    #include <WinAPI.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $hwnd = WinGetHandle("Unbenannt")
    $text = "hallo"
    $c = StringSplit($text,"")
    For $i = 1 To $c[0]
    _WinAPI_PostMessage($hwnd,$WM_KEYDOWN,_GetVK($c[$i]),0)
    ConsoleWrite(@error & @CRLF)
    Sleep(20)
    _WinAPI_PostMessage($hwnd,$WM_KEYUP,_GetVK($c[$i]),0)
    Sleep(20)
    Next

    [/autoit]
  • Console schreibt er @error, also Fehlermeldung 0 -> kein Fehler. Und ich weiß, dass es nicht geht. Aber Das war mal die 1:1 Übersetzung.

  • Meiner Meinung nach hätte das gehen sollen und ich habs erst nach dem Posten geteset :thumbdown: Und ih dachte dann, mein Rechner spinnt ;)