#include-once #include #region ##### EXAMPLE ##### ;~ #include ;~ #region - GUI Create ;~ GUICreate('HTML Edit Test', 640, 480) ;~ $Tmp = _GuiCtrlTexte_Create(5, 5, 630, 470) ;~ GUISetState() ;~ #endregion ;~ _GuiCtrlTexte_Write($Tmp, "

Test de l'UDF: GuiCtrlTexte.au3

") ;~ _GuiCtrlTexte_Add($Tmp, '

Voici le premier paragraphe de test pour cet UDF!
Il à été créer à la base par timmalos du forum ' & _ ;~ 'de la communauté francophone AutoIt.') ;~ _GuiCtrlTexte_Add($Tmp, '

Il fut en suite amélioré par bubule, il lui a en effet ajouter plusieurs fonction fort utiles

') ;~ _GuiCtrlTexte_Add($Tmp, '

Et c''est la que j''entre en jeu! Trouvant que l''UDF méritait beaucoups plus d''attention, et une meilleur gestion des erreurs, ' & _ ;~ 'Je me mis à ajouter les définitions des fonction, à améliorer la lisibilité du code et la gestion des erreurs, et enfin ' & _ ;~ 'à tapoter ce petit exemple tout simple pour montrer un peut comment ça marche!') ;~ #region - GUI SelectLoop ;~ While 1 ;~ $msg = GUIGetMsg() ;~ Select ;~ Case $msg = $GUI_EVENT_CLOSE ;~ Exit ;~ EndSelect ;~ WEnd #endregion #endregion ;=============================================================================== ; ; Function Name: _GuiCtrlTexte_Create($x, $y, $width = -1, $height = -1, $bgcolor = "white", $sFontColor = "black", $sFont = "", $iFontSize = 0) ; Description:: Create a HTML based Edit Control ; Parameter(s): $x = Position In the GUI ; $y = Position In the GUI ; $width = Width of the control ; $height = Height of the control ; $bgcolor = OPTIONAL: Background color of the edit (in HTML style) (Default = White) ; $sFontColor = OPTIONAL: Text default color (Default = Black) ; $sFont = OPTIONAL: Font name. If blank or Default, then default font is used ; $iFontSize = OPTIONAL: Font size. If 0 or Default, then default size is used ; Requirement(s): ; Return Value(s): Succes => Handle to the control (An array containing the _IECreateEmbedded and GUICtrlCreateObj) ; Failed => 0, @Extended = The function that have failed, @Error = the error returned by that function ; Author(s): timmalos -> Bubule -> Matwachich ; ;=============================================================================== ; Func _GuiCtrlTexte_Create($x, $y, $width = -1, $height = -1, $bgcolor = "white", $sFontColor = "black", $sFont = "", $iFontSize = 0) If Int($x) <> $x Or Int($y) <> $y Or $x = "" Or $y = "" Or $x = 0 Or $y = 0 Then Return 0 Local $hCtrlObj, $hCtrl, $baseHtml, $style Dim $hReturn[2] $hCtrlObj = _IECreateEmbedded() If @error Then Return SetError(@error, "_IECreateEmbedded", 0) $hCtrl = GUICtrlCreateObj($hCtrlObj, $x, $y, $width, $height) _IENavigate($hCtrlObj, "about:blank") If @error Then Return SetError(@error, "_IENavigate", 0) If $sFont = "" And $iFontSize = 0 Then $style = "" If $sFont <> "" And $iFontSize = 0 Then $style = 'style="font-family:' & $sFont If $sFont = "" And $iFontSize <> 0 Then $style = 'style="font-size:' & $iFontSize & 'px' If $sFont <> "" And $iFontSize <> 0 Then $style = 'style="font-family:' & $sFont & ';font-size:' & $iFontSize & 'px' $style &= ';color:' & $sFontColor & '"' $baseHtml = "" _IEDocWriteHTML($hCtrlObj, $baseHtml) If @error Then Return SetError(@error, "_IEDocWriteHTML", 0) $hReturn[0] = $hCtrlObj $hReturn[1] = $hCtrl Return $hReturn EndFunc ;=============================================================================== ; ; Function Name: _GuiCtrlTexte_Config($hCtrl, $bgcolor = "white", $sFontColor = "black", $sFont = "", $iFontSize = 0) ; Description:: Configure the background color, the font name and size ; Parameter(s): $hCtrl = Handle returned by _GuiCtrlTexte_Create() ; $bgcolor = OPTIONAL: Background color of the edit (in HTML style) (Default = White) ; $sFontColor = OPTIONAL: Text default color (Default = Black) ; $sFont = OPTIONAL: Font name. If blank or Default, then default font is used ; $iFontSize = OPTIONAL: Font size. If 0 or Default, then default size is used ; Requirement(s): ; Return Value(s): Succes => Handle to the control (An array containing the _IECreateEmbedded and GUICtrlCreateObj) ; Failed => 0, @Extended = The function that have failed, @Error = the error returned by that function ; Author(s): timmalos -> Bubule -> Matwachich ; ;=============================================================================== ; Func _GuiCtrlTexte_Config($hCtrl, $bgcolor = "white", $sFontColor = "black", $sFont = "", $iFontSize = 0) If $bgcolor = "" Then $bgcolor = "white" Local $stxt = _GuiCtrlTexte_Read($hCtrl, 1), $baseHtml, $style If @error Then Return SetError(@error, "_IEBodyReadHTML", 0) If $sFont = "" And $iFontSize = 0 Then $style = "" If $sFont <> "" And $iFontSize = 0 Then $style = 'style="font-family:' & $sFont If $sFont = "" And $iFontSize <> 0 Then $style = 'style="font-size:' & $iFontSize & 'px' If $sFont <> "" And $iFontSize <> 0 Then $style = 'style="font-family:' & $sFont & ';font-size:' & $iFontSize & 'px' $style &= ';color:' & $sFontColor & '"' $baseHtml = "" _IEDocWriteHTML($hCtrl[0], $baseHtml) If @error Then Return SetError(@error, "_IEDocWriteHTML", 0) If $stxt Then _IEBodyWriteHTML($hCtrl[0], $stxt) If @error Then Return SetError(@error, "_IEBodyWriteHTML", 0) EndIf Return 1 EndFunc ;=============================================================================== ; ; Function Name: _GuiCtrlTexte_Write($hCtrl, $s_html) ; Description:: Write HTML code in the edit ; Parameter(s): $hCtrl = Handle returned by _GuiCtrlTexte_Create() ; $s_html = HTML code to write in the edit ; Requirement(s): ; Return Value(s): Succes => Handle to the control (An array containing the _IECreateEmbedded and GUICtrlCreateObj) ; Failed => 0, @Extended = The function that have failed, @Error = the error returned by that function ; Author(s): timmalos -> Bubule -> Matwachich ; ;=============================================================================== ; Func _GuiCtrlTexte_Write($hCtrl, $s_html) _IEBodyWriteHTML($hCtrl[0], $s_html) If @error Then Return SetError(@error, "_IEBodyWriteHTML", 0) Return 1 EndFunc ;=============================================================================== ; ; Function Name: _GuiCtrlTexte_Add($hCtrl, $s_html) ; Description:: Adds HTML code to the edit ; Parameter(s): $hCtrl = Handle returned by _GuiCtrlTexte_Create() ; $s_html = HTML code to add in the edit ; Requirement(s): ; Return Value(s): Succes => Handle to the control (An array containing the _IECreateEmbedded and GUICtrlCreateObj) ; Failed => 0, @Extended = The function that have failed, @Error = the error returned by that function ; Author(s): timmalos -> Bubule -> Matwachich ; ;=============================================================================== ; Func _GuiCtrlTexte_Add($hCtrl, $s_html) Local $Texte = _GuiCtrlTexte_Read($hCtrl, 1) If @error Then Return SetError(@error, "_GuiCtrlTexte_Read -> " & @extended, 0) _IEBodyWriteHTML($hCtrl[0], $Texte & $s_html) If @error Then Return SetError(@error, "_IEBodyWriteHTML", 0) Return 1 EndFunc ;=============================================================================== ; ; Function Name: _GuiCtrlTexte_Read($hCtrl, $rpt = 0) ; Description:: Read either the HTML code, or the text only in the edit ; Parameter(s): $hCtrl = Handle returned by _GuiCtrlTexte_Create() ; $flag = False (Default) => Returns text ; True => Returns entire HTML code ; Requirement(s): ; Return Value(s): Succes => Handle to the control (An array containing the _IECreateEmbedded and GUICtrlCreateObj) ; Failed => 0, @Extended = The function that have failed, @Error = the error returned by that function ; Author(s): timmalos -> Bubule -> Matwachich ; ;=============================================================================== ; Func _GuiCtrlTexte_Read($hCtrl, $bHTML = False) Local $return Switch $bHTML Case False $return = _IEBodyReadText($hCtrl[0]) If @error Then Return SetError(@error, "_IEBodyReadText", 0) Case True $return = _IEBodyReadHTML($hCtrl[0]) If @error Then Return SetError(@error, "_IEBodyReadHTML", 0) EndSwitch If $return = "0" Then $return = "" Return $return EndFunc ;=============================================================================== ; ; Function Name: _GuiCtrlTexte_Clear($hCtrl) ; Description:: Clear the edit ; Parameter(s): $hCtrl = Handle returned by _GuiCtrlTexte_Create() ; Requirement(s): ; Return Value(s): Succes => Handle to the control (An array containing the _IECreateEmbedded and GUICtrlCreateObj) ; Failed => 0, @Extended = The function that have failed, @Error = the error returned by that function ; Author(s): timmalos -> Bubule -> Matwachich ; ;=============================================================================== ; Func _GuiCtrlTexte_Clear($hCtrl) _IEBodyWriteHTML($hCtrl[0], "") If @error Then Return SetError(@error, "_IEBodyWriteHTML", 0) Return 1 EndFunc ;=============================================================================== ; ; Function Name: _GuiCtrlTexte_Delete() ; Description:: Destroy the edit ; Parameter(s): $hCtrl = Handle returned by _GuiCtrlTexte_Create() ; Requirement(s): ; Return Value(s): Succes => Handle to the control (An array containing the _IECreateEmbedded and GUICtrlCreateObj) ; Failed => 0, @Extended = The function that have failed, @Error = the error returned by that function ; Author(s): timmalos -> Bubule -> Matwachich ; ;=============================================================================== ; Func _GuiCtrlTexte_Delete($hCtrl) Return GUICtrlDelete($hCtrl[1]) EndFunc