Jump to content

Class create


wolf9228
 Share

Recommended Posts

With this project, you can create a Class with a set of functions... There are two examples for the rich editor. The code speaks for itself

 

Class.zip

Class.au3

#include <Memory.au3>

Func AddClassVariable($VariableArray,$VariableType,$VariableName,$VariableVale)

if Not IsArray($VariableArray) Then
Local $cVariableArray[1][3]
Else
$cVariableArray = $VariableArray
ReDim $cVariableArray[UBound($cVariableArray) + 1][3]
EndIf

$cVariableArray[UBound($cVariableArray) - 1][0] = $VariableType
$cVariableArray[UBound($cVariableArray) - 1][1] = $VariableName
$cVariableArray[UBound($cVariableArray) - 1][2] = $VariableVale

Return $cVariableArray

EndFunc

Func AddClassMethod($MethodArray,$MethodName,$MethodPointer)

if Not IsArray($MethodArray) Then
Local $cMethodArray[1][3]
Else
$cMethodArray = $MethodArray
ReDim $cMethodArray[UBound($cMethodArray) + 1][2]
EndIf

$cMethodArray[UBound($cMethodArray) - 1][0] = $MethodName
$cMethodArray[UBound($cMethodArray) - 1][1] = $MethodPointer

Return $cMethodArray

EndFunc

Func NewClass($MethodArray,$VariableArray = 0)

Local $TagClass = "",$Tag_Class = "",$UBoundA = UBound($MethodArray),$UBoundB = UBound($VariableArray)

if $UBoundA + $UBoundB = 0 Then Return SetError(1,0,0)

if $UBoundA Then
For $i = 1 To $UBoundA
$TagClass &= "PTR " & $MethodArray[$i - 1][0] & ";"
Next
$TagClass = StringTrimRight($TagClass,1)
EndIf

if $UBoundB Then
For $i = 1 To $UBoundB
$Tag_Class &= $VariableArray[$i - 1][0] & " " & $VariableArray[$i - 1][1] & ";"
Next
$Tag_Class = StringTrimRight($Tag_Class,1)
EndIf

$NewClass = DllStructCreate($TagClass,_MemGlobalLock(_MemGlobalAlloc(DllStructGetSize(DllStructCreate($TagClass)))))
if @error And StringLen($TagClass) Then SetError(3,0,0)

if $UBoundA Then
For $i = 1 To $UBoundA
DllStructSetData($NewClass,$MethodArray[$i - 1][0],$MethodArray[$i - 1][1])
if @error Then Return SetError(4,0,0)
Next
EndIf

$cTag_Class = "PTR;INT;INT;INT;WCHAR[" & StringLen($TagClass) + 2 & "]" & ";WCHAR[" & StringLen($Tag_Class) + 2 & "];" & $Tag_Class
$New_Class = DllStructCreate($cTag_Class,_MemGlobalLock(_MemGlobalAlloc(DllStructGetSize(DllStructCreate($cTag_Class)))))

DllStructSetData($New_Class,1,DllStructGetPtr($NewClass))
DllStructSetData($New_Class,3 , StringLen($TagClass) + 2)
DllStructSetData($New_Class, 4,StringLen($Tag_Class) + 2)

DllStructSetData($New_Class,2,0123456789)
DllStructSetData($New_Class,5, $TagClass)
DllStructSetData($New_Class,6,$Tag_Class)

if $UBoundB Then
For $i = 1 To $UBoundB
DllStructSetData($New_Class,$VariableArray[$i - 1][1],$VariableArray[$i - 1][2])
if @error Then Return SetError(5,0,0)
Next
EndIf

Return SetError(0,0,DllStructGetPtr($New_Class))

EndFunc

Func GetValue($Object,$VarName)
$Class = DllStructCreate("PTR;INT;INT;INT",$Object)
$FormatNumbr = DllStructGetData($Class,2)
if ($FormatNumbr <> 0123456789) Then Return SetError(6,0,0) ; error 6
$StrLenA = DllStructGetData($Class,3)
$StrLenB = DllStructGetData($Class,4)
$Class = DllStructCreate("PTR;INT;INT;INT;WCHAR[" & $StrLenA & "]" & ";WCHAR[" & $StrLenB & "]",$Object)
$Tag_Class = DllStructGetData($Class,6)
$ClassSt = DllStructCreate("PTR;INT;INT;INT;WCHAR[" & $StrLenA & "]" & ";WCHAR[" & $StrLenB & "];" & $Tag_Class,$Object)
$Value = DllStructGetData($ClassSt,$VarName) ; DllStructGetData @error ==> 1 2 3 4 5
Return SetError(@error,0,$Value) ; DllStructGetData @error ==> 1 2 3 4 5
EndFunc

Func SetValue($Object,$VarName,$Value)
$Class = DllStructCreate("PTR;INT;INT;INT",$Object)
$FormatNumbr = DllStructGetData($Class,2)
if ($FormatNumbr <> 0123456789) Then Return SetError(6,0,0) ; error 6
$StrLenA = DllStructGetData($Class,3)
$StrLenB = DllStructGetData($Class,4)
$Class = DllStructCreate("PTR;INT;INT;INT;WCHAR[" & $StrLenA & "]" & ";WCHAR[" & $StrLenB & "]",$Object)
$Tag_Class = DllStructGetData($Class,6)
$ClassSt = DllStructCreate("PTR;INT;INT;INT;WCHAR[" & $StrLenA & "]" & ";WCHAR[" & $StrLenB & "];" & $Tag_Class,$Object)
$Value = DllStructSetData($ClassSt,$VarName,$Value)
Return SetError(@error,0,$Value) ;DllStructSetData @error ==> 1 2 3 4 5
EndFunc


