Mouseclick im richtigen Fenster - WindowInfo vs. WindowSpy

  • Hallo all

    ich versuche gerade einen Text (Adresse) über Wordpad auszudrucken
    weil ich mit den Autoitbefehlen (ich wollte die Schriftgröße usw ändern) nicht weitergekommen bin
    habe ich mir gedacht ich öffne einen wordpadtext und ändere über Mouseclick.

    Öffnen geht
    aber dann klickt die Mouse völlig woanders hin und ignoriert das Wordpadfenster
    Was habe ich da übersehen?

    Spoiler anzeigen

    Run("C:\Program Files\Windows NT\Accessories\wordpad.exe")
    WinActivate ( "Dokument - WordPad" )
    WinMove ( "Dokument - WordPad","", 0, 100 , 800 , 600 )
    Sleep (1000)
    Send ('^o')
    Sleep(500)
    Send ("AdressAufkleber")
    SEND (".")
    Send ("RTF")
    Send ("{TAB}")
    Send ("{TAB}")
    Send ("{ENTER}")
    WinActivate ( "AdressAufkleber - WordPad" )
    WinWaitActive ( "AdressAufkleber - WordPad" )

    MouseMove(250,250) ;ohne Sinn nur ins Wordpadfenster geclickt
    MouseClick ("left",230,50); hier auch nur zum Probieren
    Sleep(3000)
    MouseClick ("left",111,45)
    Sleep(3000)
    ;Send ("ABS:" ,1 )
    ;Send ("{SPACE}")
    ;Send ($Absender)
    ;Send ("{SPACE}")
    ;Send ($PDST)
    ;Send ("{SPACE}")
    ;Send ($PDSTNR )
    ;Send ("{ENTER}")
    MouseClick ("left",112,75)
    Sleep(3000)
    ; Send ($VORNAME)
    ; Send ("{SPACE}")
    ; Send ($NACHNAME)
    ; Send ("{ENTER}")
    MouseClick ("left",112,118)
    Sleep(3000)
    ;Send ($STRASSE)
    ;Send ("{ENTER}")
    MouseClick ("left",112,156 )
    Sleep(3000)
    ;Send ($PLZ)
    ;Send ("{SPACE}")
    ;Send ($ORT)
    ;Send ("{ENTER}")


    Besser wär natürlich eine Lösung ohne Wordpad aufzurufen habe aber noch nichts finden können

    viele Grüße
    Jörg

    Einmal editiert, zuletzt von joerg8051 (20. August 2011 um 11:10)

  • Hallo Hugbert,

    Code
    ControlClick

    hat noch nicht geholfen, an der Stelle wo das Programm hinklicken soll, ist auch gar kein Control
    da ist einfach nur eine Textzeile.

    die Befehle zB. MouseClick ("left",111,45) werden an den Bildschirmkoordinaten ausgeführt und nicht wie gewünscht nach den Fensterkoordinaten, also Clickt der obere Befehl etwas völlig anderes.

    Eine Lösung ohne die Klickerei wär mir noch lieber
    so soll das Ergebnis gedruckt werden:

    ABSENDER: der fröhliche Lieferer blabla
    PAUL TEST
    TESTGASSE 12
    12345 Probierstadt

    viele Grüße
    jörg

  • Hallo Hellboy,

    eigentlich nur einen Adressaufkleber ausdrucken mit verschiedenen Schriftgrößen.

    Mir viel nur ein Wordpad zu öffnen - klappt auch
    einen bestehenden Text zuöffnen - klappt auch

    an bestimmte Stellen in den Text zu klicken - klappt nicht
    um dann mit send "text" den bestehenden Text zu überschreiben.

    Wenn man per Hand an die Textstellen klickt verändert sich der Text und man überschreibt ihn
    die Werte habe ich mir aus Windowinfo ausgelesen nur die Mouseclicks landen nicht da wo sie sollen
    trotz winactivate

    viele Grüße
    jörg

  • Es gibt mehrere Möglichkeiten auf WordPad zu verzichten. Du könntest zum Beispiel ein IE oder RichEdit-Control erzeugen und daraus drucken.

    Anbei ein Beispiel für RichEdit (Achtung: druckt sofort auf dem Standartdrucker)

    Spoiler anzeigen
    [autoit]


    #include <GuiRichEdit.au3>

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

    Global $sZeile[4] = ["ABSENDER: der fröhliche Lieferer blabla", "PAUL TEST", "TESTGASSE 12", "12345 Probierstadt"]

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

    ConsoleWrite(Main() & @CRLF)

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

    Func Main()
    Local $hGui, $hRichEdit, $iMsg, $sPrint
    $hGui = GUICreate("Richedit", 320, 240)
    $hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 10, 10, 300, 220)
    _GUICtrlRichEdit_SetCharAttributes($hRichEdit, "+un")
    _GUICtrlRichEdit_SetFont($hRichEdit, 10)
    _GUICtrlRichEdit_AppendText($hRichEdit, $sZeile[0] & @CRLF)
    _GUICtrlRichEdit_SetCharAttributes($hRichEdit, "-un")
    For $i = 1 To 3
    _GUICtrlRichEdit_SetFont($hRichEdit, 14)
    _GUICtrlRichEdit_AppendText($hRichEdit, $sZeile[$i] & @CRLF)
    Next
    GUISetState() ; löschen wenn Fester unsichtbar bleiben soll
    $sPrint = _RTF_Print(_GetDC_PrinterNoDialog(), $hRichEdit, "Titel")
    GUIDelete()
    Return $sPrint
    EndFunc ;==>Main

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

    Func _GetDC_PrinterNoDialog()
    Local $strcPD, $bRet, $hDC
    Local $PDtags = "align 1;DWORD lStructSize;HWND hwndOwner;handle hDevMode;handle hDevNames;handle hDC;DWORD Flags;WORD nFromPage;WORD nToPage;" & _
    "WORD nMinPage;WORD nMaxPage;WORD nCopies;handle hInstance;LPARAM lCustData;ptr lpfnPrintHook;ptr lpfnSetupHook;ptr lpPrintTemplateName;" & _
    "ptr lpSetupTemplateName;handle hPrintTemplate;handle hSetupTemplate"
    $strcPD = DllStructCreate($PDtags)
    DllStructSetData($strcPD, "lStructSize", DllStructGetSize($strcPD))
    DllStructSetData($strcPD, "Flags", 0x100 + 0x40 + 0x400)
    $bRet = DllCall("Comdlg32.dll", "int", "PrintDlgW", "ptr", DllStructGetPtr($strcPD))
    If $bRet[0] Then Return DllStructGetData($strcPD, "hDC")
    Return 0
    EndFunc ;==>_GetDC_PrinterNoDialog

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

    Func _RTF_Print($hPrintDc, $hwnd, $DocTitle, $LeftMinMrgn = 1, $TopMinMrgn = 1, $RightMinMrgn = 1, $BottomMinMrgn = 1)
    $TopMinMrgn *= 567
    $LeftMinMrgn *= 567
    $RightMinMrgn *= 567
    $BottomMinMrgn *= 567

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

    $dotInchX = _WinAPI_GetDeviceCaps($hPrintDc, 88);-----Const LOGPIXELSX = 88
    $dotInchY = _WinAPI_GetDeviceCaps($hPrintDc, 90);-----Const LOGPIXELSY = 90

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

    $PageW = _WinAPI_GetDeviceCaps($hPrintDc, 8);-----Const HORZRES= 8
    $PageH = _WinAPI_GetDeviceCaps($hPrintDc, 10);-----Const VERTRES = 10
    $PaperW = _WinAPI_GetDeviceCaps($hPrintDc, 110) ;-----Const PHYSICALWIDTH = 110
    $PaperH = _WinAPI_GetDeviceCaps($hPrintDc, 111) ;-----Const PHYSICALHEIGHT = 111

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

    $OffSetX = _WinAPI_GetDeviceCaps($hPrintDc, 112) ;-----Const PHYSICALOFFSETX = 112
    $OffSetY = _WinAPI_GetDeviceCaps($hPrintDc, 113);-----Const PHYSICALOFFSETY = 113
    $RightMrgn = $PaperW - $PageW - $OffSetX
    $BottomMrgn = $PaperH - $PageH - $OffSetY

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

    $TwipsInchX = $dotInchX / 1440;-----convert dots to twips [per inch]
    $TwipsInchY = $dotInchY / 1440;-----convert dots to twips [per inch]

    ;--------convert all measurments to twips
    $OffSetX = $OffSetX / $TwipsInchX ;-----convert Left dots to twips
    $OffSetY = $OffSetY / $TwipsInchY ;-----convert Left dots to twips
    $PageW = $PageW / $TwipsInchX ;-----convert Right dots to twips
    $PageH = $PageH / $TwipsInchY ;-----convert Right dots to twips
    $PaperW = $PaperW / $TwipsInchX ;-----convert Paper Width dots to twips
    $PaperH = $PaperH / $TwipsInchY ;-----convert Paper Width dots to twips

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

    ;----------Set the margins and keep everything in the printable area
    $Left1 = $LeftMinMrgn - $OffSetX
    If $Left1 < 0 Then $Left1 = 0;-----dont print before printable area starts

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

    $Top1 = $TopMinMrgn - $OffSetY
    If $Top1 < 0 Then $Top1 = 0;-----dont print before printable area starts

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

    $Right1 = $RightMinMrgn - $RightMrgn
    If $Right1 < 0 Then $Right1 = 0;-----dont print after printable area ends
    $Right1 = $PageW - $Right1 ;+$Left1;- $OffSetX

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

    $Bottom1 = $BottomMinMrgn - $BottomMrgn
    If $Bottom1 < 0 Then $Bottom1 = 0;-----dont print after printable area ends
    $Bottom1 = $PageH - $Bottom1;+$Top1

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

    $z = _SendMessage($hwnd, $EM_SETTARGETDEVICE, 0);---0=wrap----anything else is 1 char per page!!!!!
    If $z = 0 Then Return 'Cant find RichEdit Control'

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

    If _GUICtrlRichEdit_GetTextLength($hwnd) < 1 Then Return 'Nothing to Print.'
    ;---------must have a selection on the richEdit control---------------
    _SendMessage($hwnd, $EM_SETSEL, 0, -1);--ok----select all

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

    $pgTags = "int Left1;int Top1;int Right1;int Bottom1;int Left2;int Top2;int Right2;int Bottom2;"
    $rgTags = "LONG cpMin;LONG cpMax"
    $dcHTags = "HANDLE hdc;HANDLE hdcTarget;"
    ;------------create a structure for the printed page
    $strcPg = DllStructCreate($dcHTags & $pgTags & $rgTags)
    DllStructSetData($strcPg, "hdc", $hPrintDc);-------------printer
    DllStructSetData($strcPg, "Left1", $Left1);-----twip--------printer
    DllStructSetData($strcPg, "Right1", $Right1);-----twip--------printer
    DllStructSetData($strcPg, "Top1", $Top1);-----twip--------printer
    DllStructSetData($strcPg, "Bottom1", $Bottom1);-----twip--------printer

    ;---------get the pointer to all that will be printed??? {I think????????}
    $a = DllStructGetPtr($strcPg) + DllStructGetSize(DllStructCreate($dcHTags & $pgTags))
    ;-----------use this pointer-----------
    _SendMessage($hwnd, $EM_EXGETSEL, 0, $a)
    ;-----------find the last char of the document to be printed
    $cpMax = DllStructGetData($strcPg, "cpMax")
    ;-----------set the 1st page start char-----------
    $cpMin = 0
    $cpMin2 = -1
    ;-----------------------------------------------------------------------------------
    ;--------create a Document structure for the print job title
    $strDocNm = DllStructCreate("char DocName[" & StringLen($DocTitle & Chr(0)) & "]")
    DllStructSetData($strDocNm, "DocName", $DocTitle & Chr(0))
    $strDoc = DllStructCreate("int Size;ptr DocName;ptr Output;ptr Datatype;dword Type")
    DllStructSetData($strDoc, "Size", DllStructGetSize($strDoc))
    ;---------------insert the document name structure into the document structure
    DllStructSetData($strDoc, "DocName", DllStructGetPtr($strDocNm))
    DllCall("gdi32.dll", "long", "StartDoc", "hwnd", $hPrintDc, "ptr", DllStructGetPtr($strDoc))
    ;-----------------------------------------------------------------------------------
    ;-----------make a loop to format each printed page and exit when-----------
    ;-----$cpMin reaches the $cpMax
    ;-----$cpMin is less than 0---{I have seen -1 but I forget when}---
    ;----ALSO-- ExitLoop if $cpMin = $cpMin 2---if it stops finding the start of next page
    While $cpMax > $cpMin And $cpMin > -1
    ;-----------start a new page-----------
    $StartPage = DllCall("Gdi32.dll", "int", "StartPage", "HANDLE", $hPrintDc)
    ;-----------increment page the count-----------
    ;-----------if not done now it will exit the loop before counting the last page
    ; ;-----------get the 1st char of the next page, {but how does it work ???}
    $cpMin2 = $cpMin
    $cpMin = _SendMessage($hwnd, $EM_FORMATRANGE, True, DllStructGetPtr($strcPg))
    ;----ExitLoop when $cpMin = $cpMin 2---just in case it stops finding the start of next page
    If $cpMin2 = $cpMin Then ExitLoop;---get out of loop before more pages are added
    ; ;-----------set the next page start char-----------
    DllStructSetData($strcPg, "cpMin", $cpMin)
    ;------this sends it to the printer
    $EndPage = DllCall("Gdi32.dll", "int", "EndPage", "HANDLE", $hPrintDc)
    ;-----------end the page and loop again for the next page until the end of document
    WEnd
    _SendMessage($hwnd, $EM_FORMATRANGE, False, 0)
    If $EndPage[0] Then
    $r = 'Sent to the printer.'
    DllCall("Gdi32.dll", "int", "EndDoc", "HANDLE", $hPrintDc)
    Else
    $r = 'Printing aborted.'
    DllCall("Gdi32.dll", "int", "AbortDoc", "HANDLE", $hPrintDc)
    EndIf
    Return $r
    EndFunc ;==>_RTF_Print

    [/autoit]


    Die Druckfunktion ist von hier.

  • Dann wird dir das da wohl nicht helfen, aber ich wollte mir die Richedits sowieso mal ansehen, vielleicht wäre eine eigene GUI mit Druckfunktion ja vielleicht doch eine Alternative für dich:

    Spoiler anzeigen
    [autoit]


    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GuiRichEdit.au3>

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

    $GUI = GUICreate("Form1", 625, 445, 192, 124)
    $RichEdit = _GUICtrlRichEdit_Create($Gui, "This is a test.", 120, 104, 417, 225, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    _GUICtrlRichEdit_AutoDetectURL($RichEdit,True)
    _GUICtrlRichEdit_CanPaste($RichEdit)
    _GUICtrlRichEdit_CanRedo($RichEdit)
    _GUICtrlRichEdit_CanUndo($RichEdit)

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

    $ButtonK = GUICtrlCreateButton("Schrift kleiner", 100, 376, 75, 25, $WS_GROUP)
    $ButtonG = GUICtrlCreateButton("Schrift größer", 200, 376, 75, 25, $WS_GROUP)
    $ButtonU = GUICtrlCreateButton("U", 300, 376, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    case $ButtonK
    _GUICtrlRichEdit_ChangeFontSize($RichEdit, -1)
    case $ButtonG
    _GUICtrlRichEdit_ChangeFontSize($RichEdit, +1)
    case $ButtonU
    _GUICtrlRichEdit_SetCharAttributes($RichEdit, "+un" , True)
    EndSwitch
    WEnd

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

    EDIT: Na da hatten wir wohl den selben Gedanken, wobei dein Script wohl etwas umfangreicher und brauchbarer ist ^^

  • Hallo
    zwischendurch erstmal Dank für Eure prompte Hilfe
    ich versuche mal alle auszuprobieren
    aber schon bei der ersten Idee ist nicht mit mal eben getan!

    Meine Daten kommen in dieser Form von meinem Script:

    Spoiler anzeigen


    Dim $Absender
    Dim $VORNAME = "Vorname"
    Dim $NACHNAME
    Dim $STRASSE ;mit Hausnummer
    Dim $PLZ
    Dim $ORT


    du muß ich erstmal begreifen wie es in dem Vorschlag weitergeht:

    Code
    Global $sZeile[4] = [ $Absender, $VORNAME, $NACHNAME, $STRASSE,$PLZ, $ORT ]

    ich probiere mal daran herum
    viele Grüße
    jörg

  • Schau dir WinGetTitel und WinGetPosition und WinGetCaretPosition an, mit denen gehts.
    Bin mir sicher, da ich auch bots erstelle( ich erstelle bots, aber frage hier nicht danach!) und deshalb bei einigen Fenstern damit arbeite.

  • Hallo
    ich habe den script von Ahnungslos etwas angepaßt und schon geht es, super.
    weil ich kein @space gefunden habe habe ich eben ein " " gesendet, geht auch.


    Spoiler anzeigen

    Global $sZeile[6] = [$Absender, $VORNAME, $NACHNAME, $STRASSE,$PLZ, $ORT ]

    ;ConsoleWrite(Main() & @CRLF)

    ;Func Main()
    Local $hGui, $hRichEdit, $iMsg, $sPrint
    $hGui = GUICreate("Richedit", 320, 240)
    $hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 10, 10, 300, 220)
    _GUICtrlRichEdit_SetCharAttributes($hRichEdit, "+un")
    _GUICtrlRichEdit_SetFont($hRichEdit, 10)
    _GUICtrlRichEdit_AppendText($hRichEdit, $sZeile[0] & @CRLF)
    _GUICtrlRichEdit_SetCharAttributes($hRichEdit, "-un")
    ;etwas anders Formatiert
    _GUICtrlRichEdit_SetFont($hRichEdit, 14)
    _GUICtrlRichEdit_AppendText($hRichEdit, $sZeile[1] )
    _GUICtrlRichEdit_SetFont($hRichEdit, 14)
    _GUICtrlRichEdit_AppendText($hRichEdit, " " )
    _GUICtrlRichEdit_SetFont($hRichEdit, 14)
    _GUICtrlRichEdit_AppendText($hRichEdit, $sZeile[2] & @CRLF)
    _GUICtrlRichEdit_SetFont($hRichEdit, 14)
    _GUICtrlRichEdit_AppendText($hRichEdit, $sZeile[3] & @CRLF)
    _GUICtrlRichEdit_SetFont($hRichEdit, 14)
    _GUICtrlRichEdit_AppendText($hRichEdit, $sZeile[4])
    _GUICtrlRichEdit_SetFont($hRichEdit, 14)
    _GUICtrlRichEdit_AppendText($hRichEdit, " " )
    _GUICtrlRichEdit_SetFont($hRichEdit, 14)
    _GUICtrlRichEdit_AppendText($hRichEdit, $sZeile[5] & @CRLF)

    GUISetState() ; löschen wenn Fester unsichtbar bleiben soll
    $sPrint = _RTF_Print(_GetDC_PrinterNoDialog(), $hRichEdit, "Titel")
    Sleep(9000)
    GUIDelete()
    Return $sPrint
    EndFunc ;==>Main

    Func _GetDC_PrinterNoDialog()
    Local $strcPD, $bRet, $hDC
    Local $PDtags = "align 1;DWORD lStructSize;HWND hwndOwner;handle hDevMode;handle hDevNames;handle hDC;DWORD Flags;WORD nFromPage;WORD nToPage;" & _
    "WORD nMinPage;WORD nMaxPage;WORD nCopies;handle hInstance;LPARAM lCustData;ptr lpfnPrintHook;ptr lpfnSetupHook;ptr lpPrintTemplateName;" & _
    "ptr lpSetupTemplateName;handle hPrintTemplate;handle hSetupTemplate"
    $strcPD = DllStructCreate($PDtags)
    DllStructSetData($strcPD, "lStructSize", DllStructGetSize($strcPD))
    DllStructSetData($strcPD, "Flags", 0x100 + 0x40 + 0x400)
    $bRet = DllCall("Comdlg32.dll", "int", "PrintDlgW", "ptr", DllStructGetPtr($strcPD))
    If $bRet[0] Then Return DllStructGetData($strcPD, "hDC")
    Return 0
    EndFunc ;==>_GetDC_PrinterNoDialog

    Func _RTF_Print($hPrintDc, $hwnd, $DocTitle, $LeftMinMrgn = 1, $TopMinMrgn = 1, $RightMinMrgn = 1, $BottomMinMrgn = 1)
    $TopMinMrgn *= 567
    $LeftMinMrgn *= 567
    $RightMinMrgn *= 567
    $BottomMinMrgn *= 567

    $dotInchX = _WinAPI_GetDeviceCaps($hPrintDc, 88);-----Const LOGPIXELSX = 88
    $dotInchY = _WinAPI_GetDeviceCaps($hPrintDc, 90);-----Const LOGPIXELSY = 90

    $PageW = _WinAPI_GetDeviceCaps($hPrintDc, 8);-----Const HORZRES= 8
    $PageH = _WinAPI_GetDeviceCaps($hPrintDc, 10);-----Const VERTRES = 10
    $PaperW = _WinAPI_GetDeviceCaps($hPrintDc, 110) ;-----Const PHYSICALWIDTH = 110
    $PaperH = _WinAPI_GetDeviceCaps($hPrintDc, 111) ;-----Const PHYSICALHEIGHT = 111

    $OffSetX = _WinAPI_GetDeviceCaps($hPrintDc, 112) ;-----Const PHYSICALOFFSETX = 112
    $OffSetY = _WinAPI_GetDeviceCaps($hPrintDc, 113);-----Const PHYSICALOFFSETY = 113
    $RightMrgn = $PaperW - $PageW - $OffSetX
    $BottomMrgn = $PaperH - $PageH - $OffSetY

    $TwipsInchX = $dotInchX / 1440;-----convert dots to twips [per inch]
    $TwipsInchY = $dotInchY / 1440;-----convert dots to twips [per inch]

    ;--------convert all measurments to twips
    $OffSetX = $OffSetX / $TwipsInchX ;-----convert Left dots to twips
    $OffSetY = $OffSetY / $TwipsInchY ;-----convert Left dots to twips
    $PageW = $PageW / $TwipsInchX ;-----convert Right dots to twips
    $PageH = $PageH / $TwipsInchY ;-----convert Right dots to twips
    $PaperW = $PaperW / $TwipsInchX ;-----convert Paper Width dots to twips
    $PaperH = $PaperH / $TwipsInchY ;-----convert Paper Width dots to twips

    ;----------Set the margins and keep everything in the printable area
    $Left1 = $LeftMinMrgn - $OffSetX
    If $Left1 < 0 Then $Left1 = 0;-----dont print before printable area starts

    $Top1 = $TopMinMrgn - $OffSetY
    If $Top1 < 0 Then $Top1 = 0;-----dont print before printable area starts

    $Right1 = $RightMinMrgn - $RightMrgn
    If $Right1 < 0 Then $Right1 = 0;-----dont print after printable area ends
    $Right1 = $PageW - $Right1 ;+$Left1;- $OffSetX

    $Bottom1 = $BottomMinMrgn - $BottomMrgn
    If $Bottom1 < 0 Then $Bottom1 = 0;-----dont print after printable area ends
    $Bottom1 = $PageH - $Bottom1;+$Top1

    $z = _SendMessage($hwnd, $EM_SETTARGETDEVICE, 0);---0=wrap----anything else is 1 char per page!!!!!
    If $z = 0 Then Return 'Cant find RichEdit Control'

    If _GUICtrlRichEdit_GetTextLength($hwnd) < 1 Then Return 'Nothing to Print.'
    ;---------must have a selection on the richEdit control---------------
    _SendMessage($hwnd, $EM_SETSEL, 0, -1);--ok----select all

    $pgTags = "int Left1;int Top1;int Right1;int Bottom1;int Left2;int Top2;int Right2;int Bottom2;"
    $rgTags = "LONG cpMin;LONG cpMax"
    $dcHTags = "HANDLE hdc;HANDLE hdcTarget;"
    ;------------create a structure for the printed page
    $strcPg = DllStructCreate($dcHTags & $pgTags & $rgTags)
    DllStructSetData($strcPg, "hdc", $hPrintDc);-------------printer
    DllStructSetData($strcPg, "Left1", $Left1);-----twip--------printer
    DllStructSetData($strcPg, "Right1", $Right1);-----twip--------printer
    DllStructSetData($strcPg, "Top1", $Top1);-----twip--------printer
    DllStructSetData($strcPg, "Bottom1", $Bottom1);-----twip--------printer

    ;---------get the pointer to all that will be printed??? {I think????????}
    $a = DllStructGetPtr($strcPg) + DllStructGetSize(DllStructCreate($dcHTags & $pgTags))
    ;-----------use this pointer-----------
    _SendMessage($hwnd, $EM_EXGETSEL, 0, $a)
    ;-----------find the last char of the document to be printed
    $cpMax = DllStructGetData($strcPg, "cpMax")
    ;-----------set the 1st page start char-----------
    $cpMin = 0
    $cpMin2 = -1
    ;-----------------------------------------------------------------------------------
    ;--------create a Document structure for the print job title
    $strDocNm = DllStructCreate("char DocName[" & StringLen($DocTitle & Chr(0)) & "]")
    DllStructSetData($strDocNm, "DocName", $DocTitle & Chr(0))
    $strDoc = DllStructCreate("int Size;ptr DocName;ptr Output;ptr Datatype;dword Type")
    DllStructSetData($strDoc, "Size", DllStructGetSize($strDoc))
    ;---------------insert the document name structure into the document structure
    DllStructSetData($strDoc, "DocName", DllStructGetPtr($strDocNm))
    DllCall("gdi32.dll", "long", "StartDoc", "hwnd", $hPrintDc, "ptr", DllStructGetPtr($strDoc))
    ;-----------------------------------------------------------------------------------
    ;-----------make a loop to format each printed page and exit when-----------
    ;-----$cpMin reaches the $cpMax
    ;-----$cpMin is less than 0---{I have seen -1 but I forget when}---
    ;----ALSO-- ExitLoop if $cpMin = $cpMin 2---if it stops finding the start of next page
    While $cpMax > $cpMin And $cpMin > -1
    ;-----------start a new page-----------
    $StartPage = DllCall("Gdi32.dll", "int", "StartPage", "HANDLE", $hPrintDc)
    ;-----------increment page the count-----------
    ;-----------if not done now it will exit the loop before counting the last page
    ; ;-----------get the 1st char of the next page, {but how does it work ???}
    $cpMin2 = $cpMin
    $cpMin = _SendMessage($hwnd, $EM_FORMATRANGE, True, DllStructGetPtr($strcPg))
    ;----ExitLoop when $cpMin = $cpMin 2---just in case it stops finding the start of next page
    If $cpMin2 = $cpMin Then ExitLoop;---get out of loop before more pages are added
    ; ;-----------set the next page start char-----------
    DllStructSetData($strcPg, "cpMin", $cpMin)
    ;------this sends it to the printer
    $EndPage = DllCall("Gdi32.dll", "int", "EndPage", "HANDLE", $hPrintDc)
    ;-----------end the page and loop again for the next page until the end of document
    WEnd
    _SendMessage($hwnd, $EM_FORMATRANGE, False, 0)
    If $EndPage[0] Then
    $r = 'Sent to the printer.'
    DllCall("Gdi32.dll", "int", "EndDoc", "HANDLE", $hPrintDc)
    Else
    $r = 'Printing aborted.'
    DllCall("Gdi32.dll", "int", "AbortDoc", "HANDLE", $hPrintDc)
    EndIf
    Return $r
    EndFunc ;==>_RTF_Print


    Jetzt probier ich noch den Vorschlag von Autoitnoob aus falls ich doch mal den wordpad brauche.


    viele Grüße
    jörg

  • Hallo All
    ich glaube ich habe jetzt die Fehlerquelle, aber ich verstehe sie nicht.

    Autoit Window Info gibt mir die Koordinaten 234 , 259 also verwende ich

    Mouseclick ("left", 234, 259) und klicke völlig daneben

    erst Mouseclick ("left", 236,305) trifft den Punkt

    Auch wenn ich das Fenster mit winmove auf 0,0 bringe

    Autoit window spy gibt als Koordinaten für den gleichen Punkt (wo WindowInfo 234,259 angibt) dieses:
    238,311 onScreen
    246,319 active Window
    left: -8 top: -8 width: 1168 height: 840 als Active Window Position

    auch Window Info sagt -8,-8 als Position, von daher sind sie gleich

    nu guck ich aber dumm daher und weiß nicht weiter

    viele Grüße
    jörg