Ticket #2790: StreamToFile Problem.au3

File StreamToFile Problem.au3, 6.0 KB (added by qwert, on Jul 11, 2014 at 4:43:19 PM)

RichEdit_StreamToFile reference copies

Line 
1
2;
3;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
4; AS IN 3.3.12.0 .... note the ? marks in the iWparam statements ... BUT MAINLY the "If $hFile - 1 Then ..." statement
5;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
6
7; #FUNCTION# ====================================================================================================================
8; Authors........: Chris Haslam (c.haslam)
9; Modified ......:
10; ===============================================================================================================================
11Func _GUICtrlRichEdit_StreamToFile($hWnd, $sFilespec, $bIncludeCOM = True, $iOpts = 0, $iCodePage = 0)
12 If Not _WinAPI_IsClassName($hWnd, $__g_sRTFClassName) Then Return SetError(101, 0, False)
13
14 Local $iWparam
15 If StringRight($sFilespec, 4) = ".rtf" Then
16 $iWparam = ($bIncludeCOM ? $SF_RTF : $SF_RTFNOOBJS)
17 Else
18 $iWparam = ($bIncludeCOM ? $SF_TEXTIZED : $SF_TEXT)
19 If BitAND($iOpts, $SFF_PLAINRTF) Then Return SetError(1041, 0, False)
20 EndIf
21 ; only opts are $SFF_PLAINRTF and $SF_UNICODE
22 If BitAND($iOpts, BitNOT(BitOR($SFF_PLAINRTF, $SF_UNICODE))) Then Return SetError(1042, 0, False)
23 If BitAND($iOpts, $SF_UNICODE) Then
24 If Not BitAND($iWparam, $SF_TEXT) Then Return SetError(1043, 0, False)
25 EndIf
26
27 If _GUICtrlRichEdit_IsTextSelected($hWnd) Then $iWparam = BitOR($iWparam, $SFF_SELECTION)
28
29 $iWparam = BitOR($iWparam, $iOpts)
30 If $iCodePage <> 0 Then
31 $iWparam = BitOR($iWparam, $SF_USECODEPAGE, BitShift($iCodePage, -16))
32 EndIf
33 Local $tEditStream = DllStructCreate($tagEDITSTREAM)
34 DllStructSetData($tEditStream, "pfnCallback", DllCallbackGetPtr($__g_pGRC_StreamToFileCallback))
35 Local $hFile = FileOpen($sFilespec, $FO_OVERWRITE)
36 If $hFile - 1 Then Return SetError(102, 0, False) ;<<<<<<<<<<<<<<<<<<<<<<<<<<< problem
37
38 DllStructSetData($tEditStream, "dwCookie", $hFile) ; -> Send handle to CallbackFunc
39 _SendMessage($hWnd, $EM_STREAMOUT, $iWparam, $tEditStream, 0, "wparam", "struct*")
40 FileClose($hFile)
41 Local $iError = DllStructGetData($tEditStream, "dwError")
42 If $iError <> 0 Then SetError(700, $iError, False)
43 Return True
44EndFunc ;==>_GUICtrlRichEdit_StreamToFile
45
46
47;
48; AS IT WAS IN 3.3.8.1 ... for reference <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
49;
50; #FUNCTION# ====================================================================================================================
51; Name ..........: _GUICtrlRichEdit_StreamToFile
52; Description....: Writes contens of a control to a file
53; Syntax ........: _GUICtrlRichEdit_StreamToFile($hWnd, $sFilespec[, $fIncludeCOM=True[, $iOpts=0[, $iCodePage = 0]]])
54; Parameters.....: $hWnd - Handle to the control
55; $sFileSpec - file specification
56; $fIncludeCOM - (Optional)
57; |True (default):
58; | If writing to a .rtf file, includes any COM objects (space consuming)
59; | If writing to any other file, writes a text represntation of COM objects
60; |False: Writes spaces instead of COM objects
61; $iOpts - additional options: (Optional) (default: 0)
62; |$SFF_PLAINTRTF - write only rich text keywords common to all languages
63; |$SF_UNICODE - write Unicode
64; $iCodePage - Generate UTF-8 and text using this code page (Optional)
65; |Default: do not
66; Return values..: Success - True
67; Failure - False and sets @error:
68; |101 - $hWnd is not a handle
69; |102 - Can't create $sFilespec
70; |1041 - $SFF_PLAINRTF is invalid for a text file
71; |1042 - $opts: invalid option
72; |1043 - $SF_UNICODE is only valid for a text file
73; |700 - internal error
74; Authors........: Chris Haslam (c.haslam)
75; Modified ......:
76; Remarks .......: If text is selected, writes only the selection, else writes all text in the control
77;+
78; If the extension in $sFileSpec is .rtf, RTF is written, else text
79; Related .......: _GUICtrlRichEdit_SetLimitOnText, _GUICtrlRichEdit_StreamFromVar, _GUICtrlRichEdit_StreamToFile
80; Link ..........: @@MsdnLink@@ EM_STREAMIN
81; Example .......: Yes
82; ===============================================================================================================================
83Func _GUICtrlRichEdit_StreamToFile($hWnd, $sFilespec, $fIncludeCOM = True, $iOpts = 0, $iCodePage = 0)
84 If Not _WinAPI_IsClassName($hWnd, $_GRE_sRTFClassName) Then Return SetError(101, 0, False)
85
86 Local $iWparam
87 If StringRight($sFilespec, 4) = ".rtf" Then
88 $iWparam = _Iif($fIncludeCOM, $SF_RTF, $SF_RTFNOOBJS)
89 Else
90 $iWparam = _Iif($fIncludeCOM, $SF_TEXTIZED, $SF_TEXT)
91 If BitAND($iOpts, $SFF_PLAINRTF) Then Return SetError(1041, 0, False)
92 EndIf
93 ; only opts are $SFF_PLAINRTF and $SF_UNICODE
94 If BitAND($iOpts, BitNOT(BitOR($SFF_PLAINRTF, $SF_UNICODE))) Then Return SetError(1042, 0, False)
95 If BitAND($iOpts, $SF_UNICODE) Then
96 If Not BitAND($iWparam, $SF_TEXT) Then Return SetError(1043, 0, False)
97 EndIf
98
99 If _GUICtrlRichEdit_IsTextSelected($hWnd) Then $iWparam = BitOR($iWparam, $SFF_SELECTION)
100
101 $iWparam = BitOR($iWparam, $iOpts)
102 If $iCodePage <> 0 Then
103 $iWparam = BitOR($iWparam, $SF_USECODEPAGE, BitShift($iCodePage, -16))
104 EndIf
105 Local $tEditStream = DllStructCreate($tagEDITSTREAM)
106 DllStructSetData($tEditStream, "pfnCallback", DllCallbackGetPtr($_GRC_StreamToFileCallback))
107 Local $hFile = FileOpen($sFilespec, 2) ; overwrite
108 If $hFile - 1 Then Return SetError(102, 0, False)
109
110 DllStructSetData($tEditStream, "dwCookie", $hFile) ; -> Send handle to CallbackFunc
111 _SendMessage($hWnd, $EM_STREAMOUT, $iWparam, $tEditStream, 0, "wparam", "struct*")
112 FileClose($hFile)
113 Local $iError = DllStructGetData($tEditStream, "dwError")
114 If $iError <> 0 Then SetError(700, $iError, False)
115 Return True
116EndFunc ;==>_GUICtrlRichEdit_StreamToFile
117