Func CallMethodA($ReturnType,$MethodNumber,$MehParams,$VarType1 = 0,$VarName1 = 0,$VarType2 = 0,$VarName2 = 0 , $VarType3 = 0 , $VarName3 = 0 ,$VarType4 = 0, _
$VarName4 = 0,$VarType5 = 0 , $VarName5 = 0 , $VarType6 = 0 , $VarName6 = 0 , $VarType7 = 0,$VarName7 = 0,$VarType8 = 0,$VarName8 = 0,$VarType9 = 0,$VarName9 = 0, _
$VarType10 = 0,$VarName10 = 0 , $VarType11 = 0 , $VarName11 = 0 , $VarType12 = 0 , $VarName12 = 0 ,$VarType13 = 0 ,$VarName13 = 0 ,$VarType14 = 0 ,$VarName14 = 0, _
$VarType15 = 0,$VarName15 = 0 , $VarType16 = 0 ,  $VarName16 = 0 , $VarType17 = 0 , $VarName17 = 0 , $VarType18 = 0 ,$VarName18 = 0,$VarType19 = 0,$VarName19 = 0, _
$VarType20 = 0,$VarName20 = 0)

;$MehParams ==> @NumParams macro

$Class = DllStructCreate("PTR Class",$VarName1)
$MethodSt = DllStructCreate("PTR",DllStructGetData($Class,1) + (($MethodNumber - 1) * 4))
$MethodPtr = DllStructGetData($MethodSt,1)

Switch $MehParams
Case 1
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1)
Case 2
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2)
Case 3
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3)
Case 4
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4)
Case 5
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5)
Case 6
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6)
Case 7
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7)
Case 8
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8)
Case 9
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8,$VarType9,$VarName9)
Case 10
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8,$VarType9,$VarName9,$VarType10,$VarName10)
Case 11
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8,$VarType9,$VarName9,$VarType10,$VarName10,$VarType11,$VarName11)
Case 12
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8,$VarType9,$VarName9,$VarType10,$VarName10,$VarType11,$VarName11,$VarType12,$VarName12)
Case 13
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8,$VarType9,$VarName9,$VarType10,$VarName10,$VarType11,$VarName11,$VarType12,$VarName12, _
$VarType13,$VarName13)
Case 14
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8,$VarType9,$VarName9,$VarType10,$VarName10,$VarType11,$VarName11,$VarType12,$VarName12, _
$VarType13,$VarName13,$VarType14,$VarName14)
Case 15
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8,$VarType9,$VarName9,$VarType10,$VarName10,$VarType11,$VarName11,$VarType12,$VarName12, _
$VarType13,$VarName13,$VarType14,$VarName14,$VarType15,$VarName15)
Case 16
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8,$VarType9,$VarName9,$VarType10,$VarName10,$VarType11,$VarName11,$VarType12,$VarName12, _
$VarType13,$VarName13,$VarType14,$VarName14,$VarType15,$VarName15,$VarType16,$VarName16)
Case 17
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8,$VarType9,$VarName9,$VarType10,$VarName10,$VarType11,$VarName11,$VarType12,$VarName12, _
$VarType13,$VarName13,$VarType14,$VarName14,$VarType15,$VarName15,$VarType16,$VarName16,$VarType17,$VarName17)
Case 18
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8,$VarType9,$VarName9,$VarType10,$VarName10,$VarType11,$VarName11,$VarType12,$VarName12, _
$VarType13,$VarName13,$VarType14,$VarName14,$VarType15,$VarName15,$VarType16,$VarName16,$VarType17,$VarName17,$VarType18,$VarName18)
Case 19
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8,$VarType9,$VarName9,$VarType10,$VarName10,$VarType11,$VarName11,$VarType12,$VarName12, _
$VarType13,$VarName13,$VarType14,$VarName14,$VarType15,$VarName15,$VarType16,$VarName16,$VarType17,$VarName17,$VarType18,$VarName18,$VarType19, _
$VarName19)
Case 20
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8,$VarType9,$VarName9,$VarType10,$VarName10,$VarType11,$VarName11,$VarType12,$VarName12, _
$VarType13,$VarName13,$VarType14,$VarName14,$VarType15,$VarName15,$VarType16,$VarName16,$VarType17,$VarName17,$VarType18,$VarName18,$VarType19, _
$VarName19,$VarType20,$VarName20)
EndSwitch

Return SetError(1,0,0)

EndFunc

Func CallMethodB($ReturnType,$MethodName,$MehParams,$VarType1 = 0,$VarName1 = 0,$VarType2 = 0,$VarName2 = 0 , $VarType3 = 0 , $VarName3 = 0 ,$VarType4 = 0, _
$VarName4 = 0,$VarType5 = 0 , $VarName5 = 0 , $VarType6 = 0 , $VarName6 = 0 , $VarType7 = 0,$VarName7 = 0,$VarType8 = 0,$VarName8 = 0,$VarType9 = 0,$VarName9 = 0, _
$VarType10 = 0,$VarName10 = 0 , $VarType11 = 0 , $VarName11 = 0 , $VarType12 = 0 , $VarName12 = 0 ,$VarType13 = 0 ,$VarName13 = 0 ,$VarType14 = 0 ,$VarName14 = 0, _
$VarType15 = 0,$VarName15 = 0 , $VarType16 = 0 ,  $VarName16 = 0 , $VarType17 = 0 , $VarName17 = 0 , $VarType18 = 0 ,$VarName18 = 0,$VarType19 = 0,$VarName19 = 0, _
$VarType20 = 0,$VarName20 = 0)

;$MehParams ==> @NumParams macro

$Class = DllStructCreate("PTR;INT;INT;INT",$VarName1)
$FormatNumbr = DllStructGetData($Class,2)
if ($FormatNumbr <> 0123456789) Then Return SetError(1,0,0)
$StrLenA = DllStructGetData($Class,3)
$StrLenB = DllStructGetData($Class,4)
$Class = DllStructCreate("PTR;INT;INT;INT;WCHAR[" & $StrLenA & "]" & ";WCHAR[" & $StrLenB & "]",$VarName1)
$TagClass = DllStructGetData($Class,5)
$ClassSt = DllStructCreate($TagClass,DllStructGetData($Class,1))
$MethodPtr = DllStructGetData($ClassSt,$MethodName)
if @error Then Return SetError(2,0,0)

