Jump to content

Search the Community

Showing results for tags 'RichEdit'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • Forum FAQ
  • AutoIt

Calendars

  • Community Calendar

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

  1. I want to crate a small editor to just have minimum functions. But I want to see my changes directly (Color/Bold...). I tried it with richedit and mostly it is ok. Some functions are not included: Sizeposition (left/center). I do not really need a RTF at the end, I have to create a html-file with the used functions. So. If anyone have a better idea to make this -> please let me know. I put my existing script here: SCEDIT.ZIP includes all used JPG. SCEdit.au3 SCEdit.zip
  2. First I want to thanks to RoyGlanfield for : Printing RichEdit A long time ago I was wondering how to print RTF files in the background. I just used to use this solution: ShellExecuteWait($sRTF_FileFullPath, '', '', 'print') Unfortunately, it is slow and is not done, in the background. A few days ago I was looking for a solution through google. I found a solution at home and exactly here. I modified it a little, and behold, here it is: #include-once #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 #Tidy_Parameters=/sort_funcs /reel #Region RTF PRINTER Include# #include <GuiRichEdit.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <SendMessage.au3> #include <Array.au3> #EndRegion RTF PRINTER Include# #Region RTF PRINTER HEADER# ; #INDEX# ======================================================================================================================= ; Title .........: UDF for Printing RTF files ; AutoIt Version : 3.3.10.2++ ; Language ......: English ; Description ...: UDF for Printing RTF files ; Author(s) .....: mLipok, RoyGlanfield ; Modified ......: ; =============================================================================================================================== #cs Title: UDF for Printing RTF files Filename: RTF_Printer.au3 Description: UDF for Printing RTF files Author: RoyGlanfield, mLipok Modified: Last Update: 2014/06/15 Requirements: AutoIt 3.3.10.2 or higher http://www.autoitscript.com/forum/topic/127580-printing-richedit/ http://www.autoitscript.com/forum/topic/161831-rtf-printer-printing-richedit/ Update History: =================================================== 2014/06/04 v0.1 First official version 2014/06/04 v0.2 * Global Variable renaming by adding $__ * extended $__API_RTF_Printer * new function: _RTF_SetMargins($vMarginLeft = 1, $vMarginTop = 1, $vMarginRight = 1, $vMarginBottom = 1) * new function: _RTF_SetNumberOfCopies($iNumberOfCopies = 1) * added #Region RTF PRINTER initialization# * CleanUp * added #forceref * added #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 2014/06/12 v0.3 * Global Variable Renaming add 'RTF' to variable names and added $__ to be sure that no one else used the name * Global Variable renaming $aPageInfo to $__aRTFPageInfo to be sure that no one else used the name * variable renaming $hInput* to $iCtrlInput* * in _RTF_PrintFile() new parameter $fAddIndex * Setting RTF_Printer Window Title * fix problem with printing more than 16 RTF files >> GUIDelete($__API_RTF_Printer[$__hRTF_Gui]) * new internal function __RTF_AddLeadingZeros * added some more comments * brand new RTF_Printer_Examples.au3 2014/06/15 v0.4 * $sRTF_FileFullPath_or_Stream - A string value. Full path to the RTF file to be printed or Stream Data from _GUICtrlRichEdit_StreamToVar * Now you can create documents in RichEdit and print them without the need to save the RTF file. * You can also download the documents from the database and print them without having to save them to disk as RTF files. * new RTF_Printer_Examples.au3 * new #Region MSDN Links , Help, Doc * some minior variable renaming #CE #EndRegion RTF PRINTER HEADER# #Region RTF PRINTER Constants# ; #CONSTANTS# =================================================================================================================== ; $__<UDF>_CONSTANT_<NAME> Global Const $__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" Global Enum _ $__hRTF_dcc, _ $__hRTF_Gui, $__hRichEditE, $__hRTF_RichEditPre, _ $__iRTFLabelPagegNow, $__iRTFLabelPagesTotal, _ $__vRTFMarginTop, $__vRTFMarginLeft, $__vRTFMarginRight, $__vRTFMarginBottom, _ $__iRTFNumberOfCopies, _ $__API_RTF_Printer_Count ; , $tDefaultPrinter, _ #EndRegion RTF PRINTER Constants# #Region RTF PRINTER Global Variables# Global $__API_RTF_Printer[$__API_RTF_Printer_Count] Global $__aRTFPageInfo[2]; $__aRTFPageInfo[0]= total num of pages $__aRTFPageInfo[1.....] = 1st char number of each page #EndRegion RTF PRINTER Global Variables# #Region RTF PRINTER initialization# _RTF_SetMargins() _RTF_SetNumberOfCopies() #EndRegion RTF PRINTER initialization# #Region RTF PRINTER CURRENT# ; #FUNCTION# ==================================================================================================================== ; Name ..........: _RTF_PrintFile ; Description ...: Print Selected File in the background or with custom window dialog ; Syntax ........: _RTF_PrintFile($sRTF_FileFullPath_or_Stream[, $sDocTitle = Default[, $fPrintNow = True[, $fAddIndex = False]]]) ; Parameters ....: $sRTF_FileFullPath_or_Stream - A string value. Full path to the RTF file to be printed or Stream Data from _GUICtrlRichEdit_StreamToVar ; $sDocTitle - [optional] A string value. Default is Default. If Default then $sDocTitle = FileName ; $fPrintNow - [optional] A boolean value. Default is True. If true then printing is running in the background. ; $fAddIndex - [optional] A boolean value. Default is False. If true then add Indexing to Document Name in spooler ; Return values .: None ; TODO ; Author ........: mLipok, RoyGlanfield ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/161831-rtf-printer-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func _RTF_PrintFile($sRTF_FileFullPath_or_Stream, $sDocTitle = Default, $fPrintNow = True, $fAddIndex = False) Static $__iRTF_Printer_Counter If $__iRTF_Printer_Counter = '' Then $__iRTF_Printer_Counter = 1 ; chcecking if Streamed Data insteed FileFullPath If StringLeft($sRTF_FileFullPath_or_Stream, 5) = '{\rtf' Then If $sDocTitle = Default Then $sDocTitle = 'RichEdit Data' EndIf Else If Not FileExists($sRTF_FileFullPath_or_Stream) Then Return -1 ; setting DocTitle (document Name in spooler) - if Default then FileName If $sDocTitle = Default Then $sDocTitle = StringRegExp($sRTF_FileFullPath_or_Stream, '(?i).+\\(.+)', 3)[0] EndIf EndIf ; adding index (as prefix) to the DocTitle (document Name in spooler) If $fAddIndex Then $sDocTitle = __RTF_AddLeadingZeros(String($__iRTF_Printer_Counter), 5) & '_' & $sDocTitle EndIf Local $hPrintDc = '' #forceref $hPrintDc Local $__aRTFPageInfo[2]; $__aRTFPageInfo[0]= total num of pages $__aRTFPageInfo[1.....] = 1st char number of each page Local $iPageInPreview = 1 ; the Page Now on show in the preview ; Printer dialog tags Local $tDefaultPrinter = __GetDefaultPrinter() ; Setting RTF_Printer Window Title Local $sRTF_Printer_Title = 'Print RTF ---- ' & $tDefaultPrinter $sRTF_Printer_Title = '[' & String($__iRTF_Printer_Counter) & '] ' & $sRTF_Printer_Title $__API_RTF_Printer[$__hRTF_Gui] = GUICreate($sRTF_Printer_Title, 430, 580, -1, -1) ; Control whose contents is to be printed--------MUST be RichEdit. ; any size will do---- has no effect on the printed copy $__API_RTF_Printer[$__hRichEditE] = _GUICtrlRichEdit_Create($__API_RTF_Printer[$__hRTF_Gui], "", 10, 50, 400, 124, $ES_MULTILINE + $WS_VSCROLL) ;+ $ES_AUTOVSCROLL) ; 21000 push the preview control off the page ; to be resized and positioned after paper size and orientation has been chosen [print dialog or default] $__API_RTF_Printer[$__hRTF_RichEditPre] = _GUICtrlRichEdit_Create($__API_RTF_Printer[$__hRTF_Gui], "", 21000, 10, 10, 10, $ES_MULTILINE) ;+ $ES_AUTOVSCROLL) $__API_RTF_Printer[$__iRTFLabelPagegNow] = GUICtrlCreateLabel("0", 60, 180, 40, 20, $SS_RIGHT) GUICtrlCreateLabel(" of ", 100, 180, 20, 20, $SS_Center) $__API_RTF_Printer[$__iRTFLabelPagesTotal] = GUICtrlCreateLabel("0", 120, 180, 40, 20, $SS_Left) Local $iButtonBack = GUICtrlCreateButton("Back", 160, 180, 50, 20) Local $iButtonNext = GUICtrlCreateButton("Next", 210, 180, 50, 20) Local $iButtonPrintNow = GUICtrlCreateButton("PrintNow", 280, 180, 100, 20) Local $EndPage = '' #forceref $EndPage GUICtrlCreateLabel('Margins-->', 0, 3, 50, 20) GUICtrlCreateLabel(' cm--->', 0, 30, 40, 20) GUICtrlCreateLabel('Left', 50, 3, 30, 15) GUICtrlCreateLabel('Top', 80, 3, 40, 15) GUICtrlCreateLabel('Right', 120, 3, 40, 15) GUICtrlCreateLabel('Bottom', 160, 3, 40, 15) GUICtrlCreateLabel('Copies', 230, 3, 40, 15) Local $iCtrlInputMarginLeft = GUICtrlCreateInput($__API_RTF_Printer[$__vRTFMarginLeft], 40, 18, 40, 30, $ES_READONLY) GUICtrlCreateUpdown(-1) GUICtrlSetLimit(-1, 4, 0) Local $iCtrlInputMarginTop = GUICtrlCreateInput($__API_RTF_Printer[$__vRTFMarginTop], 80, 18, 40, 30, $ES_READONLY) GUICtrlCreateUpdown(-1) GUICtrlSetLimit(-1, 4, 0) Local $iCtrlInputMarginRight = GUICtrlCreateInput($__API_RTF_Printer[$__vRTFMarginRight], 120, 18, 40, 30, $ES_READONLY) GUICtrlCreateUpdown(-1) GUICtrlSetLimit(-1, 4, 0) Local $iCtrlInputMarginBottom = GUICtrlCreateInput($__API_RTF_Printer[$__vRTFMarginBottom], 160, 18, 40, 30, $ES_READONLY) GUICtrlCreateUpdown(-1) GUICtrlSetLimit(-1, 4, 0) Local $iCtrlInputNumberOfCopies = GUICtrlCreateInput($__API_RTF_Printer[$__iRTFNumberOfCopies], 230, 25, 40, 20) Local $iButtonPrint = GUICtrlCreateButton("Print", 280, 5, 55, 20) Local $iButtonPrintGeneral = GUICtrlCreateButton("General", 280, 25, 60, 20) Local $iButtonPrintSetup = GUICtrlCreateButton("Print Setup", 335, 5, 75, 20) Local $iButtonNoDialog = GUICtrlCreateButton("No dialog", 340, 25, 70, 20) ; chcecking if Streamed Data insteed FileFullPath If StringLeft($sRTF_FileFullPath_or_Stream, 5) = '{\rtf' Then _GUICtrlRichEdit_StreamFromVar($__API_RTF_Printer[$__hRichEditE], $sRTF_FileFullPath_or_Stream) Else _GUICtrlRichEdit_StreamFromFile($__API_RTF_Printer[$__hRichEditE], $sRTF_FileFullPath_or_Stream) EndIf ; TrayTip('_GUICtrlRichEdit_StreamFromFile',@error,4) ; for test only If $fPrintNow = False Then GUISetState() EndIf ; this does not work ---$r = _GUICtrlRichEdit_SetZoom($__API_RTF_Printer[$__hRichEditE], 1/2)-------------- ; Below works well---but does have to be reset after anything is streamed in------ ; OK--------$r = _SendMessage($h_RichEdit, $EM_SETZOOM, $tDefaultPrinterominator, $denominator) ; $r = _SendMessage($__API_RTF_Printer[$__hRichEditE], $EM_SETZOOM, 1000, 2333) ; must be integer -- "1000, 2333" not "1, 2.333" ; $r = _SendMessage($__API_RTF_Printer[$__hRichEditE], $EM_SETZOOM, 100, 200) ; eg 50% Local $r = _SendMessage($__API_RTF_Printer[$__hRichEditE], $EM_SETZOOM, 100, 300) ; eg 33.3333333333% #forceref $r ; $r = _SendMessage($__API_RTF_Printer[$__hRTF_RichEditPre], $EM_SETZOOM, 100, 500) ; eg 20% Local $z Local $iMsg If $fPrintNow Then ; NO DIALOG ; $__API_RTF_Printer[$__iRTFNumberOfCopies] = GUICtrlRead($iCtrlInputNumberOfCopies) ; not needed as only prints 1copy ; "No dialog" ---No choices ; prints 1 copy using the default printer's settings $__API_RTF_Printer[$__hRTF_dcc] = __GetDC_PrinterNoDialog() If IsPtr($__API_RTF_Printer[$__hRTF_dcc]) = 1 Then $z = __RTF_Preview($__API_RTF_Printer[$__hRTF_dcc], $__API_RTF_Printer[$__hRichEditE], $__API_RTF_Printer[$__vRTFMarginLeft], $__API_RTF_Printer[$__vRTFMarginTop], $__API_RTF_Printer[$__vRTFMarginRight], $__API_RTF_Printer[$__vRTFMarginBottom]) EndIf ; PRINT NOW ; "Print Setup" dialog ---choices ; number of copies ; portrait/landscape choice ; paper size If IsPtr($__API_RTF_Printer[$__hRTF_dcc]) = 1 Then __RTF_Print($__API_RTF_Printer[$__hRTF_dcc], $__API_RTF_Printer[$__hRichEditE], $sDocTitle, $__API_RTF_Printer[$__vRTFMarginLeft], $__API_RTF_Printer[$__vRTFMarginTop], $__API_RTF_Printer[$__vRTFMarginRight], $__API_RTF_Printer[$__vRTFMarginBottom]) $__iRTF_Printer_Counter += 1 Else EndIf $hPrintDc = '' ; GUISetState() ; for test only ; Sleep(3000) ; for test only Else While 1 Sleep(10) $__API_RTF_Printer[$__vRTFMarginLeft] = GUICtrlRead($iCtrlInputMarginLeft) $__API_RTF_Printer[$__vRTFMarginTop] = GUICtrlRead($iCtrlInputMarginTop) $__API_RTF_Printer[$__vRTFMarginRight] = GUICtrlRead($iCtrlInputMarginRight) $__API_RTF_Printer[$__vRTFMarginBottom] = GUICtrlRead($iCtrlInputMarginBottom) $__API_RTF_Printer[$__iRTFNumberOfCopies] = GUICtrlRead($iCtrlInputNumberOfCopies) $iMsg = GUIGetMsg() Select Case $iMsg = $GUI_EVENT_CLOSE GUIDelete() Exit Case $iMsg = $iButtonNoDialog; "No dialog" ; $__API_RTF_Printer[$__iRTFNumberOfCopies] = GUICtrlRead($iCtrlInputNumberOfCopies) ; not needed as only prints 1copy ; "No dialog" ---No choices ; prints 1 copy ; using the default printer's settings $__API_RTF_Printer[$__hRTF_dcc] = __GetDC_PrinterNoDialog() If IsPtr($__API_RTF_Printer[$__hRTF_dcc]) = 1 Then $z = __RTF_Preview($__API_RTF_Printer[$__hRTF_dcc], $__API_RTF_Printer[$__hRichEditE], $__API_RTF_Printer[$__vRTFMarginLeft], $__API_RTF_Printer[$__vRTFMarginTop], $__API_RTF_Printer[$__vRTFMarginRight], $__API_RTF_Printer[$__vRTFMarginBottom]) MsgBox(4096, '', $z & ' pages sent to the preview.') EndIf Case $iMsg = $iButtonPrintSetup; "PrintSetup" ; "Print Setup" dialog ---choices ; number of copies ; portrait/landscape choice ; paper size $__API_RTF_Printer[$__hRTF_dcc] = __GetDC_PrinterSetup($__API_RTF_Printer[$__iRTFNumberOfCopies]) ; OK-- If IsPtr($__API_RTF_Printer[$__hRTF_dcc]) = 1 Then $z = __RTF_Preview($__API_RTF_Printer[$__hRTF_dcc], $__API_RTF_Printer[$__hRichEditE], $__API_RTF_Printer[$__vRTFMarginLeft], $__API_RTF_Printer[$__vRTFMarginTop], $__API_RTF_Printer[$__vRTFMarginRight], $__API_RTF_Printer[$__vRTFMarginBottom]) MsgBox(4096, '', $z & ' pages sent to the preview.') EndIf Case $iMsg = $iButtonPrint; "Print" ; "Print" ---choices-- ; number of copies ; Page range---All, from, to, Selection ; NO-- portrait/landscape choice $__API_RTF_Printer[$__hRTF_dcc] = __GetDC_Printer($__API_RTF_Printer[$__iRTFNumberOfCopies]) ; OK--"Print" dialog If IsPtr($__API_RTF_Printer[$__hRTF_dcc]) = 1 Then $z = __RTF_Preview($__API_RTF_Printer[$__hRTF_dcc], $__API_RTF_Printer[$__hRichEditE], $__API_RTF_Printer[$__vRTFMarginLeft], $__API_RTF_Printer[$__vRTFMarginTop], $__API_RTF_Printer[$__vRTFMarginRight], $__API_RTF_Printer[$__vRTFMarginBottom]) MsgBox(4096, '', $z & ' pages sent to the preview.') EndIf Case $iMsg = $iButtonPrintGeneral; "General" ; "General" ---choices-- ; number of copies ; Page range---All, Selection ; NO-- portrait/landscape choice----------- $__API_RTF_Printer[$__hRTF_dcc] = __GetDC_PrinterGeneral($__API_RTF_Printer[$__hRichEditE], $__API_RTF_Printer[$__iRTFNumberOfCopies]) If IsPtr($__API_RTF_Printer[$__hRTF_dcc]) = 1 Then $z = __RTF_Preview($__API_RTF_Printer[$__hRTF_dcc], $__API_RTF_Printer[$__hRichEditE], $__API_RTF_Printer[$__vRTFMarginLeft], $__API_RTF_Printer[$__vRTFMarginTop], $__API_RTF_Printer[$__vRTFMarginRight], $__API_RTF_Printer[$__vRTFMarginBottom]) MsgBox(4096, '', $z & ' pages sent to the preview.') EndIf Case $iMsg = $iButtonPrintNow; ; "Print Setup" dialog ---choices ; number of copies ; portrait/landscape choice ; paper size If IsPtr($__API_RTF_Printer[$__hRTF_dcc]) = 1 Then MsgBox(4096, '', __RTF_Print($__API_RTF_Printer[$__hRTF_dcc], $__API_RTF_Printer[$__hRichEditE], $sDocTitle, $__API_RTF_Printer[$__vRTFMarginLeft], $__API_RTF_Printer[$__vRTFMarginTop], $__API_RTF_Printer[$__vRTFMarginRight], $__API_RTF_Printer[$__vRTFMarginBottom])) Else EndIf $hPrintDc = '' Case $iMsg = $iButtonNext; If $iPageInPreview < $__aRTFPageInfo[0] Then $iPageInPreview += 1 __NextPage($iPageInPreview) EndIf Case $iMsg = $iButtonBack ; If $iPageInPreview > 1 Then $iPageInPreview -= 1 __NextPage($iPageInPreview) EndIf EndSelect WEnd EndIf ; CleanUp If IsHWnd($__API_RTF_Printer[$__hRTF_Gui]) Then GUIDelete($__API_RTF_Printer[$__hRTF_Gui]) EndFunc ;==>_RTF_PrintFile ; #FUNCTION# ==================================================================================================================== ; Name ..........: _RTF_SetMargins ; Description ...: Set Margins size in cm [centimeters] ; Syntax ........: _RTF_SetMargins([$vMarginLeft = 1[, $vMarginTop = 1[, $vMarginRight = 1[, $vMarginBottom = 1]]]]) ; Parameters ....: $vMarginLeft - [optional] A variant value. Default is 1. ; $vMarginTop - [optional] A variant value. Default is 1. ; $vMarginRight - [optional] A variant value. Default is 1. ; $vMarginBottom - [optional] A variant value. Default is 1. ; Return values .: None ; Author ........: mLipok ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _RTF_SetMargins($vMarginLeft = 1, $vMarginTop = 1, $vMarginRight = 1, $vMarginBottom = 1) $__API_RTF_Printer[$__vRTFMarginLeft] = $vMarginLeft ; initial minimum Left margin $__API_RTF_Printer[$__vRTFMarginTop] = $vMarginTop ; initial minimum Top margin $__API_RTF_Printer[$__vRTFMarginRight] = $vMarginRight ; initial minimum Right margin $__API_RTF_Printer[$__vRTFMarginBottom] = $vMarginBottom ; initial minimum Bottom margin EndFunc ;==>_RTF_SetMargins ; #FUNCTION# ==================================================================================================================== ; Name ..........: _RTF_SetNumberOfCopies ; Description ...: Set number of copies ; Syntax ........: _RTF_SetNumberOfCopies([$iNumberOfCopies = 1]) ; Parameters ....: $iNumberOfCopies - [optional] An integer value. Default is 1. ; Return values .: None ; Author ........: mLipok ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _RTF_SetNumberOfCopies($iNumberOfCopies = 1) $__API_RTF_Printer[$__iRTFNumberOfCopies] = $iNumberOfCopies ; initial number of Copies to print EndFunc ;==>_RTF_SetNumberOfCopies #EndRegion RTF PRINTER CURRENT# #Region RTF PRINTER INTERNAL# ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __GetDC_PrinterSetup ; Description ...: Get the device context of a "PrinterSetup" Dialog box ; Syntax ........: __GetDC_PrinterSetup([$iCopies = 1]) ; Parameters ....: $iCopies - [optional] An integer value. Default is 1. Number of copies to print. ; Return values .: Success: Device context ; Failure: 0 ; Author ........: RoyGlanfield ; Modified ......: mLipok ; Remarks .......: Has choices for -- portrait/landscape, printer, paper size ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/127580-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func __GetDC_PrinterSetup($iCopies = 1) Local $strcPD = DllStructCreate($__PDtags) DllStructSetData($strcPD, "lStructSize", DllStructGetSize($strcPD)) ; DllStructSetData($strcPD, "hwndOwner", $hwnd) ; ; Constants--$PD_RETURNDC = 0x100----$PD_PRINTSETUP = 0x40 DllStructSetData($strcPD, "Flags", 0x100 + 0x40) ; different flags open different dialogue boxes DllStructSetData($strcPD, "nCopies", $iCopies) ; set the number of copies ; DllStructSetData($strcPD,"nFromPage", 1) ; start from page # ; DllStructSetData($strcPD, "nToPage", 0xFFFF) ; DllStructSetData($strcPD, "nMinPage", 1) ; DllStructSetData($strcPD, "nMaxPage", 0xFFFF) Local $bRet = DllCall("Comdlg32.dll", "int", "PrintDlgW", "ptr", DllStructGetPtr($strcPD)) Local $hDC = 0 If $bRet[0] = True Then $hDC = DllStructGetData($strcPD, "hDC") EndIf $strcPD = '' Return $hDC EndFunc ;==>__GetDC_PrinterSetup ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __GetDC_Printer ; Description ...: Get the device context of a "Print" Dialog box ; Syntax ........: __GetDC_Printer([$iCopies = 1]) ; Parameters ....: $iCopies - [optional] An integer value. Default is 1. Number of copies to print. ; Return values .: Success: Device context ; Failure: 0 ; Author ........: RoyGlanfield ; Modified ......: mLipok ; Remarks .......: Has choices for -- many, but no portrait/landscape ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/127580-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func __GetDC_Printer($iCopies = 1) Local $strcPD = DllStructCreate($__PDtags) DllStructSetData($strcPD, "lStructSize", DllStructGetSize($strcPD)) ; DllStructSetData($strcPD, "hwndOwner", $hwnd) ; ; Constant--$PD_RETURNDC = 0x100 DllStructSetData($strcPD, "Flags", 0x100) ; different flags open different dialogue boxes DllStructSetData($strcPD, "nCopies", $iCopies) ; set the number of copies DllStructSetData($strcPD, "nFromPage", 1) ; start from page # DllStructSetData($strcPD, "nToPage", 0xFFFF) DllStructSetData($strcPD, "nMinPage", 1) DllStructSetData($strcPD, "nMaxPage", 0xFFFF) Local $bRet = DllCall("Comdlg32.dll", "int", "PrintDlgW", "ptr", DllStructGetPtr($strcPD)) Local $hDC = 0 If $bRet[0] = True Then $hDC = DllStructGetData($strcPD, "hDC") EndIf $strcPD = '' Return $hDC EndFunc ;==>__GetDC_Printer ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __GetDC_PrinterNoDialog ; Description ...: Get the device context of the default printer ; Syntax ........: __GetDC_PrinterNoDialog() ; Parameters ....: ; Return values .: Success: Device context ; Failure: 0 ; Author ........: RoyGlanfield ; Modified ......: mLipok ; Remarks .......: Uses the default printers settings ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/127580-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func __GetDC_PrinterNoDialog() Local $strcPD = DllStructCreate($__PDtags) DllStructSetData($strcPD, "lStructSize", DllStructGetSize($strcPD)) ; DllStructSetData($strcPD, "hwndOwner", $hwnd) ; ; Const--RETURNDEFAULT = 0x400---RETURNDC = 0x100----PRINTSETUP = 0x40 DllStructSetData($strcPD, "Flags", 0x100 + 0x40 + 0x400) ; different flags open different dialogue boxes ; DllStructSetData($strcPD, "nCopies", $iCopies) ; only set this if a dialog is shown ; DllStructSetData($strcPD,"nFromPage", 1) ; start from page # ; DllStructSetData($strcPD, "nToPage", 0xFFFF) ; DllStructSetData($strcPD, "nMinPage", 1) ; DllStructSetData($strcPD, "nMaxPage", 0xFFFF) Local $bRet = DllCall("Comdlg32.dll", "int", "PrintDlgW", "ptr", DllStructGetPtr($strcPD)) Local $hDC = 0 If $bRet[0] = True Then $hDC = DllStructGetData($strcPD, "hDC") EndIf $strcPD = '' Return $hDC EndFunc ;==>__GetDC_PrinterNoDialog ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __GetDC_PrinterGeneral ; Description ...: Get the device context of a "PrinterSetup General tab" Dialog box ; Syntax ........: __GetDC_PrinterGeneral($hRichEditCtrl[, $iCopies = 1]) ; Parameters ....: $hRichEditCtrl - A handle value. Handle of the RichEdit control. ; $iCopies - [optional] An integer value. Default is 1. Number of copies to print. ; Return values .: Success: Device context ; Failure: 0 ; Author ........: RoyGlanfield ; Modified ......: mLipok ; Remarks .......: Has choices for -- many, but no portrait/landscape ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/127580-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func __GetDC_PrinterGeneral($hRichEditCtrl, $iCopies = 1) ; Printer Setup, general options---NO landscape! Local $strcPD = DllStructCreate($__PDtags) DllStructSetData($strcPD, "lStructSize", DllStructGetSize($strcPD)) DllStructSetData($strcPD, "hwndOwner", $hRichEditCtrl) ; ; Constant--$PD_RETURNDC = 0x100 DllStructSetData($strcPD, "Flags", 0x100) ; different flags open different dialogue boxes DllStructSetData($strcPD, "nCopies", $iCopies) ; set the number of copies ; DllStructSetData($strcPD,"nFromPage", 10) ; start from page # ; DllStructSetData($strcPD, "nToPage", 0xFFFF) ; DllStructSetData($strcPD, "nMinPage", 1) ; DllStructSetData($strcPD, "nMaxPage", 0xFFFF) Local $bRet = DllCall("Comdlg32.dll", "int", "PrintDlgW", "ptr", DllStructGetPtr($strcPD)) Local $hDC = 0 If $bRet[0] = True Then $hDC = DllStructGetData($strcPD, "hDC") EndIf $strcPD = '' Return $hDC EndFunc ;==>__GetDC_PrinterGeneral ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __GetDefaultPrinter ; Description ...: Get default printer dialog tags ; Syntax ........: __GetDefaultPrinter() ; Parameters ....: ; Return values .: Printer dialog tags ; Author ........: RoyGlanfield ; Modified ......: mLipok ; Remarks .......: ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/127580-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func __GetDefaultPrinter() Local $tags1 = DllStructCreate("dword") DllCall("winspool.drv", "int", "GetDefaultPrinter", "str", '', "ptr", DllStructGetPtr($tags1)) Local $tags2 = DllStructCreate("char[" & DllStructGetData($tags1, 1) & "]") DllCall("winspool.drv", "int", "GetDefaultPrinter", "ptr", DllStructGetPtr($tags2), "ptr", DllStructGetPtr($tags1)) Return DllStructGetData($tags2, 1) EndFunc ;==>__GetDefaultPrinter ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __NextPage ; Description ...: Show selected page in preview ; Syntax ........: __NextPage($iPageNumber) ; Parameters ....: $iPageNumber - An integer value. ; Return values .: None ; Author ........: RoyGlanfield ; Modified ......: mLipok ; Remarks .......: ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/127580-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func __NextPage($iPageNumber) ; stream into preview all up to the end of the page to show ; _GUICtrlRichEdit_SetSel($__API_RTF_Printer[$__hRichEditE], 0, $__aRTFPageInfo[$iPageNumber + 1] - 1) ; '-1' because $__aRTFPageInfo[$iPageNumber+1] is the 1st char of next page _GUICtrlRichEdit_SetSel($__API_RTF_Printer[$__hRichEditE], 0, $__aRTFPageInfo[$iPageNumber + 1]) ; '-1' because $__aRTFPageInfo[$iPageNumber+1] is the 1st char of next page Local $stream = _GUICtrlRichEdit_StreamToVar($__API_RTF_Printer[$__hRichEditE]) _GUICtrlRichEdit_StreamFromVar($__API_RTF_Printer[$__hRTF_RichEditPre], $stream) _GUICtrlRichEdit_HideSelection($__API_RTF_Printer[$__hRTF_RichEditPre]) ; now delete all before the page to show this way the font size etc. is continued, rather than reverting to the default. _GUICtrlRichEdit_SetSel($__API_RTF_Printer[$__hRTF_RichEditPre], 0, $__aRTFPageInfo[$iPageNumber]) _GUICtrlRichEdit_ReplaceText($__API_RTF_Printer[$__hRTF_RichEditPre], '') Local $r = _SendMessage($__API_RTF_Printer[$__hRTF_RichEditPre], $EM_SETZOOM, 100, 500) ; eg 20% #forceref $r GUICtrlSetData($__API_RTF_Printer[$__iRTFLabelPagegNow], $iPageNumber) EndFunc ;==>__NextPage Func __RTF_AddLeadingZeros($iDigitToExpand, $iNumberOfDigits) Return StringRight("00000000000000000000000000000000000" & String($iDigitToExpand), $iNumberOfDigits) EndFunc ;==>__RTF_AddLeadingZeros ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __RTF_Preview ; Description ...: Show a "Print Preview" from RichEdit control ; Syntax ........: __RTF_Preview($hPrintDc, $hRichEditCtrl[, $LeftMinMargin = 1[, $TopMinMargin = 1[, $RightMinMargin = 1[, $BottomMinMargin = 1]]]]) ; Parameters ....: $hPrintDc - A handle value. Handle of Printer's device context. ; $hRichEditCtrl - A handle value. Handle of the RichEdit control. ; $LeftMinMargin - [optional] An unknown value. Default is 1. Minimum margin on the left. ; $TopMinMargin - [optional] An unknown value. Default is 1. Minimum margin on the top. ; $RightMinMargin - [optional] An unknown value. Default is 1. Minimum margin on the Right. ; $BottomMinMargin - [optional] An unknown value. Default is 1. Minimum margin on the Bottom. ; Return values .: None ; Author ........: RoyGlanfield ; Modified ......: mLipok ; Remarks .......: Orientation, paper size, number of copies, and which printer are set when the Printer's device context is generated. ; Unexpected results may be caused by single line/paragaph orphin tags in the rtf. ; The Preview RichEdit Control is resized and zoomed 20% ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/127580-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func __RTF_Preview($hPrintDc, $hRichEditCtrl, $LeftMinMargin = 1, $TopMinMargin = 1, $RightMinMargin = 1, $BottomMinMargin = 1) ; convert the margins 0.1 inches to twips ; $TopMinMarg = $TopMinMarg * 144; eg 10*144 = 1440 which 1 inch ; $LeftMinMarg = $LeftMinMarg * 144; eg 10*144 = 1440 which 1 inch ; $PageMinMarg = $PageMinMarg * 144; eg 10*144 = 1440 which 1 inch ; $BottomMinMarg = $BottomMinMarg * 144; eg 10*144 = 1440 which 1 inch ; convert the margins 1 cm to twips $TopMinMargin = $TopMinMargin * 567; eg 2.539cm * 567= ~1440 which 1 inch $LeftMinMargin = $LeftMinMargin * 567; eg 2.539cm * 567 = ~1440 which 1 inch $RightMinMargin = $RightMinMargin * 567; eg 2.539cm * 567 = ~1440 which 1 inch $BottomMinMargin = $BottomMinMargin * 567; eg 2.539cm * 567 = ~1440 which 1 inch ; $hPrintDc ; Divice Context handle----------- ; dots per inch depends on the printer quality setting-------X and Y can be different! Local $dotInchX = _WinAPI_GetDeviceCaps($hPrintDc, 88) ; Const LOGPIXELSX = 88 Local $dotInchY = _WinAPI_GetDeviceCaps($hPrintDc, 90) ; Const LOGPIXELSY = 90 ; printer dots per inch ; get the printable area [Page] and paper area [Paper] Local $vPageWidth = _WinAPI_GetDeviceCaps($hPrintDc, 8) ; Const HORZRES= 8 Local $vPageHeight = _WinAPI_GetDeviceCaps($hPrintDc, 10) ; Const VERTRES = 10 Local $vPaperWidth = _WinAPI_GetDeviceCaps($hPrintDc, 110) ; Const PHYSICALWIDTH = 110 Local $vPaperHeight = _WinAPI_GetDeviceCaps($hPrintDc, 111) ; Const PHYSICALHEIGHT = 111 ; none printable margins Local $OffSetX = _WinAPI_GetDeviceCaps($hPrintDc, 112) ; Const PHYSICALOFFSETX = 112 Local $OffSetY = _WinAPI_GetDeviceCaps($hPrintDc, 113) ; Const PHYSICALOFFSETY = 113 Local $vRightMargin = $vPaperWidth - $vPageWidth - $OffSetX Local $vBottomMargin = $vPaperHeight - $vPageHeight - $OffSetY ; conversion factors to use later----------- Local $TwipsInchX = $dotInchX / 1440 ; convert dots to twips [per inch] Local $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 $vPageWidth = $vPageWidth / $TwipsInchX ; convert Right dots to twips $vPageHeight = $vPageHeight / $TwipsInchY ; convert Right dots to twips $vPaperWidth = $vPaperWidth / $TwipsInchX ; convert Paper Width dots to twips $vPaperHeight = $vPaperHeight / $TwipsInchY ; convert Paper Width dots to twips ; Set the margins and keep everything in the printable area Local $Left1 = $LeftMinMargin - $OffSetX If $Left1 < 0 Then $Left1 = 0 ; dont print before printable area starts Local $Top1 = $TopMinMargin - $OffSetY If $Top1 < 0 Then $Top1 = 0 ; dont print before printable area starts Local $Right1 = $RightMinMargin - $vRightMargin If $Right1 < 0 Then $Right1 = 0 ; dont print after printable area ends ; $Right1 = $vPaperWidth - $Right1 - $OffSetX $Right1 = $vPageWidth - $Right1 ; $OffSetX+$Left1-$vRightMargin Local $Bottom1 = $BottomMinMargin - $vBottomMargin If $Bottom1 < 0 Then $Bottom1 = 0 ; dont print after printable area ends $Bottom1 = $vPageHeight - $Bottom1 Local $z = _SendMessage($__API_RTF_Printer[$__hRTF_RichEditPre], $EM_SETTARGETDEVICE, $hPrintDc, $Right1 - $Left1) ; If $z = 0 Then Return 'Cant find RichEdit Control' If _GUICtrlRichEdit_GetTextLength($hRichEditCtrl) < 1 Then Return 'Nothing to Print.' ; must have a selection on the richEdit control--------------- _SendMessage($hRichEditCtrl, $EM_SETSEL, 0, -1) ; ok----select all Local $dcHTags = "HANDLE hdc;HANDLE hdcTarget;" Local $pgTags = "int Left1 ;int Top1 ;int Right1 ;int Bottom1 ;int Left2;int Top2;int Right2;int Bottom2;" Local $rgTags = "LONG cpMin;LONG cpMax" ; create a structure for the printed page Local $strcPage = DllStructCreate($dcHTags & $pgTags & $rgTags) DllStructSetData($strcPage, "hdc", $hPrintDc) ; printer DllStructSetData($strcPage, "Left1", $Left1) ; twip--------printer DllStructSetData($strcPage, "Right1", $Right1) ; twip--------printer DllStructSetData($strcPage, "Top1", $Top1) ; twip--------printer DllStructSetData($strcPage, "Bottom1", $Bottom1) ; twip--------printer ; next 7 lines seem to have, no effect or crash printer jobs queue---why??? ; "HANDLE hdc;" is the printer------- before conecting printer to rtf??? ; "HANDLE hdcTarget;" is the target RichEdit control that has the rtf ???? ; DllStructSetData($strcPage,"hdcTarget",$hPrintDc) ; richEdit scource??? ; DllStructSetData($strcPage,"Left2",$Left1/$dotInchX*96/3) ; richEdit scource??? ; DllStructSetData($strcPage,"Top2",$Top1/$dotInchX*96/3) ; richEdit scource??? ; DllStructSetData($strcPage,"Right2",$Page1/$dotInchX*96/3) ; twip------richEdit scource??? ; DllStructSetData($strcPage,"Bottom2",$Bottom1/$dotInchX*96/3) ; twip-----richEdit scource??? ; get the pointer to all that will be printed??? {I think????????} Local $a = DllStructGetPtr($strcPage) + DllStructGetSize(DllStructCreate($dcHTags & $pgTags)) ; use this pointer----------- _SendMessage($hRichEditCtrl, $EM_EXGETSEL, 0, $a) ReDim $__aRTFPageInfo[2] $__aRTFPageInfo[1] = 1 $__aRTFPageInfo[0] = 0 ; the total number of pages Local $iPageInPreview = 1 ; the page number of the preview now showing #forceref $iPageInPreview ; find the last char of the document to be printed Local $cpMax = DllStructGetData($strcPage, "cpMax") ; set the 1st page start char----------- Local $cpMin = 0 Local $cpMin2 = -1 ; ----------------------------------------------------------- ; 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 ; get the 1st char of the next page, {but how does it work ???} $cpMin2 = $cpMin $cpMin = _SendMessage($hRichEditCtrl, $EM_FORMATRANGE, True, DllStructGetPtr($strcPage)) If $cpMin2 = $cpMin Then ExitLoop; get out of loop before more pages are added ; set the next page start char----------- DllStructSetData($strcPage, "cpMin", $cpMin) $__aRTFPageInfo[0] += 1 ; increment page the total page count ; update array --- for what to show in the preview _ArrayAdd($__aRTFPageInfo, $cpMin) ; start char-number of each page ; end the page and loop again for the next page until the end of document WEnd _SendMessage($hRichEditCtrl, $EM_FORMATRANGE, False, 0) ; adjust the preview shape/size WinMove($__API_RTF_Printer[$__hRTF_RichEditPre], '', 210 - $vPaperWidth / 1440 * 96 / 5 / 2, 200, $vPaperWidth / 1440 * 96 / 5 + 15, $vPaperHeight / 1440 * 96 / 5 + 15) ; the printer starts printing at offsetX and offsetY but the preview windiw starts at 1 and 1 ; so add offsetX and offsetY to the page margins to the printer would use _GUICtrlRichEdit_SetRECT($__API_RTF_Printer[$__hRTF_RichEditPre], ($Left1 + $OffSetX) / $dotInchX * 96 / 5, ($Top1 + $OffSetY) / $dotInchY * 96 / 5, 460, 500) __NextPage(1) GUICtrlSetData($__API_RTF_Printer[$__iRTFLabelPagesTotal], $__aRTFPageInfo[0]) Return $__aRTFPageInfo[0] EndFunc ;==>__RTF_Preview ; #FUNCTION# ==================================================================================================================== ; Name ..........: __RTF_Print ; Description ...: Print from RichEdit control ; Syntax ........: __RTF_Print($hPrintDc, $hRichEditCtrl, $sDocTitle[, $LeftMinMargin = 1[, $TopMinMargin = 1[, $RightMinMargin = 1[, ; $BottomMinMargin = 1]]]]) ; Parameters ....: $hPrintDc - A handle value. Printer's device context. ; $hRichEditCtrl - A handle value. Handle of the RichEdit control. ; $sDocTitle - An unknown value. Printer's job title. ; $LeftMinMargin - [optional] An unknown value. Default is 1. Minimum margin on the left ; $TopMinMargin - [optional] An unknown value. Default is 1. Minimum margin on the Top ; $RightMinMargin - [optional] An unknown value. Default is 1. Minimum margin on the Right ; $BottomMinMargin - [optional] An unknown value. Default is 1. Minimum margin on the Bottom ; Return values .: Success - 'Sent to the printer.' ; Failure - 'Printing aborted.' ; Author ........: RoyGlanfield ; Modified ......: mLipok ; Remarks .......: Orientation, paper size, number of copies, and which printer are set when the Printer's device context is generated. ; Unexpected results may be caused by single line/paragaph orphin tags in the rtf. ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/127580-printing-richedit/ ; Example .......: No ; =============================================================================================================================== Func __RTF_Print($hPrintDc, $hRichEditCtrl, $sDocTitle, $LeftMinMargin = 1, $TopMinMargin = 1, $RightMinMargin = 1, $BottomMinMargin = 1) ; convert the margins 0.1 inches to twips ; $TopMinMarg = $TopMinMarg * 144; eg 10*144 = 1440 which 1 inch ; $LeftMinMarg = $LeftMinMarg * 144; eg 10*144 = 1440 which 1 inch ; $PageMinMarg = $PageMinMarg * 144; eg 10*144 = 1440 which 1 inch ; $BottomMinMarg = $BottomMinMarg * 144; eg 10*144 = 1440 which 1 inch ; convert the margins 1 cm to twips $TopMinMargin = $TopMinMargin * 567; eg 2.539cm * 567= ~1440 which 1 inch $LeftMinMargin = $LeftMinMargin * 567; eg 2.539cm * 567 = ~1440 which 1 inch $RightMinMargin = $RightMinMargin * 567; eg 2.539cm * 567 = ~1440 which 1 inch $BottomMinMargin = $BottomMinMargin * 567; eg 2.539cm * 567 = ~1440 which 1 inch ; $hPrintDc ; Divice Context handle----------- ; dots per inch depends on the printer quality setting-------X and Y can be different! Local $dotInchX = _WinAPI_GetDeviceCaps($hPrintDc, 88) ; Const LOGPIXELSX = 88 Local $dotInchY = _WinAPI_GetDeviceCaps($hPrintDc, 90) ; Const LOGPIXELSY = 90 ; printer dots per inch ; get the printable area [Page] and paper area [Paper] Local $vPageWidth = _WinAPI_GetDeviceCaps($hPrintDc, 8) ; Const HORZRES= 8 Local $vPageHeight = _WinAPI_GetDeviceCaps($hPrintDc, 10) ; Const VERTRES = 10 Local $vPaperWidth = _WinAPI_GetDeviceCaps($hPrintDc, 110) ; Const PHYSICALWIDTH = 110 Local $vPaperHeight = _WinAPI_GetDeviceCaps($hPrintDc, 111) ; Const PHYSICALHEIGHT = 111 ; none printable margins Local $OffSetX = _WinAPI_GetDeviceCaps($hPrintDc, 112) ; Const PHYSICALOFFSETX = 112 Local $OffSetY = _WinAPI_GetDeviceCaps($hPrintDc, 113) ; Const PHYSICALOFFSETY = 113 Local $vRightMargin = $vPaperWidth - $vPageWidth - $OffSetX Local $vBottomMargin = $vPaperHeight - $vPageHeight - $OffSetY ; conversion factors to use later----------- Local $TwipsInchX = $dotInchX / 1440 ; convert dots to twips [per inch] Local $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 $vPageWidth = $vPageWidth / $TwipsInchX ; convert Right dots to twips $vPageHeight = $vPageHeight / $TwipsInchY ; convert Right dots to twips $vPaperWidth = $vPaperWidth / $TwipsInchX ; convert Paper Width dots to twips $vPaperHeight = $vPaperHeight / $TwipsInchY ; convert Paper Width dots to twips ; Set the margins and keep everything in the printable area Local $Left1 = $LeftMinMargin - $OffSetX If $Left1 < 0 Then $Left1 = 0 ; dont print before printable area starts Local $Top1 = $TopMinMargin - $OffSetY If $Top1 < 0 Then $Top1 = 0 ; dont print before printable area starts Local $Right1 = $RightMinMargin - $vRightMargin If $Right1 < 0 Then $Right1 = 0 ; dont print after printable area ends ; $Right1 = $vPaperWidth - $Right1 - $OffSetX $Right1 = $vPageWidth - $Right1 ;+$Left1 ; $OffSetX Local $Bottom1 = $BottomMinMargin - $vBottomMargin If $Bottom1 < 0 Then $Bottom1 = 0 ; dont print after printable area ends $Bottom1 = $vPageHeight - $Bottom1 ;+$Top1 Local $z = _SendMessage($hRichEditCtrl, $EM_SETTARGETDEVICE, 0) ; 0=wrap----anything else is 1 char per page!!!!! If $z = 0 Then Return 'Cant find RichEdit Control' If _GUICtrlRichEdit_GetTextLength($hRichEditCtrl) < 1 Then Return 'Nothing to Print.' ; must have a selection on the richEdit control--------------- _SendMessage($hRichEditCtrl, $EM_SETSEL, 0, -1) ; ok----select all Local $pgTags = "int Left1 ;int Top1 ;int Right1 ;int Bottom1 ;int Left2;int Top2;int Right2;int Bottom2;" Local $rgTags = "LONG cpMin;LONG cpMax" Local $dcHTags = "HANDLE hdc;HANDLE hdcTarget;" ; create a structure for the printed page Local $strcPage = DllStructCreate($dcHTags & $pgTags & $rgTags) DllStructSetData($strcPage, "hdc", $hPrintDc) ; printer DllStructSetData($strcPage, "Left1", $Left1) ; twip--------printer DllStructSetData($strcPage, "Right1", $Right1) ; twip--------printer DllStructSetData($strcPage, "Top1", $Top1) ; twip--------printer DllStructSetData($strcPage, "Bottom1", $Bottom1) ; twip--------printer ; next 7 lines seem to have, no effect or crash printer jobs queue---why??? ; "HANDLE hdc;" is the printer------- before conecting printer to rtf??? ; "HANDLE hdcTarget;" is the target RichEdit control that has the rtf ???? ; DllStructSetData($strcPage,"hdcTarget",$hPrintDc) ; richEdit scource??? ; DllStructSetData($strcPage,"Left2",$Left1/$dotInchX*96/3) ; richEdit scource??? ; DllStructSetData($strcPage,"Top2",$Top1/$dotInchX*96/3) ; richEdit scource??? ; DllStructSetData($strcPage,"Right2",$Page1/$dotInchX*96/3) ; twip------richEdit scource??? ; DllStructSetData($strcPage,"Bottom2",$Bottom1/$dotInchX*96/3) ; twip-----richEdit scource??? ; get the pointer to all that will be printed??? {I think????????} Local $a = DllStructGetPtr($strcPage) + DllStructGetSize(DllStructCreate($dcHTags & $pgTags)) ; use this pointer----------- _SendMessage($hRichEditCtrl, $EM_EXGETSEL, 0, $a) ; find the last char of the document to be printed Local $cpMax = DllStructGetData($strcPage, "cpMax") ; set the 1st page start char----------- Local $cpMin = 0 Local $cpMin2 = -1 ; ----------------------------------------------------------- ; create a Document structure for the print job title Local $strDocNm = DllStructCreate("char DocName[" & StringLen($sDocTitle & Chr(0)) & "]") DllStructSetData($strDocNm, "DocName", $sDocTitle & Chr(0)) Local $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 Local $StartPage, $EndPage #forceref $StartPage 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($hRichEditCtrl, $EM_FORMATRANGE, True, DllStructGetPtr($strcPage)) ; 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($strcPage, "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($hRichEditCtrl, $EM_FORMATRANGE, False, 0) If $EndPage[0] > 0 Then DllCall("Gdi32.dll", "int", "EndDoc", "HANDLE", $hPrintDc) Return 'Sent to the printer.' Else DllCall("Gdi32.dll", "int", "AbortDoc", "HANDLE", $hPrintDc) Return 'Printing aborted.' EndIf EndFunc ;==>__RTF_Print #EndRegion RTF PRINTER INTERNAL# #Region MSDN Links , Help, Doc ;~ How to Print the Contents of Rich Edit Controls ;~ http://msdn.microsoft.com/en-us/library/windows/desktop/bb787875(v=vs.85).aspx ;~ http://blogs.msdn.com/b/oldnewthing/archive/2007/01/12/1455972.aspx ;~ How To Use GetDeviceCaps to Determine Margins on a Page ;~ http://support.microsoft.com/kb/193943 ;~ http://msdn.microsoft.com/en-us/library/windows/desktop/dd144877(v=vs.85).aspx ;~ http://msdn.microsoft.com/en-us/library/windows/desktop/dd162833(v=vs.85).aspx ;~ http://msdn.microsoft.com/en-us/library/windows/desktop/dd162931(v=vs.85).aspx ;~ http://support.microsoft.com/kb/139652 ;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ms646962(v=vs.85).aspx ;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ms646964(v=vs.85).aspx ;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ms646966(v=vs.85).aspx #EndRegion MSDN Links , Help, Doc HOW TO USE THIS: #include-once #include <RTF_Printer.au3> _RTF_PrintFile($sRTF_FileFullPath, Default, True, True) ; or take a look in attached RTF_Printer_Examples.au3 ; Regards mLipok EDIT: attachment changed (before 6 downloads) RTF_Printer.au3.Download.html
  3. This is a simple func I made to write colored text to a rich edit, and I thought someone else might find it useful. What it does is format the text into RTF syntax so you don't need to mess with selecting and setting the color and such with multiple commands. ; _GUICtrlRichEdit_AppendTextEx($RichEdit, $text, $font="Arial", $color="000000", $size=12, $bold=0, $italic=0, $underline=0, $strike=0) ; This function was created to make it simpler to use RichEdit controls. ; ; Note: to set the line spacing to a size bigger than the text, ; you need to call this function once to write the text, and then call ; it again and write a space with a larger size, and that will give you ; spacing between the lines. ; ;Peramiters ; $RichEdit = handle of RichEdit control ; $text = the string to write. You need to add @CRLF for a newline ; $font = the font family to use, default = "Arial" ; $color = the rrggbb hex color code to use, default = "000000" (black) ; $size = the font size to use in points, will be rounded to the nearest 0.5 points before use, default = 12 ; $bold = flag to make the text bold, default = 0 (not bold) ; $italic = flag to make the text italic, default = 0 (not italic) ; $strike = flag to make the text strikethrough, default = 0 ; $underline = int, what kind of underlining to use. default = 0 ; 1 = Underline ; 2 = Double Underline ; 3 = Thick Underline ; 4 = Underline words only ; 5 = Wave Underline ; 6 = Dotted Underline ; 7 = Dash Underline ; 8 = Dot Dash Underline ; ;Return value ; On success: Returns the value from _GUICtrlRichEdit_AppendText() ; On failure: Sets @error to non-0 ; 1 = Error with color ; Func _GUICtrlRichEdit_AppendTextEx($RichEdit, $text, $font="Arial", $color="000000", $size=12, $bold=0, $italic=0, $strike=0, $underline=0) Local $command = "{\rtf1\ansi" Local $r, $g, $b, $ul[9] = ["8", '\ul', '\uldb', '\ulth', '\ulw', '\ulwave', '\uld', '\uldash', '\uldashd'] If $font <> "" Then $command &= "{\fonttbl\f0\f"&$font&";}" If $color <> "" Then If StringLen($color) <> 6 And StringLen($color) = 8 Then Return SetError(1) $b = dec(StringRight($color,2)) if @error Then seterror(1, 1) $color = StringTrimRight($color,2) $g = dec(StringRight($color,2)) if @error Then seterror(1, 2) $color = StringTrimRight($color,2) $r = dec(StringRight($color,2)) if @error Then seterror(1, 3) If $r+$b+$g > 0 Then $command &= "{\colortbl;\red"&$r&"\green"&$g&"\blue"&$b&";}\cf1" EndIf EndIf If $size Then $command &= "\fs"&round($size*2)&" " If $strike Then $command &= "\strike " If $italic Then $command &= "\i " If $bold Then $command &= "\b " If $underline > 0 and $underline < 9 Then $command &= $ul[$underline]&" " ;~ ConsoleWrite($command&$text&"}"&@CRLF) ; Debugging line Return _GUICtrlRichEdit_AppendText($RichEdit, $command&StringReplace($text,@CRLF,"\line")&"}" ) EndFuncAn example of it's use: #include <GuiRichEdit.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 331, 303, 192, 124) $Input1 = GUICtrlCreateInput("Input1", 8, 240, 313, 21) $ButtonBob = GUICtrlCreateButton("Bob", 8, 264, 75, 25) $ButtonMar = GUICtrlCreateButton("Mary", 88, 264, 75, 25) $ButtonSus = GUICtrlCreateButton("Susan", 168, 264, 75, 25) $ButtonJoe = GUICtrlCreateButton("Joe", 248, 264, 75, 25) $RichEdit = _GUICtrlRichEdit_Create($Form1, "", 8, 8, 313, 225, BitOR($WS_VSCROLL, $ES_AUTOVSCROLL, $ES_MULTILINE, $ES_READONLY)) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $lastuser = "" demo() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $ButtonBob If GUICtrlRead($Input1) <> "" Then _Chat_SendMessage("Bob", "993333", GUICtrlRead($Input1)) Case $ButtonJoe If GUICtrlRead($Input1) <> "" Then _Chat_SendMessage("Joe", "339933", GUICtrlRead($Input1)) Case $ButtonSus If GUICtrlRead($Input1) <> "" Then _Chat_SendMessage("Susan", "333399", GUICtrlRead($Input1)) Case $ButtonMar If GUICtrlRead($Input1) <> "" Then _Chat_SendMessage("Mary", "339999", GUICtrlRead($Input1)) EndSwitch WEnd Func demo() _Chat_SendMessage("Bob", "993333", "Testin 123") _Chat_SendMessage("Bob", "993333", "Example script here") _Chat_SendMessage("Susan", "333399", "Enter something in the input and press a button") _Chat_SendMessage("Susan", "333399", "Try experimenting with it a bit") _Chat_SendMessage("Mary", "339999", "Messages between the same user are less spaced out than between other people") EndFunc ;use a function for wrapping messages with multiple parts of different formattings Func _Chat_SendMessage($user, $color, $text) Local $temp = ControlGetFocus($Form1) _GUICtrlRichEdit_AppendTextEx($RichEdit, $user&":", "Arial", $color, 10, 1) If $lastuser <> $user and $lastuser <> "" Then ; Add line spacing between users by using a taller font size for the space _GUICtrlRichEdit_AppendTextEx($RichEdit, " ", "Arial", "000000", 15) Else ; Same width as 15, but only as tall as 10 :P _GUICtrlRichEdit_AppendTextEx($RichEdit, " ", "Arial", "000000", 10) _GUICtrlRichEdit_AppendTextEx($RichEdit, " ", "Arial", "000000", 5) EndIf _GUICtrlRichEdit_AppendTextEx($RichEdit, $text&@CRLF, "Arial", "000000", 10) $lastuser = $user ControlFocus($Form1, "", $temp) EndFunc ; _GUICtrlRichEdit_AppendTextEx($RichEdit, $text, $font="Arial", $color="000000", $size=12, $bold=0, $italic=0, $underline=0, $strike=0) ; This function was created to make it simpler to use RichEdit controls. ; ; Note: to set the line spacing to a size bigger than the text, ; you need to call this function once to write the text, and then call ; it again and write a space with a larger size, and that will give you ; spacing between the lines. ; ;Peramiters ; $RichEdit = handle of RichEdit control ; $text = the string to write. You need to add @CRLF for a newline ; $font = the font family to use, default = "Arial" ; $color = the rrggbb hex color code to use, default = "000000" (black) ; $size = the font size to use in points, will be rounded to the nearest 0.5 points before use, default = 12 ; $bold = flag to make the text bold, default = 0 (not bold) ; $italic = flag to make the text italic, default = 0 (not italic) ; $strike = flag to make the text strikethrough, default = 0 ; $underline = int, what kind of underlining to use. default = 0 ; 1 = Underline ; 2 = Double Underline ; 3 = Thick Underline ; 4 = Underline words only ; 5 = Wave Underline ; 6 = Dotted Underline ; 7 = Dash Underline ; 8 = Dot Dash Underline ; ;Return value ; On success: Returns the value from _GUICtrlRichEdit_AppendText() ; On failure: Sets @error to non-0 ; 1 = Error with color ; Func _GUICtrlRichEdit_AppendTextEx($RichEdit, $text, $font="Arial", $color="000000", $size=12, $bold=0, $italic=0, $strike=0, $underline=0) Local $command = "{\rtf1\ansi" Local $r, $g, $b, $ul[9] = ["8", '\ul', '\uldb', '\ulth', '\ulw', '\ulwave', '\uld', '\uldash', '\uldashd'] If $font <> "" Then $command &= "{\fonttbl\f0\f"&$font&";}" If $color <> "" Then If StringLen($color) <> 6 And StringLen($color) = 8 Then Return SetError(1) $b = dec(StringRight($color,2)) if @error Then seterror(1, 1) $color = StringTrimRight($color,2) $g = dec(StringRight($color,2)) if @error Then seterror(1, 2) $color = StringTrimRight($color,2) $r = dec(StringRight($color,2)) if @error Then seterror(1, 3) If $r+$b+$g > 0 Then $command &= "{\colortbl;\red"&$r&"\green"&$g&"\blue"&$b&";}\cf1" EndIf EndIf If $size Then $command &= "\fs"&round($size*2)&" " If $strike Then $command &= "\strike " If $italic Then $command &= "\i " If $bold Then $command &= "\b " If $underline > 0 and $underline < 9 Then $command &= $ul[$underline]&" " ;~ ConsoleWrite($command&$text&"}"&@CRLF) ; Debugging line Return _GUICtrlRichEdit_AppendText($RichEdit, $command&StringReplace($text,@CRLF,"\line")&"}" ) EndFuncIf this was useful to you, or if you have any ideas / suggestions to make it better, let me know.
  4. Hi, For an internal project I want to write internal script to mail some special request to an external party. To make it a little bit universal I decided that the user should be able to write or edit the e-mail signature. Because I wanted to put a logo into the e-mail, I decided to use RichEdit. I I found the following code by @UEZ and adapted it a little to save and load. When I start the script and edit the text only, I can save and load the signature.rtf. However the moment I resize one of the images (with the mouse), the script wil only save the edited image. Somehow resizing an image deletes the other content of the RichEdit object. Does anyone know a solution for me? P.s. you need to delete signature.rtf to reset the file. #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> Example() Func Example() Local $hGui, $iMsg, $idBtnExit, $hRichEdit $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")", 520, 550, -1, -1) $hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 10, 10, 500, 490, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) $idBtnExit = GUICtrlCreateButton("Exit", 10, 510, 40, 30) $GoodRead = False If FileExists(@ScriptDir & "\signature.rtf") Then $ResSFF = _GUICtrlRichEdit_StreamFromFile($hRichEdit, @ScriptDir & "\signature.rtf") If $ResSFF=true then $GoodRead = True EndIf If $GoodRead=False Then _GUICtrlRichEdit_InsertText($hRichEdit, "Inserting image..." & @LF & @LF) _GUICtrlRichEdit_InsertText($hRichEdit, @LF & "JPG image scaled:" & @LF & @LF) _GUICtrlRichEdit_InsertBitmap($hRichEdit, "c:\Program Files (x86)\AutoIt3\Examples\GUI\mslogo.jpg", "\qc", "\picw6747\pich1058\picwgoal6690\pichgoal1860\") ;\qc = centered _GUICtrlRichEdit_InsertText($hRichEdit, @LF & @LF & "PNG image:" & @LF & @LF) _GUICtrlRichEdit_InsertBitmap($hRichEdit, "c:\Program Files (x86)\AutoIt3\Examples\GUI\Torus.png") _GUICtrlRichEdit_InsertText($hRichEdit, @LF & @LF & "Done.") EndIf GUISetState(@SW_SHOW) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idBtnExit _GUICtrlRichEdit_StreamToFile($hRichEdit, @ScriptDir & "\signature.rtf") _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes GUIDelete() Exit EndSwitch WEnd EndFunc ;==>Example Func _GUICtrlRichEdit_InsertBitmap($hWnd, $sFile, $sFormatFunctions = "\", $sBitmapFunctions = "\", $iBgColor = Default) ;coded by UEZ build 2016-02-16 If Not FileExists($sFile) Then Return SetError(0, 0, 1) If Not _WinAPI_IsClassName($hWnd, $__g_sRTFClassName) Then Return SetError(0, 0, 2) _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile($sFile) If @error Then _GDIPlus_Shutdown() Return SetError(0, 0, 3) EndIf Local Const $aDim = _GDIPlus_ImageGetDimension($hImage) Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($aDim[0], $aDim[1]), $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap) If $iBgColor = Default Then $iBgColor = 0xFF000000 + _WinAPI_SwitchColor(_GUICtrlRichEdit_GetBkColor($hWnd)) EndIf _GDIPlus_GraphicsClear($hGfx, $iBgColor) _GDIPlus_GraphicsDrawImageRect($hGfx, $hImage, 0, 0, $aDim[0], $aDim[1]) _GDIPlus_GraphicsDispose($hGfx) Local $binStream = _GDIPlus_StreamImage2BinaryString($hBitmap, "BMP") If @error Then _GDIPlus_ImageDispose($hImage) _GDIPlus_ImageDispose($hBitmap) _GDIPlus_Shutdown() Return SetError(0, 0, 4) EndIf Local $binBmp = StringMid($binStream, 31) Local Const $binRtf = "{\rtf1\viewkind4" & $sFormatFunctions & " {\pict{\*\picprop}" & $sBitmapFunctions & "dibitmap " & $binBmp & "}\par}" ;check out http://www.biblioscape.com/rtf15_spec.htm _GUICtrlRichEdit_AppendText($hWnd, $binRtf) $binStream = 0 $binBmp = 0 _GDIPlus_ImageDispose($hImage) _GDIPlus_ImageDispose($hBitmap) _GDIPlus_Shutdown() Return 1 EndFunc ;==>_GUICtrlRichEdit_InsertBitmap Func _GDIPlus_StreamImage2BinaryString($hBitmap, $sFormat = "JPG", $iQuality = 80, $bSave = False, $sFileName = @ScriptDir & "\Converted.jpg") ;coded by UEZ 2013 build 2014-01-25 (based on the code by Andreik) Local $sImgCLSID, $tGUID, $tParams, $tData Switch $sFormat Case "JPG" $sImgCLSID = _GDIPlus_EncodersGetCLSID($sFormat) $tGUID = _WinAPI_GUIDFromString($sImgCLSID) $tData = DllStructCreate("int Quality") DllStructSetData($tData, "Quality", $iQuality) ;quality 0-100 Local $pData = DllStructGetPtr($tData) $tParams = _GDIPlus_ParamInit(1) _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData) Case "PNG", "BMP", "GIF", "TIF" $sImgCLSID = _GDIPlus_EncodersGetCLSID($sFormat) $tGUID = _WinAPI_GUIDFromString($sImgCLSID) Case Else Return SetError(1, 0, 0) EndSwitch Local $hStream = _WinAPI_CreateStreamOnHGlobal() ;http://msdn.microsoft.com/en-us/library/ms864401.aspx If @error Then Return SetError(2, 0, 0) _GDIPlus_ImageSaveToStream($hBitmap, $hStream, DllStructGetPtr($tGUID), DllStructGetPtr($tParams)) If @error Then Return SetError(3, 0, 0) Local $hMemory = _WinAPI_GetHGlobalFromStream($hStream) ;http://msdn.microsoft.com/en-us/library/aa911736.aspx If @error Then Return SetError(4, 0, 0) Local $iMemSize = _MemGlobalSize($hMemory) If Not $iMemSize Then Return SetError(5, 0, 0) Local $pMem = _MemGlobalLock($hMemory) $tData = DllStructCreate("byte[" & $iMemSize & "]", $pMem) Local $bData = DllStructGetData($tData, 1) _WinAPI_ReleaseStream($hStream) ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221473(v=vs.85).aspx _MemGlobalFree($hMemory) If $bSave Then Local $hFile = FileOpen($sFileName, 18) If @error Then Return SetError(6, 0, $bData) FileWrite($hFile, $bData) FileClose($hFile) EndIf Return $bData EndFunc ;==>_GDIPlus_StreamImage2BinaryString
  5. I think RichEdit has been my favorite thing I've ever discovered on AutoIt lol. In my quest to add in more html tags to my _StringToRichEditArray I needed a way to do href! There was an example I found that I followed but it didn't format correctly and didn't work 100% but it gave me a good base. Think I'll tackle inserting an image next, not looking forward to that. If anyone has an idea on how to do it let me know. Known issues (these will cause the hyperlink to lose the +li attribute after the RichEdit is updated): The hyperlink and friendly text are appended/inserted (directly adjacent to a non whitespace) but the hyperlink is not a valid hyperlink. Changing the char color for the control causes the hyperlink to lose it's hyperlink color (the light blue). Fix for Issue 1: Use the full URL for the hyperlink (https://www.autoitscript.com/site/ instead of www.autoitscript.com/site) Use any hyperlink with any friendly text that does not have www at the beginning (Hyperlink: www.google.com, Friendly Text: google.com) Use any hyperlink with any, or no, friendly text, but have a whitespace to the left of the hyperlink. Fix for Issue 2: I have no fix. Updated RichEdit Hyperlink.au3 Demo Original Post, outdated: Had a problem with inserting/appending hyperlinks that pointed to the local computer. (C:\Windows\)
  6. Hello, i would like to know why isnt anything displayed on the combo box. i used this example and added it to my code Autoit Example : #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> Dim $sRegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" GUICreate("Test", 400, 100) $cCombo_Font = GUICtrlCreateCombo("", 10, 10, 170, 20, 2097474);HELPHERE GUICtrlSetData($cCombo_Font, _RegEnumVal($sRegKey)) $cLabel = GUICtrlCreateLabel("Font preview", 230, 10, 155, 20) GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $cCombo_Font GUICtrlSetFont($cLabel, 10, Default, Default, GUICtrlRead($cCombo_Font)) EndSwitch WEnd Func _RegEnumVal($sKey) Local $i = 1, $sVal, $sResult While 1 $sVal = RegEnumVal($sKey, $i) If @error Then ExitLoop $i += 1 $sResult &= $sVal & "|" WEnd Return StringRegExpReplace($sResult, " \(.*?\)", "") EndFunc ;==>_RegEnumVal And my code: #NoTrayIcon #include <Misc.au3> #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <File.au3> #include <GuiEdit.au3> #include <String.au3> #include <GuiRichEdit.au3> #include <GuiToolbar.au3> #include <GuiImageList.au3> $WIDTH = 500 $HEIGHT = 380 $EXT1 = "|Rich Text File (*.rtf)" $EXT2 = "|ODF Text (*.odt)" $EXT3 = "|All Files(*.*)" $EXT = $EXT1 & $EXT2 $SETTINGS = "Settings.ini" Dim $FONTKEY = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" Global $FILESAVE, $FILEOPEN = "", $SAVES, $SAVE, $FILEOPENED = 0 Global Enum $e_idNew = 1000, $e_idOpen, $e_idSave, $e_idHelp $MAINGUI = GUICreate("Text Editor", $WIDTH, $HEIGHT, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE) $TOOLBAR = _GUICtrlToolbar_Create($MAINGUI) _GUIImageList_AddIcon($TOOLBAR, @SystemDir & "\shell.dll", -1) $IMAGES = _GUIImageList_Create(24,24) _GUICtrlToolbar_SetImageList($TOOLBAR, $IMAGES) _GUICtrlToolbar_AddButton($TOOLBAR, $e_idNew, -1);AndHereIfYouCouldTHX _GUICtrlToolbar_AddButton($TOOLBAR, $e_idNew, -2) _GUICtrlToolbar_AddButton($TOOLBAR, $e_idNew, 3) _GUICtrlToolbar_AddButton($TOOLBAR, $e_idNew, 4) _GUICtrlToolbar_AddButtonSep($TOOLBAR) _GUICtrlToolbar_AddButton($TOOLBAR, $e_idNew, 5) _GUICtrlToolbar_AddButton($TOOLBAR, $e_idNew, 6) $EDITBOX = _GUICtrlRichEdit_Create($MAINGUI, "This is a test.", 10, 35, $WIDTH - 20, $HEIGHT - 70, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) $FONTCOMBOBOX = GUICtrlCreateCombo("", $WIDTH - 170, 10, 160, 20, 2097474);HELPMEHERE GUICtrlSetData($FONTCOMBOBOX, _RegEnumVal($FONTKEY));ALSOHERE $FONTSIZECOMBOBOX = GUICtrlCreateCombo("", $WIDTH - 200, 10, 20, 20, 2097474);FuncForPreviousLineAtTheEnd $FILE = GUICtrlCreateMenu("File") $NEW = GUICtrlCreateMenuItem("New", $FILE) $OPEN = GUICtrlCreateMenuItem("Open...", $FILE) $SAVE = GUICtrlCreateMenuItem("Save", $FILE) $SAVEAS = GUICtrlCreateMenuItem("Save As...", $FILE) $PRINT = GUICtrlCreateMenuItem("Print...", $FILE) GUICtrlCreateMenuItem("", $FILE) $EXIT = GUICtrlCreateMenuItem("Exit", $FILE) $EDIT = GUICtrlCreateMenu("Edit") $UNDO = GUICtrlCreateMenuItem("Undo", $EDIT) $REDO = GUICtrlCreateMenuItem("Redo", $EDIT) $SEPARATOR = GUICtrlCreateMenuItem("", $EDIT) $FONT = GUICtrlCreateMenuItem("Font test", $EDIT) $SEPARATOR1 = GUICtrlCreateMenuItem("", $EDIT) $CUT = GUICtrlCreateMenuItem("Cut", $EDIT) $COPY = GUICtrlCreateMenuItem("Copy", $EDIT) $PASTE = GUICtrlCreateMenuItem("Paste", $EDIT) GUISetState(@SW_SHOW & $GUI_ACCEPTFILES) While 1 $Msg = GUIGetMsg() Select Case $Msg = $GUI_EVENT_CLOSE If _GUICtrlEdit_CanUndo($EDITBOX) Then $SAVECHANGES = MsgBox(35, "Text Editor", "Your original file has been modified." & @CRLF & "Would you like to save changes to it?") If $SAVECHANGES = 6 And $FILEOPENED = 0 Then SaveAs() _GUICtrlRichEdit_Destroy($hRichEdit) Exit EndIf If $SAVECHANGES = 6 And $FILEOPENED = 1 Then FileDelete($FILEOPEN) FileWrite($FILEOPEN, GUICtrlRead($EDITBOX)) Exit EndIf If $SAVECHANGES = 7 Then ExitLoop Exit EndIf EndIf If Not _GUICtrlEdit_CanUndo($EDITBOX) Then Exit Case $Msg = $OPEN $FILEOPEN = FileOpenDialog("Open", $FILEOPEN, $EXT) $TEXT = _GUICtrlRichEdit_StreamFromFile($EDITBOX, $FILEOPEN) _GUICtrlRichEdit_ReplaceText($EDITBOX, $TEXT) $FILEOPENED = 1 Case $Msg = $NEW If _GUICtrlEdit_CanUndo($EDITBOX) Then $SAVECHANGES = MsgBox(35, "Text Editor", "Your original file has been modified." & @CRLF & "Would you like to save changes to it?") If $SAVECHANGES = 6 And $FILEOPENED = 0 Then SaveAs() EndIf If $SAVECHANGES = 6 And $FILEOPENED = 1 Then FileDelete($FILEOPEN) FileWrite($FILEOPEN, GUICtrlRead($EDITBOX)) EndIf If $SAVECHANGES = 7 Then GUICtrlSetData($EDITBOX, "") If $SAVECHANGES = 2 Then Sleep(1) EndIf If Not _GUICtrlEdit_CanUndo($EDITBOX) Then GUICtrlSetData($EDITBOX, "") $FILEOPENED = 0 Case $Msg = $EXIT If _GUICtrlEdit_CanUndo($EDITBOX) Then $SAVECHANGES = MsgBox(35, "Text Editor", "Your original file has been modified." & @CRLF & "Would you like to save changes to it?") If $SAVECHANGES = 6 And $FILEOPENED = 0 Then SaveAs() _GUICtrlRichEdit_Destroy($hRichEdit) Exit EndIf If $SAVECHANGES = 6 And $FILEOPENED = 1 Then FileDelete($FILEOPEN) FileWrite($FILEOPEN, GUICtrlRead($EDITBOX)) Exit EndIf If $SAVECHANGES = 7 Then ExitLoop If $SAVECHANGES = 2 Then Sleep(1) EndIf EndIf If Not _GUICtrlEdit_CanUndo($EDITBOX) Then Exit Case $Msg = $SAVEAS GUICtrlSetState($EDITBOX, $GUI_DISABLE) SaveAs() $FILEOPENED = 1 GUICtrlSetState($EDITBOX, $GUI_ENABLE) Case $Msg = $SAVE And $FILEOPENED = 1 FileDelete($FILEOPEN) FileWrite($FILEOPEN, GUICtrlRead($EDITBOX)) _GUICtrlEdit_EmptyUndoBuffer($EDITBOX) Case $Msg = $SAVE And $FILEOPENED = 0 GUICtrlSetState($EDITBOX, $GUI_DISABLE) SaveAs() $FILEOPENED = 1 GUICtrlSetState($EDITBOX, $GUI_ENABLE) Case $Msg = $SAVE And $FILEOPENED = 0 GUICtrlSetState($EDITBOX, $GUI_DISABLE) SaveAs() $FILEOPENED = 1 GUICtrlSetState($EDITBOX, $GUI_ENABLE) Case $Msg = $PRINT $PRINTMSGBOX = MsgBox(35, "Text Editor", "Are you sure you want to print this page?") Select Case $PRINTMSGBOX = 6 If FileExists("Print.txt") Then FileDelete("Print.txt") EndIf FileWrite("Print.txt", GUICtrlRead($EDITBOX)) $PRINTFILE = "Print.txt" _FilePrint($PRINTFILE) FileDelete($PRINTFILE) EndSelect Case $Msg = $UNDO _GUICtrlRichEdit_Undo($EDITBOX) Case $Msg = $REDO _GUICtrlRichEdit_Redo($EDITBOX) Case _GUICtrlEdit_CanUndo($EDITBOX) And $SAVES = 1 GUICtrlSetState($SAVE, $GUI_ENABLE) Case $Msg = $CUT _GUICtrlRichEdit_Cut ($EDITBOX) Case $Msg = $COPY _GUICtrlRichEdit_Copy ($EDITBOX) Case $Msg = $PASTE _GUICtrlRichEdit_Paste ($EDITBOX) Case Not _GUICtrlEdit_CanUndo($EDITBOX) And $SAVES = 0 GUICtrlSetState($SAVE, $GUI_DISABLE) $SAVES = 1 Case $Msg = $FONT _GUICtrlRichEdit_SetFont($EDITBOX, $FONTSIZECOMBOBOX, "Times New Roman") Case $FONTCOMBOBOX _GUICtrlRichEdit_SetFont($EDITBOX, $FONTSIZECOMBOBOX, GUICtrlRead($FONTCOMBOBOX)) EndSelect WEnd Exit Func SaveAs() $FILESAVEAS = FileSaveDialog("Save As", "", "Text Document (*.txt)|All Files (*.*)") If Not @error Then $STRING = StringSplit($FILESAVEAS, ".") If $STRING[0] = 1 Then FileDelete($FILESAVEAS) _GUICtrlRichEdit_StreamToFile($EDITBOX, $FILESAVEAS &".rtf") Else _GUICtrlRichEdit_StreamToFile($EDITBOX, $FILESAVEAS &".rtf") EndIf EndIf EndFunc Func _RegEnumVal($sKey) Local $i = 1, $sVal, $sResult While 1 $sVal = RegEnumVal($sKey, $i) If @error Then ExitLoop $i += 1 $sResult &= $sVal & "|" WEnd Return StringRegExpReplace($sResult, " \(.*?\)", "") EndFunc ;==>_RegEnumVal So the problem is that The second combo box is blank Icons in taskbar are not appearing (don't really care for now, .dll file for icon in attachement) problem with $FONTCOMBOBOX = GUICtrlCreateCombo("", 10, 10, 200, 20, Bitor($CBS_SORT,$CBS_DROPDOWN,$CBS_AUTOHSCROLL,$WS_VSCROLL) (BitOR gave me a weird error) Thanks ! Autoit newbie ico.dll
  7. This is an example script, showing how to avoid having Richedit control stealing focus from other controls. I have seen several person on the forum having the same issue as me. When using a RichEdit Control in a chat software, RichEdit steals focus from the Input everytime a user posts a message. I think I found a work around : find a way to append the text without making a text selection, because the selection moves the caret in the richedit control. Problems and solutions I found : 1 - "_GUICtrlRichEdit_AppendText" Steals focus because there is "_GuiCtrlRichEdit_SetSel" in the function ( "_GuiCtrlRichEdit_SetSel" is used to input the text at the end of the richedit control, and also used to scroll the page to the last line ). --- > AppendText Solution = I use "_GUICtrlEdit_AppendText" from "GuiEdit.au3". It appends the text at the end of the Richedit Control, without moving the caret to the richedit control. --- > Scrolling Solution = I used "_GUICtrlRichEdit_ScrollLines" to scroll one line down. Later I'll try to find how many lines really need to be scrolled ( if multiline text ). 2 - "_GUICtrlRichEdit_SetCharColor" Also needs a selection to apply the color. ( _GUICtrlRichEdit_SetFont Doesn't need a selection ) --- > Color solution = I edited the "_GUICtrlRichEdit_SetCharColor" by Jpm ( and named it "_GUICtrlRichEdit_SetCharColor_No_Selection" ) and commented the _GuiCtrlRichEdit_GetSel lines. So the color needs to be chosen before appending the text. Here is an example script showing the problem ( I tried to simulate a chat situation ) : ;INCLUDES #include <GuiRichEdit.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ;OPT Opt("GUIOnEventMode", 1) ;VARIABLES GUI Global $GUI_SIZE_X = 600 Global $GUI_SIZE_Y = 600 Global $GUI_RICHEDIT_SIZE_X = $GUI_SIZE_X Global $GUI_RICHEDIT_SIZE_Y = $GUI_SIZE_Y / 3 ;GUI Global $GUI = GUICreate("Test", $GUI_SIZE_X, $GUI_SIZE_Y) ;RICHEDIT Global $GUI_RICHEDIT = _GUICtrlRichEdit_Create($GUI, "", 0, 0, $GUI_RICHEDIT_SIZE_X, $GUI_RICHEDIT_SIZE_Y * 2, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY)) ;INPUT Global $sINPUT_TEXT = "Try to Type some text here ! (Then press ENTER to send)" & @CRLF & @CRLF & _ "It's IMPOSSIBLE !" & @CRLF & @CRLF & _ "the _GUICtrlRichEdit_AppendText steals focus from the input all the time, making RichEdit almost unusable in a chat software (Even if you use !" & @CRLF & @CRLF & _ "Also, _GUICtrlRichEdit_SetCharColor needs to have a selection to apply the color on the incoming text. If no Selection, then the color is applied on the whole control" & @CRLF & @CRLF & _ "Even with 'GUICtrlSetState ( $GUI_INPUT, $GUI_FOCUS )' it doesn't help" Global $GUI_INPUT = GUICtrlCreateInput($sINPUT_TEXT, 0, $GUI_RICHEDIT_SIZE_Y * 2, $GUI_SIZE_X, $GUI_RICHEDIT_SIZE_Y, $ES_MULTILINE) GUISetState() GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") HotKeySet("{ENTER}", "_Send") ;LOOP While 1 ;HERE WE ADD RANDOM TEXT WITH RANDOM COLOR EVERY 'Random' ms (TRY TO SIMULATE A CHAT SITUATION) _Chat_Add_Line($GUI_RICHEDIT, _ "Chat Line " & Random(0, 999999), _ "0x" & StringFormat("%02d", Random(0, 99, 1)) & StringFormat("%02d", Random(0, 99, 1)) & StringFormat("%02d", Random(0, 99, 1)), _ 8) Sleep(Random(50, 2000, 1)) WEnd Func _Send() _Chat_Add_Line($GUI_RICHEDIT, "You Said : " & GUICtrlRead($GUI_INPUT), 0xFF0000, 12) GUICtrlSetState($GUI_INPUT, $GUI_FOCUS) GUICtrlSetData($GUI_INPUT, "") Return 1 EndFunc ;==>_Send Func _Chat_Add_Line($hWnd, $sMessage, $sColor, $iFont) StringReplace(_GUICtrlRichEdit_GetText($hWnd, True), @CRLF, "") Local $iLines = @extended Local $iStart = _GUICtrlRichEdit_GetTextLength($hWnd, True, True) - $iLines _GUICtrlRichEdit_PauseRedraw($hWnd) _GUICtrlRichEdit_AppendText($hWnd, $sMessage & @CRLF) _GUICtrlRichEdit_SetSel($hWnd, $iStart, -1, False) _GUICtrlRichEdit_SetCharColor($hWnd, $sColor) _GUICtrlRichEdit_SetFont($hWnd, $iFont) _GUICtrlRichEdit_Deselect($hWnd) _GUICtrlRichEdit_ResumeRedraw($hWnd) ;---> ( TRY TO UN-COMMENT THE NEXT LINE ) ; HERE WE EVEN TRY TO GIVE BACK THE FOCUS TO THE INPUT, BUT IT DOESN'T HELP ;~ GUICtrlSetState ( $GUI_INPUT, $GUI_FOCUS ) Return 1 EndFunc ;==>_Chat_Add_Line Func _Exit() _GUICtrlRichEdit_Destroy($GUI_RICHEDIT) Exit EndFunc ;==>_ExitAnd Here is my modified version : ;INCLUDES #include <GuiEdit.au3> #include <GuiRichEdit.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ;OPT Opt("GUIOnEventMode", 1) ;VARIABLES GUI Global $GUI_SIZE_X = 600 Global $GUI_SIZE_Y = 600 Global $GUI_RICHEDIT_SIZE_X = $GUI_SIZE_X Global $GUI_RICHEDIT_SIZE_Y = $GUI_SIZE_Y / 3 ;GUI Global $GUI = GUICreate("Test", $GUI_SIZE_X, $GUI_SIZE_Y) ;RICHEDIT Global $GUI_RICHEDIT = _GUICtrlRichEdit_Create($GUI, "", 0, 0, $GUI_RICHEDIT_SIZE_X, $GUI_RICHEDIT_SIZE_Y * 2, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY)) ;INPUT Global $GUI_INPUT = GUICtrlCreateInput("Type some text here, then press Enter", 0, $GUI_RICHEDIT_SIZE_Y * 2, $GUI_SIZE_X, $GUI_RICHEDIT_SIZE_Y, $ES_MULTILINE) GUISetState() GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") HotKeySet("{ENTER}", "_Send") ;LOOP While 1 ;HERE WE ADD RANDOM TEXT WITH RANDOM COLOR EVERY 'Random' ms (TRY TO SIMULATE A CHAT SITUATION) _Chat_Add_Line($GUI_RICHEDIT, _ "Chat Line " & Random(0, 999999), _ "0x" & StringFormat("%02d", Random(0, 99, 1)) & StringFormat("%02d", Random(0, 99, 1)) & StringFormat("%02d", Random(0, 99, 1)), _ 8) Sleep(Random(50, 1000, 1)) WEnd Func _Send() _Chat_Add_Line($GUI_RICHEDIT, "You Said : " & GUICtrlRead($GUI_INPUT), 0xFF0000, 12) GUICtrlSetState($GUI_INPUT, $GUI_FOCUS) GUICtrlSetData($GUI_INPUT, "") Return 1 EndFunc ;==>_Send Func _Chat_Add_Line($hWnd, $sMessage, $sColor, $iFont) _GUICtrlRichEdit_PauseRedraw($hWnd) ;SET THE COLOR FOR THE INCOMING TEXT USING THE MODIFIED _GUICtrlRichEdit_SetCharColor THAT DOESN'T STEAL INPUT FOCUS _GUICtrlRichEdit_SetCharColor_No_Selection($hWnd, $sColor) _GUICtrlRichEdit_SetFont($hWnd, $iFont) ;THE "_GUICtrlRichEdit_AppendText" STEALS FOCUS FROM THE INPUT (Because there is a _GuiCtrlRichEdit_SetSel in the function). ;SO I APPEND THE TEXT USING "_GUICtrlEdit_AppendText" FROM "GuiEdit.au3". _GUICtrlEdit_AppendText($hWnd, $sMessage & @CRLF) _GUICtrlRichEdit_ScrollLines($hWnd, 1) _GUICtrlRichEdit_ResumeRedraw($hWnd) Return 1 EndFunc ;==>_Chat_Add_Line ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GUICtrlRichEdit_SetCharColor ; Description....: Sets the color of incoming text inserted at the insertion point ; Syntax ........: _GUICtrlRichEdit_SetCharColor($hWnd[, $iColor]) ; Parameters.....: $hWnd - Handle to the control ; $iColor - one of the following: (Optional) ; |a number - a COLORREF value ; |Default keyword - the system color (default) ; Return values..: Success - True ; Failure - False and sets @error: ; |101 - $hWnd is not a handle ; |1022 - $iColor is invalid ; Authors........: Chris Haslam (c.haslam) ; Modified ......: Jpm, Jmon ; Remarks .......: This Function has been modified to avoid stealing focus from another control ; Related .......: _GUICtrlRichEdit_GetCharColor, _GUICtrlRichEdit_SetCharColor ; Link ..........: @@MsdnLink@@ EM_SETCHARFORMAT ; Example .......: Yes ; =============================================================================================================================== Func _GUICtrlRichEdit_SetCharColor_No_Selection($hWnd, $iColor = Default) If Not IsHWnd($hWnd) Then Return SetError(101, 0, False) Local $tCharFormat = DllStructCreate($tagCHARFORMAT) DllStructSetData($tCharFormat, 1, DllStructGetSize($tCharFormat)) If IsKeyword($iColor) Then DllStructSetData($tCharFormat, 3, $CFE_AUTOCOLOR) $iColor = 0 Else If BitAND($iColor, 0xff000000) Then Return SetError(1022, 0, False) EndIf DllStructSetData($tCharFormat, 2, $CFM_COLOR) DllStructSetData($tCharFormat, 6, $iColor) ;I COMMENTED THOSE NEXT LINES, OTHERWISE THE COLOR WOULD BE APPLIED TO THE WHOLE CONTROL ;~ Local $ai = _GuiCtrlRichEdit_GetSel($hWnd) ;~ If $ai[0] = $ai[1] Then ;~ Return _SendMessage($hWnd, $EM_SETCHARFORMAT, $SCF_ALL, DllStructGetPtr($tCharFormat)) <> 0 ;~ Else Return _SendMessage($hWnd, $EM_SETCHARFORMAT, $SCF_SELECTION, DllStructGetPtr($tCharFormat)) <> 0 ;~ EndIf EndFunc ;==>_GUICtrlRichEdit_SetCharColor_No_Selection Func _Exit() _GUICtrlRichEdit_Destroy($GUI_RICHEDIT) Exit EndFunc ;==>_Exit In Both Example, you can try to type some text in the Input, at the bottom. Use "Enter" to send the text in the Richedit control. Well I hope that solves the problems that others had before. [EDIT1] I ran "tidy" on the scripts for better formatting.
  8. This UDF allows to create formatted label using pseudo element RichLabel (RichEdit actually). Formating is set by using special modificator similar to <font> tag in Html. Notes: This UDF is a transformation-continuation of related UDF Example: Download: GUIRichLabel_1.2.zip Small syntax related fix: GUIRichLabel_1.1.zip GUIRichLabel_1.1.zip History version:
  9. As the title implies, trying to mimic Microsoft Word (Older version) using RichEdit. Not an easy task, it's not even 1/10th of what word really is but I wanted to make a small text editor (That supported changing an individual word/letters properties). Some of the functions I wanted to use didn't have a whole lot of information/topics about them so I spent many many hours trying to figure out how to do some things... (Like getting the text from a ExComboBox or changing the color of the rich edit text without changing ALL of the rich edit text (Turns out I just needed to update my AutoIt version....)) Some of the things I struggled with was reading the Font Size from the ComboBoxEx (GUICtrlRead and ControlGetText do not work, by themselves, but if you use _GUICtrlComboBoxEx_GetEditControl to get the GUICtrlID of the ComboBoxEx you can use ControlGetText), trying to track a Popup menu for the font size (I didn't want to use a dropdown menu, trying to use the scroll wheel to increment/decrement the text in the ComboBoxEx, making sure the correct attribute buttons are Checked depending on the location of the caret (This isn't 100% perfect, I got it to pretty much work though... I originally had it checking the letter 1 left of the caret all the time, except when the caret is at the 0,0 mark, but if the caret is at the very end and the user presses one of the attribute buttons, it won't keep the button checked correctly). There are a few other things but I can't think of them. I don't know enough about the WinAPI in order to make a truly amazing wordpad but maybe this will help some others out there trying to use some of the controls I used. Also, this was actually made to be attached (_WinAPI_SetParent($frmEditor, WinGetHandle("[Class:LWJGL]")) to a game I play (PokeMMO), so there may be some remnants of the game stuff in here. I don't think so, but there might be... It still functions properly. (There is no gameplay automation, it's just supposed to be a child of the game and work as a simple text editor. I've currently submitted it to one of mods of the game so I can release it to the community) Beginnings of a Wordpad.rar
  10. Hey there! I'm gonna try to get access to an RichEdit Control in PSPad with Autoit which is scripted with Delphi. I wrote the commands out ouf the RichEdit.au3 UDF to can change them, because it always fails or crashs, when i call it. I Just want to set the Textcolor for the RichEdit. It seems to be a Problem with $EM_SETCHARFORMAT... (maybe protected?) I can use e.g. $EM_SETBKGNDCOLOR or other messages with no error. Sadly it doesn't exist a message constant to just set the textcolor... This is what i already tried: use $EM_GETCHARFORMAT but it crashs/doesn't work too. I saw the riched20.dll is linked to GDI+ but i couldn't make something work with it... (GetDc and so on but maybe there is another way?) Tried to set some other style on it (setWindowLong) I read the MSDN about $EM_SETCHARFORMAT up and down, but i can't find any other solution. The RichEdit should be version 2 ( error message point to riched20.dll ) Here is the PSPad that will be required for testing: https://autoit.de/wcf/attachment/87712-pspad4autoit3-v1-0-0-beta-without-setup-zip/ You need to start PSPad.exe first! ; = Info =========================================================================================== ; Title : RichEdit_Test ; -------------------------------------------------------------------------------------------------- ; ; Version (vnots) : 0.0.1 ; Date : 2020-05-13 ; Author(s) : Aelc ; ; ================================================================================================== #include <File.au3> #include <Misc.au3> #include <Date.au3> #include <String.au3> #include <GuiListBox.au3> #include <WinAPI.au3> #include <MsgBoxConstants.au3> #include <Color.au3> #include <GuiRichEdit.au3> #include <EditConstants.au3> AutoItSetOption("MustDeclareVars", 1) RichEdit_Test_Main() Func RichEdit_Test_Main() Local $hPSPad = Null Local $tLogCtrls Local $hLB_hwnd Local $hLB_ID $hPSPad = _WinAPI_GetForegroundWindow() If Not WinExists("[CLASS:TfPSPad]") Then MsgBox ( 48,"","PSPad not found." ) Exit EndIf Sleep(1000) $hPSPad = WinGetHandle("[CLASS:TfPSPad]") ;~ If $hPSPad = Null Then ;~ MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, 'AutoIt3_CompilerRunner: - Error -', 'No handle found for PSPad!') ;~ Exit (2) ; 2 = PSPad-hwnd not found ;~ EndIf If _WinAPI_IsClassName($hPSPad, "TfPSPad") Then ; -------------------------------------------------------------------------- If _Singleton("PSPad->RichEdit_Test " & String($hPSPad), 1) = 0 Then MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "RichEdit_Test: - Error -", _ '"RichEdit_Test" is already running') Exit EndIf ; -------------------------------------------------------------------------- $tLogCtrls = PSPad_GetLogControls($hPSPad, 'Log') $hLB_hwnd = $tLogCtrls.hWnd_ListBox $hLB_ID = $tLogCtrls.ID_ListBox If $hLB_hwnd > 0 Then _SendMessage($hLB_hwnd, 0xCF,False) ;Set $READONLY to False Local $tagCHARFORMAT_changeable = "struct;uint cbSize;long dwMask;long dwEffects;long yHeight;long yOffset;INT crTextColor;" & _ "byte bCharSet;byte bPitchAndFamily;wchar szFaceName[32];endstruct" Local $aColor[3] = [0xFF, 0x00, 0xFF] Local $nColor = _ColorSetCOLORREF($aColor) Local $tCharFormat = DllStructCreate($tagCHARFORMAT_changeable) DllStructSetData($tCharFormat, 1, DllStructGetSize($tCharFormat)) DllStructSetData($tCharFormat, 2, $CFM_COLOR) DllStructSetData($tCharFormat, 6, $nColor) MsgBox ( 64,"",_SendMessage($hLB_hwnd, $EM_SETCHARFORMAT, $SCF_SELECTION, $tCharFormat, 0, "wparam", "struct*")) Else ; Log-Fenster konnte nicht gefunden werden. MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "AutoIt3_CompilerRunner: - Error -", _ "The log window of PSPad could not be found.") Exit EndIf Else EndIf EndFunc ;==>RichEdit_Test_Main ;~ Func _RichEditGetTextLength($hWnd) ;~ If Not _WinAPI_IsClassName($hWnd, $__g_sRTFClassName) Then Return SetError(101, 0, 0) ;~ Local $bChars = True ;~ Local $bExact = True ;~ Local $tGetTextLen = DllStructCreate($tagGETTEXTLENGTHEX) ;~ Local $iFlags = BitOR($GTL_USECRLF, ($bExact ? $GTL_PRECISE : $GTL_CLOSE)) ;~ $iFlags = BitOR($iFlags, ($bChars ? $GTL_DEFAULT : $GTL_NUMBYTES)) ;~ DllStructSetData($tGetTextLen, 1, $iFlags) ;~ DllStructSetData($tGetTextLen, 2, ($bChars ? $CP_ACP : $CP_UNICODE)) ;~ Local $iRet = _SendMessage($hWnd, $EM_GETTEXTLENGTHEX, $tGetTextLen, 0, 0, "struct*") ;~ Return $iRet ;~ EndFunc ;==>_RichEditGetTextLength ;~ Func _RichEditGetBKColor($hWnd) ;~ If Not _WinAPI_IsClassName($hWnd, $__g_sRTFClassName) Then Return SetError(101, 0, 0) ;~ Local $iBkColor = _SendMessage($hWnd, $EM_SETBKGNDCOLOR, False, 0) ;~ _SendMessage($hWnd, $EM_SETBKGNDCOLOR, False, $iBkColor) ;~ Return $iBkColor ;~ EndFunc ;==>_RichEditGetBKColor ;~ Func _RichEditSetBKColor($hWnd, $iBkColor) ;~ If Not _WinAPI_IsClassName($hWnd, $__g_sRTFClassName) Then Return SetError(101, 0, 0) ;~ _SendMessage($hWnd, $EM_SETBKGNDCOLOR, False, $iBkColor) ;~ Return $iBkColor ;~ EndFunc ;==>_RichEditSetBKColor Func PSPad_GetLogControls($_hPSPad, $_sSheetText = 'Log') Local $sStruct_LogCtrls = _ 'hwnd hWnd_PageControl;' & _ ; TPageControl 'int ID_PageControl;' & _ 'hwnd hWnd_TabSheet;' & _ ; TTabSheet 'int ID_TabSheet;' & _ 'hwnd hWnd_ListBox;' & _ ; TListBox 'int ID_ListBox;' Local $tResult = DllStructCreate($sStruct_LogCtrls) Local $aEnum Local $sSheet Local $i, $x $aEnum = _WinAPI_EnumChildWindows($_hPSPad, False) If IsArray($aEnum) Then For $i = 1 To $aEnum[0][0] If $aEnum[$i][1] = "TTabSheet" Then $sSheet = ControlGetText($_hPSPad, '', _WinAPI_GetDlgCtrlID($aEnum[$i][0])) If $sSheet = $_sSheetText Then ; TabSheet gefunden. $tResult.hWnd_TabSheet = $aEnum[$i][0] $tResult.ID_TabSheet = _WinAPI_GetDlgCtrlID($tResult.hWnd_TabSheet) $tResult.hWnd_PageControl = _WinAPI_GetParent($tResult.hWnd_TabSheet) $tResult.ID_PageControl = _WinAPI_GetDlgCtrlID($tResult.hWnd_PageControl) For $x = $i + 1 To $aEnum[0][0] If $aEnum[$x][1] = "TRichEdit" Then $tResult.hWnd_ListBox = $aEnum[$x][0] $tResult.ID_ListBox = _WinAPI_GetDlgCtrlID($tResult.hWnd_ListBox) Return $tResult ; Wenn gefunden, dann raus aus der Funktion. EndIf Next EndIf EndIf Next EndIf Return $tResult EndFunc ;==>PSPad_GetLogControls I don't have any ideas anymore But maybe someone else has? I would be happy for every idea Thanks in advance
  11. Hi everybody. Could you tell me is there any UDF that can help to highlight syntax in the _GUICtrlRichEdit element on the fly? Is it possible to implement this feature in script in simple way using some UDF or something, instead of writing thousand of strings manually? Thanks in advance.
  12. Tell me, please, how to set / change the cursor over RichEdit (created with _GUICtrlRichEdit_Create)?
  13. If you look at the help file for the above command, you'll see that it states that it only works for certain zoom values (100 and 200 to 6400). I assume that this is due to an issue in an MSDN library that the command relies on. After doing some investigating, I noticed that the GUIRichEdit.au3 library file contains the following code: ; #FUNCTION# ==================================================================================================================== ; Authors........: Chris Haslam (c.haslam) ; Modified ......: ; =============================================================================================================================== Func _GUICtrlRichEdit_SetZoom($hWnd, $iPercent) If Not _WinAPI_IsClassName($hWnd, $__g_sRTFClassName) Then Return SetError(101, 0, False) If Not __GCR_IsNumeric($iPercent, ">0") Then Return SetError(1021, 0, False) Local $iNumerator, $iDenominator Select Case Not ($iPercent = 100 Or ($iPercent >= 200 And $iPercent < 6400)) Return SetError(1022, 0, False) Case $iPercent >= 100 $iNumerator = 10000 $iDenominator = 10000 / ($iPercent / 100) Case Else $iNumerator = 10000 * ($iPercent / 100) $iDenominator = 10000 EndSelect Return _SendMessage($hWnd, $EM_SETZOOM, $iNumerator, $iDenominator) <> 0 EndFunc ;==>_GUICtrlRichEdit_SetZoom Which ensures that values are only within the bounds specified in the help file. I found that if I comment out the portion of the code that limits the values, the function works fine for most (if not all) values. I changed the code in the library file to this by simply commenting out the restricting lines of code: ; #FUNCTION# ==================================================================================================================== ; Authors........: Chris Haslam (c.haslam) ; Modified ......: ; =============================================================================================================================== Func _GUICtrlRichEdit_SetZoom($hWnd, $iPercent) If Not _WinAPI_IsClassName($hWnd, $__g_sRTFClassName) Then Return SetError(101, 0, False) If Not __GCR_IsNumeric($iPercent, ">0") Then Return SetError(1021, 0, False) Local $iNumerator, $iDenominator Select ; Case Not ($iPercent = 100 Or ($iPercent >= 200 And $iPercent < 6400)) ; Return SetError(1022, 0, False) Case $iPercent >= 100 $iNumerator = 10000 $iDenominator = 10000 / ($iPercent / 100) Case Else $iNumerator = 10000 * ($iPercent / 100) $iDenominator = 10000 EndSelect Return _SendMessage($hWnd, $EM_SETZOOM, $iNumerator, $iDenominator) <> 0 EndFunc ;==>_GUICtrlRichEdit_SetZoom I assume whatever windows bug existed at the time this was created, no longer exists so there is no need to restrict the values. Just wanted to point this out if anyone else is using this part of the library and required this functionality like I did.
  14. Two questions... When presenting a form containing a richedit control, is there any way to make the displayed text, within said richedit control, non-selectable? In addition, is there any way to hide the vertical line cursor, within said richedit control? Thanx.
  15. I've finally come up with some simple solutions for dragging & dropping a URL onto a control. There have been many requests here for this over the years. I do have an issue though, with my second code example solution as is mentioned here. The issue relates to working in Win 7 (and no doubt newer Windows). As I state there, failure is no doubt due to 'MSCOMCT2.OCX' missing from the System32 folder, at the very least. Not sure if it would be wise to just dump 'MSCOMCT2.OCX' from WinXP into the Win 7 System32 folder. I expect not. I imagine there is a better solution available in Win 7. Maybe a different OCX file, and perhaps a different Class of object etc. Any help would be greatly appreciated. Code is here (second example). EDIT Okay, I have rediscovered that 'MSCOMCT2.OCX' is a VB6 ActiveX control. So while I could dig up a copy and register it, that would probably not be helpful to everyone. And registering it didn't help. Possibly other dependencies are also needed? When running the script, it is clear going by the error reported, that Object is not being created.
  16. Please tell me, who knows how to apply and cancel styles in RTF? The following code does not work: #include <GuiRichEdit.au3> #include <WindowsConstants.au3> $hGUI = GUICreate("RichEdit Style", 500, 500, -1, -1) $hRichEdit = _GUICtrlRichEdit_Create($hGui, "Test", 20,40,460,400) GUISetState(@SW_SHOW, $hGUI) Sleep(3000) GUICtrlSetStyle($hRichEdit, $ES_RIGHT) Sleep(3000) GUICtrlSetStyle($hRichEdit, -1) Sleep(3000) Thanks!
  17. I've been working with RichEdits and have come upon the very useful RESH UDF. But I baffled by one statement in the example's _LoadFile() function: _GUICtrlRichEdit_ReplaceText($hRichEdit, '') Can someone explain this "non-replace"? Here's the context:
  18. You can now use your favorite html tags in a richedit control! Supports: <b></b> (bold) <i></i> (italic) <s></s> (strike) <u></u> (underline) <color=#nnnnnn></color> (color text) <color=0xnnnnn></color> (color text) <bkcolor=#nnnnnn></color> (color background text) <bkcolor=0xnnnnnn></color> (color background text) <font name="Font name" size=n></font> (Font name is the only one that has to have quotes around it. They can be double quotes or single, it doesn't matter. color, bkcolor, and size can also use quotes but they're optional) Does not support (but I may add later) <align> <a href=""> <img> ; Functions _GUICtrlRichEdit_AppendHtmlText _StringToRichEditArray __GetArrayFromRegex __GetRichEditAttrFromChar __GUICtrlRichEdit_AppendTextColored __GUICtrlRichEdit_SetTextColor (I'm sure someone can come up with some better names for this lol) You can use a formatted (<color=0xNNNNNN>Formatted</color>) or non-formatted (Non-formatted) string with calling _GUICtrlRichEdit_AppendHtmlText and _StringToRichEditArray. _StringToRichEditArray will just set the attributes, font name, font size, and colors to the current attributes of the RichEdit Control (At least it should... RichEdit can be picky about setting the font and char attributes correctly....). Calling _StringToRichEditArray will return a 2d array with n amount of rows. [n][0] - String [n][1] - Font name for the [0] string. [n][2] - Font size for the [0] string. [n][3] - Character attributes for the [0] string. [n][4] - Text color for the [0] string. [n][5] - Back color for the [0] string. It seems I was too hasty in my release and this still wasn't working 100% . I guess I'll try to work on it tomorrow and see if I can get it working the way tags are supposed to work. It's not a complete waste, it's close but not perfect and I know why. Formatted RichEdit Array V2.rar Html Richedit.rar
  19. I know how to select, set color, then deselect but I'm trying to get more of a Microsoft word style richedit. In word you can Highlight and change color, it only changes color of highlighted text, or you can change the color and it changes the color the text after the caret position. Just doing _GUICtrlRichEdit_SetCharColor($hRichEdit, $color) changes the color for all of the text in the richedit and I'm trying to avoid that. Is this possible?
  20. I switched to Autoit version 3.3.14.2. After compiling the program I found that _GUICtrlRichEdit_SetCharColor function does not work as it should. The color of the text does not apply to all text. Even stopped working example from the help file. Please return properties of the function the former. She used to work clearly and correctly. Thanks!
  21. Hello everyone , I want to set the resizing of a RichEdit control in a GUI, Unfortunately GUICtrlSetResizing only accepts IDs not Handles #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiRichEdit.au3> $hGUI = GUICreate("Test GUI", 500, 300, -1, -1, BitOR($WS_SIZEBOX, $WS_SYSMENU, $WS_VISIBLE)) $hRichEdit = _GUICtrlRichEdit_Create($hGUI, "", 0, 0, 500, 300) ; GUICtrlSetResizing($hRichEdit, $GUI_DOCKAUTO) ; Don't even think of trying this While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEndI want the RichEdit to always fill the whole window, Thanks in Advance TD
  22. Hi, is there a way to convert this Code to an Code which can make more than one Color in one line? Func _GUICtrlRichEdit_WriteLine($hWnd, $sText, $iIncrement = 0, $sAttrib = "", $iColor = -1) ; Count the @CRLFs StringReplace(_GUICtrlRichEdit_GetText($hWnd, True), @CRLF, "") Local $iLines = @extended ; Adjust the text char count to account for the @CRLFs Local $iEndPoint = _GUICtrlRichEdit_GetTextLength($hWnd, True, True) - $iLines ; Add new text _GUICtrlRichEdit_AppendText($hWnd, $sText & @CRLF) ; Select text between old and new end points _GuiCtrlRichEdit_SetSel($hWnd, $iEndPoint, -1) ; Convert colour from RGB to BGR $iColor = Hex($iColor, 6) $iColor = '0x' & StringMid($iColor, 5, 2) & StringMid($iColor, 3, 2) & StringMid($iColor, 1, 2) ; Set colour If $iColor <> -1 Then _GuiCtrlRichEdit_SetCharColor($hWnd, $iColor) ; Set size If $iIncrement <> 0 Then _GUICtrlRichEdit_ChangeFontSize($hWnd, $iIncrement) ; Set weight If $sAttrib <> "" Then _GUICtrlRichEdit_SetCharAttributes($hWnd, $sAttrib) ; Clear selection _GUICtrlRichEdit_Deselect($hWnd) EndFunc
  23. Hi all, I am up to change the font of a rich edit control. I need to set an unicode font(Malayalam). But the code doesn't working. see this. Global $EditMallu = _GUICtrlRichEdit_Create ($FormM2M,"", 520, 37, 489, 417) _GUICtrlRichEdit_SetText ($EditMallu, "]co£Ww") _GUICtrlRichEdit_SetFont ($EditMallu, 14, "MLTTRevathi") ;GUICtrlSetColor($EditMallu, 0x0000FF) _GUICtrlRichEdit_SetEventMask($EditMallu, "EditMalluChange") Original name of that font is this = "ML-TTRevathi". What is wrong with it ? Edit - I can't change the font color too.
  24. This is a basic editor that uses IE functions and jasvscript/css to control the display and highlight terms. It sets the html docuement in to edit mode, to be used as the edit box, and the javascript scans and runs the highlighter onkeyup. The example is set to highlight "If", "Then" and "EndIf". If you were to type "endif", it would automatically change it to "EndIf" and highlight it. Example Source Code: #NoTrayIcon #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <IE.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Opt("GUIResizeMode", $GUI_DOCKAUTO) Opt("TrayMenuMode", 3) Local $html = '', $r = @CRLF $html &= '<html>'&$r $html &= '<head>'&$r $html &= ' <script type="text/javascript">'&$r $html &= ' function HighlightSyntax(word,highlightcolor) {'&$r $html &= ' var replacement = "<span class=''color-" + highlightcolor + "''>" + word + "</span>";' $html &= ' var re = new RegExp(word, "ig");' $html &= ' document.body.innerHTML = document.body.innerHTML.replace(re, replacement);' $html &= ' '&$r $html &= ' }'&$r $html &= ' function SyntaxHighlighter() {'&$r $html &= ' HighlightSyntax("EndIf","blue");'&$r $html &= ' HighlightSyntax("If","blue");'&$r $html &= ' HighlightSyntax("Then","blue");'&$r $html &= ' }'&$r $html &= ' </script>'&$r $html &= ' <style type="text/css">'&$r $html &= ' html, body { width: 100%; height: 100%; background: #FFFFFF; color: #000000; border: 0px none; font-family: times; font-size: 14px; padding: 0px; margin: 0px; }'&$r $html &= ' p { padding: 0px; margin: 0px; }'&$r $html &= ' .color-blue { color: #0000FF; }'&$r $html &= ' </style>'&$r $html &= '</head>'&$r $html &= '<body onkeyup="SyntaxHighlighter()" contenteditable="true" designMode="on">'&$r $html &= '</body>'&$r $html &= '</html>' Global $UI_FORM = GUICreate("Syntax Highlighting, Resizable Rich Text Editor", 601, 371, 192, 124, BitOR($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZEBOX,$WS_CLIPCHILDREN,$WS_TABSTOP,$WS_SIZEBOX), BitOR($WS_EX_TRANSPARENT,$WS_EX_WINDOWEDGE)) Local $UI_MENU_File = GUICtrlCreateMenu("&File") Global $UI_MENU_Exit = GUICtrlCreateMenuItem("&Exit", $UI_MENU_File) Global $UI_IE = _IECreateEmbedded() Global $UI_IEOject = GUICtrlCreateObj($UI_IE, 0, 0, 600, 350) GUICtrlSetOnEvent($UI_MENU_Exit, "GUI_Close") GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_Close", $UI_FORM) GUICtrlSetResizing($UI_IEOject, $GUI_DOCKAUTO) GUISetState(@SW_SHOW, $UI_FORM) _IENavigate($UI_IE, "about:blank") _IEDocWriteHTML($UI_IE, $html) While 1 Sleep(10) WEnd Func GUI_Close() GUIDelete($UI_FORM) Exit EndFunc
  25. Hey ya'll! Quick question: Is it possible to make text in a _GUICtrlRichEdit_Create:ed control strikethrough, much like you can do with the GUICtrlSetFont:s Attribute-parameter? It has to able to do so with selected text and not with everything in the control. Thanks in advance, zvvyt
×
×
  • Create New...