Jayson Posted March 26, 2010 Share Posted March 26, 2010 (edited) Hello guys, I'm grabbing a html source and display it in an edit. I'm trying to change the color automatically of all tag inside but i don't know how to do it #include <GuiRichEdit.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Color.au3> #include <IE.au3> $GUI = GUICreate("Page Source", 1016, 795, -1, -1) $IE = _IE_Example ("basic") $html = _IEDocReadHTML ($IE) $edit = _GUICtrlRichEdit_Create($GUI, $html, 10, 10, 1000, 650) GUISetState(@SW_SHOW) $test = _GUICtrlRichEdit_FindText($edit, "<HTML>") _GuiCtrlRichEdit_SetSel($edit, 0, 6) _GuiCtrlRichEdit_SetCharColor($edit, "304050") While 1 WEnd Anyone would like to help me ? Edited March 26, 2010 by Jayson Link to comment Share on other sites More sharing options...
PsaltyDS Posted March 27, 2010 Share Posted March 27, 2010 (edited) You're trying too hard. Just set the style attribute on the DOM element ('a' tag or link) directly: #include <IE.au3> $sURL = "http://www.autoitscript.com" $oIE = _IECreate($sURL) $colLinks = _IELinkGetCollection($oIE) For $oLink In $colLinks $oLink.Style.backgroundColor = 0xFFFF00 ; Yellow background $oLink.Style.Color = 0xFF0000 ; Red text Next Edited March 27, 2010 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Jayson Posted March 27, 2010 Author Share Posted March 27, 2010 Thx for your help but i still getting an error #include <IE.au3> $GUI = GUICreate("Page Source", 1016, 795, -1, -1) $oIE = _IE_Example ("basic") $html = _IEDocReadHTML ($oIE) $edit = GUICtrlCreateEdit($html, 10, 10, 1000, 650) GUISetState(@SW_SHOW) $oElements = _IETagNameAllGetCollection ($html) ;<==== For $oElement In $oElements $oElement.Style.Color = 0xFF0000 ;MsgBox(0, "Element Info", "Tagname: " & $oElement.tagname ) Next While 1 Wend<==== ; If I write what I tried it return the error For $oElement In $oElements^ ERROR. But if Iwrite $oIE it only color on the webpage but not on the grabbed source in the edit.Sorry if that's not clear, my english isn't very good. Link to comment Share on other sites More sharing options...
PsaltyDS Posted March 28, 2010 Share Posted March 28, 2010 Your $html is just a string, not the required IExplorer object. You have to get the collection of links from the $oIE object (or a frame/form/etc. that you drilled down into from there). But it doesn't look like you were interested in the browser anyway. Looking closer at the OP, you are trying to change the color of certain strings in the RichTextEdit control, not in the web browser. This would change the "HEAD" and "/HEAD" tag text in the control: expandcollapse popup#include <GuiRichEdit.au3> #include <GUIConstantsEx.au3> #include <IE.au3> ; Get HTML string $oIE = _IE_Example("basic") $sHtml = _IEDocReadHTML($oIE) _IEQuit($oIE) ; Create GUI and RTEdit control $hGUI = GUICreate("Page Source", 800, 600) $hEdit = _GUICtrlRichEdit_Create($hGUI, $sHtml, 10, 10, 780, 580) GUISetState() _GUICtrlRichEdit_GotoCharPos($hEdit, 0) ; Place cursor before begining of text $iFind = _GUICtrlRichEdit_FindText($hEdit, "<HEAD>") ConsoleWrite("$iFind = " & $iFind & @LF) If $iFind <> -1 Then _GUICtrlRichEdit_SetSel($hEdit, $iFind, $iFind + 6) _GUICtrlRichEdit_SetCharColor($hEdit, 304050) EndIf $iFind = _GUICtrlRichEdit_FindText($hEdit, "</HEAD>") ConsoleWrite("$iFind = " & $iFind & @LF) If $iFind <> -1 Then _GUICtrlRichEdit_SetSel($hEdit, $iFind, $iFind + 7) _GUICtrlRichEdit_SetCharColor($hEdit, 304050) EndIf _GUICtrlRichEdit_SetSel($hEdit, 0, 0) ; Clear selection While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($hEdit) Exit EndSwitch WEnd Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Jayson Posted March 28, 2010 Author Share Posted March 28, 2010 Wow ! That's exactly what i am looking for !! I guess i was not far away on my first try Thank you so much PsaltyDS ! God bless you Link to comment Share on other sites More sharing options...
Jayson Posted March 30, 2010 Author Share Posted March 30, 2010 Sorry to bother again but i'm trying to replace & in my RichEdit but i can't get it to workThis is my code updated :If WinExists("Source de" & $currenturl) <> 1 Then $sHtml = _IEDocReadHTML($oIE) $GUI2 = GUICreate("Source de " & $currenturl, 800, 600) $hEdit = _GUICtrlRichEdit_Create($GUI2 ,$sHtml, 10, 10, 780, 580, BitOR($ES_MULTILINE, $WS_VSCROLL, $WS_HSCROLL ,$ES_AUTOVSCROLL)) _GUICtrlRichEdit_GotoCharPos($hEdit, 0) ; Place cursor before begining of text StringReplace($shtml, "&", "&") $test = _StringBetween($shtml, "<html", "<") $test1 = _ArrayToString($test) ConsoleWrite("StrB:" & $test1) $iFind = _GUICtrlRichEdit_FindText($hEdit, "<html" & $test1) EndIf If $iFind <> -1 Then _GUICtrlRichEdit_SetSel($hEdit, $iFind, $iFind + StringLen($test1)) ;StringLen($test1) _GUICtrlRichEdit_SetCharColor($hEdit, 304050) _GUICtrlRichEdit_SetSel($hEdit, 0, 0) ;_GUICtrlRichEdit_GotoCharPos($hEdit, 0) EndIfIn the RichEdit i'm grabbing this text : <html onmousemove="google&&google.fade&&google.fade(event)"> Link to comment Share on other sites More sharing options...
PsaltyDS Posted March 30, 2010 Share Posted March 30, 2010 You didn't do anything with the return value from StringReplace(). Where did you want it to go? Maybe: $shtml = StringReplace($shtml, "&", "&") Also, you are operating on the $shtml string, not on the contents of the RichEdit control. If you wanted to do that with the control: $sText = _GUICtrlRichEdit_GetText($hEdit) $sText = StringReplace($sText, "&", "&") _GuiCtrlRichEdit_SetText($hEdit, $sText) Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Jayson Posted March 31, 2010 Author Share Posted March 31, 2010 It works like a charm !! But i just noticed the color don't go at the end of the tag. I can fix it by adding + 5 but i don't like that way _GUICtrlRichEdit_SetSel($hEdit, $iFind, $iFind + StringLen($test1) + 5) Any idea how i can solve this ? Link to comment Share on other sites More sharing options...
PsaltyDS Posted April 7, 2010 Share Posted April 7, 2010 Your $test1 string does not include "<HTML" because of the way you used StringBetween() to get it. Therefore, StringLen($test1) isn't giving you the full size. It's off by 5 because that's how long "<HTML" is. You could put it back with: $test1 = "<html" & _ArrayToString($test) Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Jayson Posted April 13, 2010 Author Share Posted April 13, 2010 Thanks Didn't tought it was that easy.. lol Thx again ! 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