Switch $MehParams
Case 1
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1)
Case 2
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2)
Case 3
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3)
Case 4
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4)
Case 5
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5)
Case 6
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6)
Case 7
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7)
Case 8
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8)
Case 9
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8,$VarType9,$VarName9)
Case 10
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8,$VarType9,$VarName9,$VarType10,$VarName10)
Case 11
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8,$VarType9,$VarName9,$VarType10,$VarName10,$VarType11,$VarName11)
Case 12
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8,$VarType9,$VarName9,$VarType10,$VarName10,$VarType11,$VarName11,$VarType12,$VarName12)
Case 13
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8,$VarType9,$VarName9,$VarType10,$VarName10,$VarType11,$VarName11,$VarType12,$VarName12, _
$VarType13,$VarName13)
Case 14
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8,$VarType9,$VarName9,$VarType10,$VarName10,$VarType11,$VarName11,$VarType12,$VarName12, _
$VarType13,$VarName13,$VarType14,$VarName14)
Case 15
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8,$VarType9,$VarName9,$VarType10,$VarName10,$VarType11,$VarName11,$VarType12,$VarName12, _
$VarType13,$VarName13,$VarType14,$VarName14,$VarType15,$VarName15)
Case 16
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8,$VarType9,$VarName9,$VarType10,$VarName10,$VarType11,$VarName11,$VarType12,$VarName12, _
$VarType13,$VarName13,$VarType14,$VarName14,$VarType15,$VarName15,$VarType16,$VarName16)
Case 17
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8,$VarType9,$VarName9,$VarType10,$VarName10,$VarType11,$VarName11,$VarType12,$VarName12, _
$VarType13,$VarName13,$VarType14,$VarName14,$VarType15,$VarName15,$VarType16,$VarName16,$VarType17,$VarName17)
Case 18
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8,$VarType9,$VarName9,$VarType10,$VarName10,$VarType11,$VarName11,$VarType12,$VarName12, _
$VarType13,$VarName13,$VarType14,$VarName14,$VarType15,$VarName15,$VarType16,$VarName16,$VarType17,$VarName17,$VarType18,$VarName18)
Case 19
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8,$VarType9,$VarName9,$VarType10,$VarName10,$VarType11,$VarName11,$VarType12,$VarName12, _
$VarType13,$VarName13,$VarType14,$VarName14,$VarType15,$VarName15,$VarType16,$VarName16,$VarType17,$VarName17,$VarType18,$VarName18,$VarType19, _
$VarName19)
Case 20
Return DllCallAddress($ReturnType,$MethodPtr,$VarType1,$VarName1,$VarType2,$VarName2,$VarType3,$VarName3,$VarType4,$VarName4,$VarType5,$VarName5, _
$VarType6,$VarName6,$VarType7,$VarName7,$VarType8,$VarName8,$VarType9,$VarName9,$VarType10,$VarName10,$VarType11,$VarName11,$VarType12,$VarName12, _
$VarType13,$VarName13,$VarType14,$VarName14,$VarType15,$VarName15,$VarType16,$VarName16,$VarType17,$VarName17,$VarType18,$VarName18,$VarType19, _
$VarName19,$VarType20,$VarName20)
EndSwitch

Return SetError(3,0,0)

EndFunc

Func DeleteClass($Object)
$Class = DllStructCreate("PTR Class",$Object)
$ClassPtr = DllStructGetData($Class,1)
_MemGlobalFree(GlobalHandle($ClassPtr))
_MemGlobalFree( GlobalHandle ($Object))
EndFunc

Func GlobalHandle($pMem)
$Return = DllCall("Kernel32.dll","ptr","GlobalHandle","ptr",$pMem)
if @error Then Return SetError(1,0,0)
Return $Return[0]
EndFunc

RichEdit_Class.au3

#include <Class.au3>

Global $S_OK = 0 , $E_NOTIMPL = 0x80004001

Func RichEdit_CB_QueryInterface($Object,$iid,$ppvObject)
return $S_OK
EndFunc

Func RichEdit_CB_AddRef($Object)
return SetValue($Object,"nCount",GetValue($Object,"nCount") + 1)
EndFunc

Func RichEdit_CB_Release($Object)
if (GetValue($Object,"nCount") > 0) Then return SetValue($Object,"nCount",GetValue($Object,"nCount") - 1)
return $S_OK;
EndFunc

Func RichEdit_CB_GetNewStorage($Object,$lplpstg)

$nHresult = DllCall("Ole32.dll","LONG","CreateILockBytesOnHGlobal","PTR",0,"BOOL",True,"PTR*",0)
if (@error Or $nHresult[0] <> $S_OK) Then return $nHresult[0]

$Lock_Bytes = $nHresult[3]

;BitOR(STGM_SHARE_EXCLUSIVE,STGM_READWRITE,STGM_CREATE)
$nHresult = DllCall("Ole32.dll","LONG","StgCreateDocfileOnILockBytes","PTR",$Lock_Bytes _
,"DWORD",BitOR(0x00000010,0x00000002,0x00001000),"DWORD",0,"PTR*",0)

if (@error Or $nHresult[0] <> $S_OK) Then CallMethodA("LONG",3,1,"PTR",$Lock_Bytes) ; Call Release() Method In $Lock_Bytes Obj // Release() Method Table Number 3

$Cast = DllStructCreate("PTR",$lplpstg)
DllStructSetData($Cast,1,$nHresult[4])

return $nHresult[0]

EndFunc

Func RichEdit_CB_GetInPlaceContext($Object,$lplpFrame,$lplpDoc,$lpFrameInfo)
return $E_NOTIMPL
EndFunc

Func RichEdit_CB_ShowContainerUI($Object,$fShow)
return $E_NOTIMPL
EndFunc

Func RichEdit_CB_QueryInsertObject($Object,$lpclsid,$lpstg,$cp)
return $S_OK
EndFunc

Func RichEdit_CB_DeleteObject($Object,$lpoleobj)
return $E_NOTIMPL
EndFunc

