wolf9228 Posted April 7, 2010 Share Posted April 7, 2010 ;Example ;The following example code prints the contents of a rich edit control to the specified printer. http://msdn.microsoft.com/en-us/library/bb787875(VS.85).aspx expandcollapse popup#Include <WinAPI.au3> #include <GuiRichEdit.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Include <SendMessage.au3> #Include <RichEditConstants.au3> Const $PD_USEDEVMODECOPIESANDCOLLATE = 0x00040000 ,$PD_RETURNDC = 0x00000100 , _ $PD_RETURNDEFAULT = 0x00000400 $tagPD = "DWORD lStructSize;HWND hwndOwner;HANDLE hDevMode;HANDLE hDevNames;" & _ "HANDLE hDC;DWORD Flags;USHORT nFromPage;USHORT nToPage;USHORT nMinPage;USHORT " & _ "nMaxPage;USHORT nCopies;HANDLE hInstance;lparam lCustData;int lpfnPrintHook;" & _ "int lpfnSetupHook;char lpPrintTemplateName[4];char lpSetupTemplateName[4];" & _ "HANDLE hPrintTemplate;HANDLE hSetupTemplate" $PRINTDLGA = DllStructCreate($tagPD) DllStructSetData($PRINTDLGA,"lStructSize",66) DllStructSetData($PRINTDLGA,"hwndOwner",0) DllStructSetData($PRINTDLGA,"hDevMode",0) DllStructSetData($PRINTDLGA,"hDevNames",0) DllStructSetData($PRINTDLGA,"Flags",$PD_USEDEVMODECOPIESANDCOLLATE + $PD_RETURNDC) $pd = DllStructGetPtr($PRINTDLGA) $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName,4) &")", 320, 350, -1, -1) $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) $Button_1 = GUICtrlCreateButton("Print RTF", 10, 250, 100) GUISetState() While True $iMsg = GUIGetMsg() Select Case $iMsg = $GUI_EVENT_CLOSE GUIDelete() Exit Case $iMsg = $Button_1 if (PrintDlg($pd) == 1) Then $hdc = DllStructGetData($PRINTDLGA,"hDC") MsgBox(0,"", _ PrintRTF($hRichEdit, $hdc)) EndIf EndSelect WEnd Func PrintDlg($LPPRINTDLG_lppd) $Comdlg32 = DllOpen("Comdlg32.dll") $BOOL = DllCall($Comdlg32,"int","PrintDlgW","ptr",$LPPRINTDLG_lppd) if Not @error Then DllClose($Comdlg32) Return $BOOL[0] EndIf DllClose($Comdlg32) Return False EndFunc ;Example ;The following example code prints the contents of a rich edit control to the specified printer. ;http://msdn.microsoft.com/en-us/library/bb787875(VS.85).aspx Func PrintRTF($hwnd, $hdc) $TagDOCINFOA = "int cbSize;char lpszDocName[4];char lpszOutput[4];" & _ "char lpszDatatype[4];DWORD fwType" $DOCINFOA = DllStructCreate($TagDOCINFOA) DllStructSetData($DOCINFOA,"cbSize",DllStructGetSize($DOCINFOA)) $LPDOCINFOA = DllStructGetPtr($DOCINFOA) $RT = DllCall("Gdi32.dll","int","StartDoc","HANDLE",$hdc,"ptr",$LPDOCINFOA) if @error Then Return False if $RT[0] == 0 Then Return False Local $PHYSICALWIDTH = 110 , $PHYSICALHEIGHT = 111 , _ $PHYSICALOFFSETX = 112 , $PHYSICALOFFSETY = 113 $cxPhysOffset = _WinAPI_GetDeviceCaps($hdc, $PHYSICALOFFSETX) $cyPhysOffset = _WinAPI_GetDeviceCaps($hdc, $PHYSICALOFFSETY) $cxPhys = _WinAPI_GetDeviceCaps($hdc, $PHYSICALWIDTH) $cyPhys = _WinAPI_GetDeviceCaps($hdc, $PHYSICALHEIGHT) _SendMessage($hwnd, $EM_SETTARGETDEVICE, $hdc, $cxPhys/2) $rc = "int Left1;int Top1;int Right1;int Bottom1;" $rcPage = "int Left2;int Top2;int Right2;int Bottom2;" $charrange = "LONG cpMin;LONG cpMax" $Tagformatrange = "HANDLE hdc;HANDLE hdcTarget;" & $rc & $rcPage & $charrange $FORMATRANGE = DllStructCreate($Tagformatrange) DllStructSetData($FORMATRANGE,"hdcTarget",$hdc) DllStructSetData($FORMATRANGE,"Left1",$cxPhysOffset) DllStructSetData($FORMATRANGE,"Right1",$cxPhysOffset + $cxPhys) DllStructSetData($FORMATRANGE,"Top1",$cyPhysOffset) DllStructSetData($FORMATRANGE,"Bottom1",$cyPhysOffset + $cyPhys) _SendMessage($hwnd, $EM_SETSEL, 0,-1) _SendMessage($hwnd, $EM_EXGETSEL, 0, DllStructGetPtr($FORMATRANGE) + _ DllStructGetSize(DllStructCreate("HANDLE hdc;HANDLE hdcTarget;" & $rc & $rcPage))) Local $fSuccess = TRUE while DllStructGetData($FORMATRANGE,"cpMin") < DllStructGetData($FORMATRANGE,"cpMax") And $fSuccess $StartPage = DllCall("Gdi32.dll","int","StartPage","HANDLE",$hdc) $StartPage = $StartPage[0] $fSuccess = $StartPage > 0 if Not ($fSuccess) Then ExitLoop $cpMin = _SendMessage($hwnd, $EM_FORMATRANGE, TRUE, DllStructGetPtr($FORMATRANGE)) if ($cpMin <= DllStructGetData($FORMATRANGE,"cpMin")) Then $fSuccess = FALSE ExitLoop EndIf DllStructSetData($FORMATRANGE,"cpMin",$cpMin) $EndPage = DllCall("Gdi32.dll","int","EndPage","HANDLE",$hdc) $EndPage = $EndPage[0] $fSuccess = $EndPage > 0 WEnd _SendMessage($hwnd, $EM_FORMATRANGE, FALSE, 0) if ($fSuccess) Then DllCall("Gdi32.dll","int","EndDoc","HANDLE",$hdc) else DllCall("Gdi32.dll","int","AbortDoc","HANDLE",$hdc) EndIf return $fSuccess EndFunc صرح السماء كان هنا Link to comment Share on other sites More sharing options...
martin Posted April 7, 2010 Share Posted April 7, 2010 I get a blank page when I try that, even if I have lots of lines in the rich edit control. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
MatteoGuallini Posted April 8, 2010 Share Posted April 8, 2010 Good job!!!! However the problem is alwais the same. GuiRichEdit isnt't fully compatible with RTF generated by MS Word. http://www.vigevano-prabis.it/ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now