Func RichEdit_CB_QueryAcceptData($Object,$lpdataobj,$lpcfFormat,$reco,$fReally,$hMetaPict)
return $S_OK
EndFunc

Func RichEdit_CB_ContextSensitiveHelp($Object,$fEnterMode)
return $E_NOTIMPL
EndFunc

Func RichEdit_CB_GetClipboardData($Object,$lpchrg,$reco,$lplpdataobj)
return $E_NOTIMPL
EndFunc

Func RichEdit_CB_GetDragDropEffect($Object,$fDrag,$grfKeyState,$pdwEffect)
return $E_NOTIMPL
EndFunc

Func RichEdit_CB_GetContextMenu($Object,$seltype,$lpoleobj,$lpchrg,$lphmenu)
return $E_NOTIMPL
EndFunc


Func IDataObject_QueryInterface($Object,$iid,$ppvObject)
return $E_NOTIMPL
EndFunc

Func IDataObject_AddRef($Object)
return $E_NOTIMPL
EndFunc

Func IDataObject_Release($Object)
return $E_NOTIMPL
EndFunc

Func IDataObject_GetData($Object,$pformatetcIn,$pmedium)
MoveMemory( GetValue( $Object , "pmedium" ) ,$pmedium,12)
return $S_OK
EndFunc

Func IDataObject_GetDataHere($Object,$pformatetc,$pmedium)
return $E_NOTIMPL
EndFunc

Func IDataObject_QueryGetData($Object,$pformatetc)
return $E_NOTIMPL
EndFunc

Func IDataObject_GetCanonicalFormatEtc($Object,$pformatectIn,$pformatetcOut)
return $E_NOTIMPL
EndFunc

Func IDataObject_SetData($Object,$pformatetc,$pmedium,$fRelease)
MoveMemory(GetValue($Object,"pformatetc"),$pformatetc,20)
MoveMemory( GetValue( $Object , "pmedium" ) ,$pmedium,12)
return $S_OK
EndFunc

Func IDataObject_EnumFormatEtc($Object,$dwDirection,$ppenumFormatEtc)
return $E_NOTIMPL
EndFunc

Func IDataObject_DAdvise($Object,$pformatetc,$advf,$pAdvSink,$pdwConnection)
return $E_NOTIMPL
EndFunc

Func IDataObject_DUnadvise($Object,$dwConnection)
return $E_NOTIMPL
EndFunc

Func IDataObject_EnumDAdvise($Object,$ppenumAdvise)
return $E_NOTIMPL
EndFunc

Func MoveMemory($Source,$Destination,$Length)
DllCall("Kernel32.dll","none","RtlMoveMemory","PTR",$Destination,"PTR",$Source,"INT",$Length)
EndFunc

RichEdit_Example.au3

#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>
#include <GDIPlus.au3>
#include "RichEdit_Class.au3"

    ;Minimum supported Windows XP

    Global $RichEdit_CB_Method[13] , $IDataObject_Method[12] , $IRichEditOleCallback = 0 , $IDataObject = 0
    $hGui = GUICreate("InsertObject Example",700,390)
    $hRichEdit = _GUICtrl_RichEdit_Create($hGui,"", 10, 10,680,300, _
    BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    $Button1 = GUICtrlCreateButton("InsertObject",10,320,200,50)
    GUICtrlSetFont(-1,18,600)
    GUISetState()

    InsertObject($hRichEdit,@ScriptDir & "\Image.TIF")

    While True
        $iMsg = GUIGetMsg()
        Select
            Case $iMsg = $GUI_EVENT_CLOSE
                _GUICtrlRichEdit_SetText ($hRichEdit,"")
                _GUICtrlRichEdit_Destroy($hRichEdit)
                DeleteClass($IRichEditOleCallback)
                DeleteClass($IDataObject)
                Exit
            Case $iMsg = $Button1
                $var = FileOpenDialog("", @ScriptDir & "\","All (*.*)", 1 + 4)
                if Not @error Then
                InsertObject($hRichEdit,$var)
                EndIf
        EndSelect
    WEnd


Func __GCR_SetOLE_Callback($hWnd)
    If Not IsHWnd($hWnd) Then Return SetError(101, 0, False)
    if ($IRichEditOleCallback = 0) Then $IRichEditOleCallback = IRichEditOleCallback_Create()
    Local Const $EM_SETOLECALLBACK = 0x400 + 70
    If _SendMessage($hWnd, $EM_SETOLECALLBACK, 0, $IRichEditOleCallback) = 0 Then Return SetError(700, 0, False)
    Return True
EndFunc   ;==>__GCR_SetOLECallback

;http://msdn.microsoft.com/en-us/library/windows/desktop/dd387916%28v=vs.85%29.aspx
;Use a Rich Edit Interface
;Rich edit controls expose some of their functionality through Component Object Model
;(COM) interfaces. By obtaining an interface from a control, you gain the ability to
;work with other objects within the control. You can obtain this interface by sending
;the EM_GETOLEINTERFACE message. From the IRichEditOle interface, you can then obtain
;interfaces used in the Text Object Model.
;Another interface, IRichEditOleCallback, is implemented by applications to define the
;behavior of the control when it interacts with objects.
;Insert an Object into a Rich Edit Control
;The following code example inserts a file object into a rich edit control. If a program
;is associated with the file type on the user's machine (for example, Microsoft Excel for
;an .xls file), the contents of the file display in the control; otherwise, an icon appears.

; BMP, GIF, JPEG, PNG, TIFF, Exif, WMF, and EMF // GDIPlus Library

Func InsertObject($hRichEdit,$pszFileName)
    Local $hr = 0, $Rt = 0 , $EM_GETOLEINTERFACE = 1084 , $pRichEditOle = 0

    $pRichEditOle = _SendMessage($hRichEdit,$EM_GETOLEINTERFACE,0,0,4,"wparam","ptr*")
    if ($pRichEditOle == 0) Then

        return FALSE;
    EndIf

    Local $pLockBytes = 0
    $hr = DllCall("Ole32.dll","long","CreateILockBytesOnHGlobal","ptr",0,"BOOL",True,"Ptr*",0)

    if (@error Or $hr[0] <> 0) Then

        return FALSE;
    EndIf
    $pLockBytes = $hr[3]

    Local $pStorage = 0
    $hr = DllCall("Ole32.dll","long","StgCreateDocfileOnILockBytes","ptr",$pLockBytes, _
           "DWORD",BitOR(0x00000010,0x00001000,0x00000002), _
           "DWORD",0,"Ptr*",0)


    if (@error Or $hr[0] <> 0) Then

        return FALSE;
    EndIf
    $pStorage = $hr[4]

    $tagFORMATETC = "int cfFormat;ptr ptd;DWORD dwAspect;LONG lindex;DWORD tymed"
    $formatEtc = DllStructCreate($tagFORMATETC)
    DllStructSetData($formatEtc,"cfFormat",0)
    DllStructSetData($formatEtc,"ptd",0)
    DllStructSetData($formatEtc,"dwAspect",1)
    DllStructSetData($formatEtc,"lindex",-1)
    DllStructSetData($formatEtc,"tymed",0)

    Local $pClientSite
    ;hr = pRichEditOle->GetClientSite(&pClientSite);
    ;GetClientSite  Virtual Method Number Of GetClientSite  Is 4 in (IRichEditOle interface)
    $hr = CallMethodA("long",4,2,"ptr",$pRichEditOle,"ptr*",0)

    if (@error Or $hr[0] <> 0) Then

        return FALSE;
    EndIf
    $pClientSite = $hr[2]

    Local $pUnk,$clsid = CLSIDFromString("{00000000-0000-0000-0000-000000000000}")
    Local $IID_IUnknown = IIDFromString("{00000000-0000-0000-C000-000000000046}")

    _GDIPlus_Startup()
    ; BMP, GIF, JPEG, PNG, TIFF, Exif, WMF, and EMF
    Local $hBMP = 0
    $hBitmap = _GDIPlus_BitmapCreateFromFile($pszFileName)
    if ($hBitmap) Then
    $hBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
     _GDIPlus_BitmapDispose($hBitmap)
     EndIf
    _GDIPlus_Shutdown ( )

    if ($hBMP) Then

    if $IDataObject = 0 Then $IDataObject = IDataObject_Create()

    $DVASPECT_CONTENT = 1
    $TYMED_GDI = 16
    $OLERENDER_FORMAT = 2
    DllStructSetData($formatEtc,"cfFormat",$CF_BITMAP)
    DllStructSetData($formatEtc,"ptd",0)
    DllStructSetData($formatEtc,"dwAspect",$DVASPECT_CONTENT)
    DllStructSetData($formatEtc,"lindex",-1)
    DllStructSetData($formatEtc,"tymed",$TYMED_GDI)

    $tagSTGMEDIUM = "DWORD tymed;ptr hBitmap;ptr pUnkForRelease"
    $STGMEDIUM = DllStructCreate($tagSTGMEDIUM)
    DllStructSetData($STGMEDIUM,"tymed",$TYMED_GDI)
    DllStructSetData($STGMEDIUM , "hBitmap" ,$hBMP)
    DllStructSetData($STGMEDIUM,"pUnkForRelease",0)

    SetValue($IDataObject,"pformatetc",DllStructGetPtr($formatEtc))
    SetValue($IDataObject ,"pmedium" , DllStructGetPtr($STGMEDIUM))

    $ID_IOleObject = IIDFromString("{00000112-0000-0000-C000-000000000046}")

    $hr = DllCall("Ole32.dll","long","OleCreateStaticFromData","ptr",$IDataObject,"ptr", _
    DllStructGetPtr($ID_IOleObject),"DWORD",$OLERENDER_FORMAT,"ptr",DllStructGetPtr($formatEtc) _
    ,"ptr",$pClientSite,"ptr",$pStorage,"Ptr*",0)

    if ($hr[0] <> 0) Then

        return FALSE;
    EndIf

    $pObject = $hr[7]

    DllCall("Ole32.dll","long","OleSetContainedObject","ptr",$pObject,"BOOL",True)
    $tagREOBJECT = "DWORD cbStruct;LONG cp;ulong Data1;ushort Data2;ushort Data3;byte Data4[8]" & _
    ";ptr poleobj;ptr pstg;ptr polesite;long x;long y;DWORD dvaspect;DWORD dwFlags;DWORD dwUser"
    $reobject = DllStructCreate($tagREOBJECT)
    DllStructSetData($reobject,"cbStruct",DllStructGetSize($reobject))
    ;hr = pObject->GetUserClassID(&clsid);
    ;GetUserClassID  Virtual Method Number Of GetUserClassID  Is 16 in (IOleObject interface)
    $hr = CallMethodA("long",16,2,"ptr",$pObject,"ptr",DllStructGetPtr($clsid))

    if ($hr[0] <> 0) Then

        ;pObject->Release();
        ;Release()  Virtual Method Number Of Release() Is 3 In (IOleObject interface)
        CallMethodA("long",3,1,"ptr",$pObject)
        return FALSE
    EndIf

    MoveMemory(DllStructGetPtr($clsid),DllStructGetPtr($reobject) + 8,16)
    ;8 ==> SizeOf "DWORD cbStruct;LONG cp;"
    ;16 ==> sizeOf $clsid
    DllStructSetData($reobject,"cp",-1)
    DllStructSetData($reobject,"dvaspect",1)
    DllStructSetData($reobject,"dwFlags",BitOR(0x00000001,0x00000002))
    DllStructSetData($reobject,"dwUser",0)
    DllStructSetData($reobject,"poleobj",$pObject)
    DllStructSetData($reobject,"polesite",$pClientSite)
    DllStructSetData($reobject,"pstg",$pStorage)
    $SIZEL = DllStructCreate("long;long");
    DllStructSetData($reobject,"SIZEL",DllStructGetPtr($SIZEL))


    _SendMessage($hRichEdit, 0xB1, 0, -1);EM_SETSEL
    $Rt = _SendMessage($hRichEdit, 0xB0,0,0,-1,"DWORD*","DWORD*");EM_GETSEL
    Local $dwStart = $Rt[3], $dwEnd = $Rt[4]
    _SendMessage($hRichEdit,0xB1, $dwEnd+1, $dwEnd+1);EM_SETSEL
    _SendMessage($hRichEdit, 0xC2, TRUE,@CRLF,0,"BOOL","wstr");EM_REPLACESEL

    ;hr = pRichEditOle->InsertObject(&reobject);
    ;InsertObject  Virtual Method Number Of InsertObject  Is 8 in (IRichEditOle interface)
    $hr = CallMethodA("long",8,2,"ptr",$pRichEditOle,"ptr",DllStructGetPtr($reobject))
    ;pObject->Release();
    ;Release()  Virtual Method Number Of Release() Is 3 In (IOleObject interface)
    CallMethodA("long",3,1,"ptr",$pObject)
    ;pRichEditOle->Release();
    ;Release()  Virtual Method Number Of Release() Is 3 In (IRichEditOle interface)
    CallMethodA("long",3,1,"ptr",$pRichEditOle)

    if ($hr[0] <> 0) Then

        return FALSE;

    EndIf

    _WinAPI_DeleteObject ( $hBMP )

    return TRUE;


    Else

    $hr = DllCall("Ole32.dll","long","OleCreateFromFile","ptr",DllStructGetPtr($clsid),"wstr", _
    $pszFileName,"ptr",DllStructGetPtr($IID_IUnknown),"DWORD",1,"ptr",DllStructGetPtr($formatEtc) _
    ,"ptr",$pClientSite,"ptr",$pStorage,"Ptr*",0)

    ;pClientSite->Release();
    ;IOleClientSite interface inherits from the IUnknown Or IOleClientSite : public IUnknown
    ;Release()  Virtual Method Number Of Release() Is 3 In (IOleClientSite interface)
    CallMethodA("long",3,1,"ptr",$pClientSite)

    if ($hr[0] <> 0) Then

        return FALSE;
    EndIf
    $pUnk = $hr[8]

    Local $pObject,$IID_IOleObject = IIDFromString("{00000112-0000-0000-C000-000000000046}")
    ;hr = pUnk->QueryInterface(IID_IOleObject, (void**)&pObject);
    ;New pUnk (IOleObject) interface inherits from the IUnknown Or IOleObject : public IUnknown
    ;QueryInterface()  Virtual Method Number Of QueryInterface() Is 1 In (IOleObject)
    $hr = CallMethodA("long",1,3,"ptr",$pUnk,"ptr",DllStructGetPtr($IID_IOleObject),"ptr*",0)
    ;Release()  Virtual Method Number Of Release() Is 3 In (IOleObject interface)
    ;pUnk->Release();
    CallMethodA("long",3,1,"ptr",$pUnk)

    if ($hr[0] <> 0) Then

        return FALSE;
    EndIf
    $pObject = $hr[3]

    DllCall("Ole32.dll","long","OleSetContainedObject","ptr",$pObject,"BOOL",True)
    $tagREOBJECT = "DWORD cbStruct;LONG cp;ulong Data1;ushort Data2;ushort Data3;byte Data4[8]" & _
    ";ptr poleobj;ptr pstg;ptr polesite;long x;long y;DWORD dvaspect;DWORD dwFlags;DWORD dwUser"
    $reobject = DllStructCreate($tagREOBJECT)
    DllStructSetData($reobject,"cbStruct",DllStructGetSize($reobject))
    ;hr = pObject->GetUserClassID(&clsid);
    ;GetUserClassID  Virtual Method Number Of GetUserClassID  Is 16 in (IOleObject interface)
    $hr = CallMethodA("long",16,2,"ptr",$pObject,"ptr",DllStructGetPtr($clsid))

    if (@error Or $hr[0] <> 0) Then

        ;pObject->Release();
        ;Release()  Virtual Method Number Of Release() Is 3 In (IOleObject interface)
        CallMethodA("long",3,1,"ptr",$pObject)
        return FALSE
    EndIf

    MoveMemory(DllStructGetPtr($clsid),DllStructGetPtr($reobject) + 8,16)
    ;8 ==> SizeOf "DWORD cbStruct;LONG cp;"
    ;16 ==> sizeOf $clsid
    DllStructSetData($reobject,"cp",-1)
    DllStructSetData($reobject,"dvaspect",1)
    DllStructSetData($reobject,"dwFlags",BitOR(0x00000001,0x00000002))
    DllStructSetData($reobject,"dwUser",0)
    DllStructSetData($reobject,"poleobj",$pObject)
    DllStructSetData($reobject,"polesite",$pClientSite)
    DllStructSetData($reobject,"pstg",$pStorage)
    $SIZEL = DllStructCreate("long;long");
    DllStructSetData($reobject,"SIZEL",DllStructGetPtr($SIZEL))


    _SendMessage($hRichEdit, 0xB1, 0, -1);EM_SETSEL
    $Rt = _SendMessage($hRichEdit, 0xB0,0,0,-1,"DWORD*","DWORD*");EM_GETSEL
    Local $dwStart = $Rt[3], $dwEnd = $Rt[4]
    _SendMessage($hRichEdit,0xB1, $dwEnd+1, $dwEnd+1);EM_SETSEL
    _SendMessage($hRichEdit, 0xC2, TRUE,@CRLF,0,"BOOL","wstr");EM_REPLACESEL

    ;hr = pRichEditOle->InsertObject(&reobject);
    ;InsertObject  Virtual Method Number Of InsertObject  Is 8 in (IRichEditOle interface)

    $hr = CallMethodA("long",8,2,"ptr",$pRichEditOle,"ptr",DllStructGetPtr($reobject))
    ;pObject->Release();
    ;Release()  Virtual Method Number Of Release() Is 3 In (IOleObject interface)
    CallMethodA("long",3,1,"ptr",$pObject)
    ;pRichEditOle->Release();
    ;Release()  Virtual Method Number Of Release() Is 3 In (IRichEditOle interface)
    CallMethodA("long",3,1,"ptr",$pRichEditOle)

    if ($hr[0] <> 0) Then

        return FALSE;
    EndIf

    return TRUE;

    EndIf

EndFunc

Func IDataObject_Create()

Local $cMethodArray = 0
$IDataObject_Method[0] = DllCallbackRegister("IDataObject_QueryInterface","LONG","PTR;PTR;PTR")
$cMethodArray = AddClassMethod($cMethodArray,"IDataObject_QueryInterface",DllCallbackGetPtr($IDataObject_Method[0]))
$IDataObject_Method[1] = DllCallbackRegister("IDataObject_AddRef","LONG","PTR")
$cMethodArray = AddClassMethod($cMethodArray,"IDataObject_AddRef",DllCallbackGetPtr($IDataObject_Method[1]))
$IDataObject_Method[2] = DllCallbackRegister("IDataObject_Release","LONG","PTR")
$cMethodArray = AddClassMethod($cMethodArray,"IDataObject_Release",DllCallbackGetPtr($IDataObject_Method[2]))
$IDataObject_Method[3] = DllCallbackRegister("IDataObject_GetData","LONG","PTR;PTR;PTR")
$cMethodArray = AddClassMethod($cMethodArray,"IDataObject_GetData",DllCallbackGetPtr($IDataObject_Method[3]))
$IDataObject_Method[4] = DllCallbackRegister("IDataObject_GetDataHere","LONG","PTR;PTR;PTR")
$cMethodArray = AddClassMethod($cMethodArray,"IDataObject_GetDataHere",DllCallbackGetPtr($IDataObject_Method[4]))
$IDataObject_Method[5] = DllCallbackRegister("IDataObject_QueryGetData","LONG","PTR;PTR")
$cMethodArray = AddClassMethod($cMethodArray,"IDataObject_QueryGetData",DllCallbackGetPtr($IDataObject_Method[5]))
$IDataObject_Method[6] = DllCallbackRegister("IDataObject_GetCanonicalFormatEtc","LONG","PTR;PTR;PTR")
$cMethodArray = AddClassMethod($cMethodArray,"IDataObject_GetCanonicalFormatEtc",DllCallbackGetPtr($IDataObject_Method[6]))
$IDataObject_Method[7] = DllCallbackRegister("IDataObject_SetData","LONG","PTR;PTR;PTR;BOOL")
$cMethodArray = AddClassMethod($cMethodArray,"IDataObject_SetData",DllCallbackGetPtr($IDataObject_Method[7]))
$IDataObject_Method[8] = DllCallbackRegister("IDataObject_EnumFormatEtc","LONG","PTR;DWORD;PTR")
$cMethodArray = AddClassMethod($cMethodArray,"IDataObject_EnumFormatEtc",DllCallbackGetPtr($IDataObject_Method[8]))
$IDataObject_Method[9] = DllCallbackRegister("IDataObject_DAdvise","LONG","PTR;PTR;DWORD;PTR;DWORD")
$cMethodArray = AddClassMethod($cMethodArray,"IDataObject_DAdvise",DllCallbackGetPtr($IDataObject_Method[9]))
$IDataObject_Method[10] = DllCallbackRegister("IDataObject_DUnadvise","LONG","PTR;DWORD")
$cMethodArray = AddClassMethod($cMethodArray,"IDataObject_DUnadvise",DllCallbackGetPtr($IDataObject_Method[10]))
$IDataObject_Method[11] = DllCallbackRegister("IDataObject_EnumDAdvise","LONG","PTR;PTR")
$cMethodArray = AddClassMethod($cMethodArray,"IDataObject_EnumDAdvise",DllCallbackGetPtr($IDataObject_Method[11]))

Local $cVariableArray = 0
$cVariableArray = AddClassVariable($cVariableArray,"PTR","pformatetc",0)
$cVariableArray = AddClassVariable($cVariableArray,"PTR","pmedium",0)

Return NewClass($cMethodArray,$cVariableArray)

EndFunc

Func IRichEditOleCallback_Create()

Local $cMethodArray = 0
$RichEdit_CB_Method[0] = DllCallbackRegister("RichEdit_CB_QueryInterface","LONG","PTR;PTR;PTR")
$cMethodArray = AddClassMethod($cMethodArray,"RichEdit_CB_QueryInterface",DllCallbackGetPtr($RichEdit_CB_Method[0]))
$RichEdit_CB_Method[1] = DllCallbackRegister("RichEdit_CB_AddRef","LONG","PTR")
$cMethodArray = AddClassMethod($cMethodArray,"RichEdit_CB_AddRef",DllCallbackGetPtr($RichEdit_CB_Method[1]))
$RichEdit_CB_Method[2] = DllCallbackRegister("RichEdit_CB_Release","LONG","PTR")
$cMethodArray = AddClassMethod($cMethodArray,"RichEdit_CB_Release",DllCallbackGetPtr($RichEdit_CB_Method[2]))
$RichEdit_CB_Method[3]= DllCallbackRegister("RichEdit_CB_GetNewStorage","LONG","PTR;PTR")
$cMethodArray = AddClassMethod($cMethodArray,"RichEdit_CB_GetNewStorage",DllCallbackGetPtr($RichEdit_CB_Method[3]))
$RichEdit_CB_Method[4] = DllCallbackRegister("RichEdit_CB_GetInPlaceContext","LONG","PTR;PTR;PTR;PTR")
$cMethodArray = AddClassMethod($cMethodArray,"RichEdit_CB_GetInPlaceContext",DllCallbackGetPtr($RichEdit_CB_Method[4]))
$RichEdit_CB_Method[5]= DllCallbackRegister("RichEdit_CB_ShowContainerUI","LONG","PTR;BOOL")
$cMethodArray = AddClassMethod($cMethodArray,"RichEdit_CB_ShowContainerUI",DllCallbackGetPtr($RichEdit_CB_Method[5]))
$RichEdit_CB_Method[6]= DllCallbackRegister("RichEdit_CB_QueryInsertObject","LONG","PTR;PTR;PTR;LONG")
$cMethodArray = AddClassMethod($cMethodArray,"RichEdit_CB_QueryInsertObject",DllCallbackGetPtr($RichEdit_CB_Method[6]))
$RichEdit_CB_Method[7] = DllCallbackRegister("RichEdit_CB_DeleteObject","LONG","PTR;PTR")
$cMethodArray = AddClassMethod($cMethodArray,"RichEdit_CB_DeleteObject",DllCallbackGetPtr($RichEdit_CB_Method[7]))
$RichEdit_CB_Method[8]= DllCallbackRegister("RichEdit_CB_QueryAcceptData","LONG","PTR;PTR;PTR;DWORD;BOOL;PTR")
$cMethodArray = AddClassMethod($cMethodArray,"RichEdit_CB_QueryAcceptData",DllCallbackGetPtr($RichEdit_CB_Method[8]))
$RichEdit_CB_Method[9] = DllCallbackRegister("RichEdit_CB_ContextSensitiveHelp","LONG","PTR;BOOL")
$cMethodArray = AddClassMethod($cMethodArray,"RichEdit_CB_ContextSensitiveHelp",DllCallbackGetPtr($RichEdit_CB_Method[9]))
$RichEdit_CB_Method[10] = DllCallbackRegister("RichEdit_CB_GetClipboardData","LONG","PTR;PTR;DWORD;PTR")
$cMethodArray = AddClassMethod($cMethodArray,"RichEdit_CB_GetClipboardData",DllCallbackGetPtr($RichEdit_CB_Method[10]))
$RichEdit_CB_Method[11] = DllCallbackRegister("RichEdit_CB_GetDragDropEffect","LONG","PTR;BOOL;DWORD;PTR")
$cMethodArray = AddClassMethod($cMethodArray,"RichEdit_CB_GetDragDropEffect",DllCallbackGetPtr($RichEdit_CB_Method[11]))
$RichEdit_CB_Method[12] = DllCallbackRegister("RichEdit_CB_GetContextMenu","LONG","PTR;WORD;PTR;PTR;PTR")
$cMethodArray = AddClassMethod($cMethodArray,"RichEdit_CB_GetContextMenu",DllCallbackGetPtr($RichEdit_CB_Method[12]))

Local $cVariableArray = 0
$cVariableArray = AddClassVariable($cVariableArray,"int","nCount",0)

Return NewClass($cMethodArray,$cVariableArray)

EndFunc


Func _GUICtrl_RichEdit_Create($hWnd, $sText, $iLeft, $iTop, $iWidth = 150, $iHeight = 150, $iStyle = -1, $iExStyle = -1)
    If Not IsHWnd($hWnd) Then Return SetError(1, 0, 0) ; Invalid Window handle for _GUICtrlRichEdit_Create 1st parameter
    If Not IsString($sText) Then Return SetError(2, 0, 0) ; 2nd parameter not a string for _GUICtrlRichEdit_Create

    If Not __GCR_IsNumeric($iWidth, ">0,-1") Then Return SetError(105, 0, 0)
    If Not __GCR_IsNumeric($iHeight, ">0,-1") Then Return SetError(106, 0, 0)
    If Not __GCR_IsNumeric($iStyle, ">=0,-1") Then Return SetError(107, 0, 0)
    If Not __GCR_IsNumeric($iExStyle, ">=0,-1") Then Return SetError(108, 0, 0)

    If $iWidth = -1 Then $iWidth = 150
    If $iHeight = -1 Then $iHeight = 150
    If $iStyle = -1 Then $iStyle = BitOR($ES_WANTRETURN, $ES_MULTILINE)

    If BitAND($iStyle, $ES_MULTILINE) <> 0 Then $iStyle = BitOR($iStyle, $ES_WANTRETURN)
    If $iExStyle = -1 Then $iExStyle = 0x200 ;  $DS_FOREGROUND

    $iStyle = BitOR($iStyle, $__UDFGUICONSTANT_WS_CHILD, $__UDFGUICONSTANT_WS_VISIBLE)
    If BitAND($iStyle, $ES_READONLY) = 0 Then $iStyle = BitOR($iStyle, $__UDFGUICONSTANT_WS_TABSTOP)

    Local $nCtrlID = __UDF_GetNextGlobalID($hWnd)
    If @error Then Return SetError(@error, @extended, 0)

    __GCR_Init()

    Local $hRichEdit = _WinAPI_CreateWindowEx($iExStyle, $__g_sRTFClassName, "", $iStyle, $iLeft, $iTop, $iWidth, _
            $iHeight, $hWnd, $nCtrlID)
    If $hRichEdit = 0 Then Return SetError(700, 0, False)

    __GCR_SetOLE_Callback($hRichEdit)
    _SendMessage($hRichEdit, $__RICHEDITCONSTANT_WM_SETFONT, _WinAPI_GetStockObject($DEFAULT_GUI_FONT), True)
    _GUICtrlRichEdit_AppendText($hRichEdit, $sText)
    Return $hRichEdit
EndFunc   ;==>_GUICtrlRichEdit_Create



Func CLSIDFromString($psz)
$GUID = DllStructCreate("ulong Data1;ushort Data2;ushort Data3;byte Data4[8]")
$Oleerror = DllCall("Ole32.dll","int","CLSIDFromString","WSTR",$psz,"struct*",$GUID)
if @error Or $Oleerror[0] <> 0 Then Return SetError(1,0,0)
Return SetError(0,0,$Oleerror[2])
EndFunc

Func IIDFromString($psz)
$GUID = DllStructCreate("ulong Data1;ushort Data2;ushort Data3;byte Data4[8]")
$Oleerror = DllCall("Ole32.dll","int","IIDFromString","WSTR",$psz,"struct*",$GUID)
if @error Or $Oleerror[0] <> 0 Then Return SetError(1,0,0)
Return SetError(0,0,$Oleerror[2])
EndFunc

 

 

 

 

 

 

 

 

 

Edited by wolf9228

صرح السماء كان هنا

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...