Sign in to follow this  
Followers 0
Kreatorul

ControlSetText

9 posts in this topic

So I am writing a script to help me write guitar tabs easier. But when I use ControlSetText when there is no text in the editbox the title of the window disapears and the text it's not sent. Maybe a bug?

Here is the script

#include <GUIConstants.au3>
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$oRP = ObjCreate("RICHTEXT.RichtextCtrl.1")

$gui=GUICreate("Tab Editor", 350, 250, -1, -1,BitOr($WS_OVERLAPPEDWINDOW,$WS_VISIBLE,$WS_CLIPSIBLINGS))
;Menus
$MenuItem1 = GUICtrlCreateMenu("File")
$new = GUICtrlCreateMenuItem("New", $MenuItem1)
$save = GUICtrlCreateMenuItem("Save", $MenuItem1)
$exit = GUICtrlCreateMenuItem("Exit", $MenuItem1)
$MenuItem5 = GUICtrlCreateMenu("Help")
$help = GUICtrlCreateMenuItem("Help", $MenuItem5)
$about = GUICtrlCreateMenuItem("About", $MenuItem5)
;Buttons
$PrefsC = GUICtrlCreateButton('FontSize',175,177,70,20)
$StatC = GUICtrlCreateButton('Plain Style',245,177,70,20)
$tab = GuiCtrlCreateButton("Tab", 270, 200)
;Objects
$GUIActiveX = GUICtrlCreateObj( $oRP, 10, 10 , 400 , 260 )
GUICtrlSetPos($GUIActiveX,10,10,300,160)

With $oRP; Object tag pool
.OLEDrag()
.Font = 'Arial'
.text = ""
.multiline

EndWith

GUISetState ();Show GUI

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    
    If $msg = $save Then
            $saved=FileSaveDialog("Save Tab", @desktopDir, "Rich Text Files(*.rtf)")
            $oRP.SaveFile($saved & ".rtf", 0)
        EndIf
        
    If $msg = $tab Then
            $gettxt=ControlGetText("Tab Editor", "Tab", $oRP.text)
            If $gettxt="" Then 
                ControlSetText("Tab Editor", "Tab", $oRP.text, "Text Here" & @crlf & "Text Here")
            Else
            ControlSetText("Tab Editor", "Tab", $oRP.text, $gettxt & @crlf & @crlf & "Text Here" & @crlf & "Text Here")
            EndIf
        EndIf
        
        If $msg = $save Then
            $saved=FileSaveDialog("Save Tab", @desktopDir, "Rich Text Files(*.rtf)")
            $oRP.SaveFile($saved & ".rtf", 0)
            EndIf
                    
        If $msg = $PrefsC Then $oRP.SelFontSize = 12
            
        If $msg = $StatC Then
            $oRP.SelBold = False
            $oRP.SelItalic = False
            $oRP.SelUnderline = False 
            $oRP.SelFontSize = 8
   EndIf
WEnd

Exit

Func MyErrFunc()

  $HexNumber=hex($oMyError.number,8)

  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"       & @CRLF  & @CRLF & _
             "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
             "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "         & @TAB & $HexNumber              & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
            ,5)
            
  ; Will automatically continue after 5 seconds
  SetError(1)  ; to check for after this function returns
Endfunc

:):P

Share this post


Link to post
Share on other sites



I don't think it's a bug, but I guess Controlsettext isn't intended for objects.

To add text to your rtfedit you should do something like

$oRP.loadfile("c:\somewhere\words.txt") or use some other method of the object.


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.

Share this post


Link to post
Share on other sites

$oRP.text = "Hello - Au3 supports ActiveX components like the RICHTEXT thanks to SvenP" & @CRLF & 'Try write some text and quit to reload'


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

I know that but if i use .text="Text Here" it replaces the text that was before...I need to send some text and then if i click the button again add another text that's why i use controlsend

Share this post


Link to post
Share on other sites

#include <GUIConstants.au3>
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$oRP = ObjCreate("RICHTEXT.RichtextCtrl.1")

GUICreate("Embedded RICHTEXT control Test", 320, 250, -1, -1,BitOr($WS_OVERLAPPEDWINDOW,$WS_VISIBLE,$WS_CLIPSIBLINGS))
$TagsPageC = GuiCtrlCreateLabel('Visit Tags Page', 5, 180, 100, 15, $SS_CENTER)
GuiCtrlSetFont($TagsPageC,9,400,4)
GuiCtrlSetColor($TagsPageC,0x0000ff)
GuiCtrlSetCursor($TagsPageC,0)
$AboutC = GUICtrlCreateButton('About',105,177,70,20)
$PrefsC = GUICtrlCreateButton('FontSize',175,177,70,20)
$StatC = GUICtrlCreateButton('Plain Style',245,177,70,20)
$AddText = GUICtrlCreateButton('Add Text', 105, 205, 70, 20)
$GUIActiveX = GUICtrlCreateObj( $oRP, 10, 10 , 400 , 260 )
GUICtrlSetPos($GUIActiveX,10,10,300,160)

With $oRP; Object tag pool
.OLEDrag()
.Font = 'Arial'
.text = "Hello - Au3 supports ActiveX components like the RICHTEXT thanks to SvenP" & @CRLF & 'Try write some text and quit to reload'
;.FileName = @ScriptDir & '\RichText.rtf'
;.BackColor = 0xff00
EndWith

GUISetState ();Show GUI

While 1
    $msg = GUIGetMsg()
    
    Select
        Case $msg = $GUI_EVENT_CLOSE
;~          $oRP.SaveFile( @ScriptDir & "\RichText.rtf", 0 )
            ExitLoop
        Case $msg = $TagsPageC
            Run(@ComSpec & ' /c start http://www.myplugins.info/guids/typeinfo/typeinfo.php?clsid={3B7C8860-D78F-101B-B9B5-04021C009402}','', @SW_HIDE)
        Case $msg = $AboutC
            $oRP.AboutBox() 
        Case $msg = $PrefsC
            $oRP.SelFontSize = 12
        Case $msg = $StatC
            $oRP.SelBold = False
            $oRP.SelItalic = False
            $oRP.SelUnderline = False 
            $oRP.SelFontSize = 8
        Case $msg = $AddText
            $oRP.text = $oRP.text & @CRLF & "gafrost added some text"
    EndSelect
WEnd

Exit

Func MyErrFunc()

  $HexNumber=hex($oMyError.number,8)

  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"       & @CRLF  & @CRLF & _
             "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
             "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "         & @TAB & $HexNumber              & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
            ,5)
            
  ; Will automatically continue after 5 seconds
  SetError(1)  ; to check for after this function returns
Endfunc


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

That was the first thing I tried and it didn't worked :) But now it's working :P....I must have done something wrong :D

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

That was the first thing I tried and it didn't worked :D But now it's working :D ....I must have done something wrong ;)

I, however, am getting

WARNING: $WS_OVERLAPPEDWINDOW: possibly used before declaration.

GUICreate("Embedded RICHTEXT control Test", 320, 250, -1, -1,BitOr($WS_OVERLAPPEDWINDOW,

(and it goes downhill from there...)

Edited by everseeker

Everseeker

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Search the helpfile for those constants. You will need to include the files that have them.

WindowsConstants.au3 is one of them... :D

Cheers,

Brett

Ah, so the code, as written above, does NOT work... OK

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#include <EditConstants.au3>

#include <StaticConstants.au3>

There, all better. But now, I get a Com Error... searching produced this: (see attachment)

; Needs: MSCOMCT2.OCX in system32 but it's probably already there

; Date: 3 jul 2005

Well, that's there...

So, here is the exact file I am attempting to run...

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>


$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")
$oRP = ObjCreate("RICHTEXT.RichtextCtrl.1")

GUICreate("Embedded RICHTEXT control Test", 320, 250, -1, -1,BitOr($WS_OVERLAPPEDWINDOW,$WS_VISIBLE,$WS_CLIPSIBLINGS))
$TagsPageC = GuiCtrlCreateLabel('Visit Tags Page', 5, 180, 100, 15, $SS_CENTER)
GuiCtrlSetFont($TagsPageC,9,400,4)
GuiCtrlSetColor($TagsPageC,0x0000ff)
GuiCtrlSetCursor($TagsPageC,0)
$AboutC = GUICtrlCreateButton('About',105,177,70,20)
$PrefsC = GUICtrlCreateButton('FontSize',175,177,70,20)
$StatC = GUICtrlCreateButton('Plain Style',245,177,70,20)
$AddText = GUICtrlCreateButton('Add Text', 105, 205, 70, 20)
$GUIActiveX = GUICtrlCreateObj( $oRP, 10, 10 , 400 , 260 )
GUICtrlSetPos($GUIActiveX,10,10,300,160)

With $oRP.OLEDrag() ; Object tag pool
.OLEDrag()
.Font = 'Arial'
.text = "Hello - Au3 supports ActiveX components like the RICHTEXT thanks to SvenP" & @CRLF & 'Try write some text and quit to reload'
;.FileName = @ScriptDir & '\RichText.rtf'
;.BackColor = 0xff00
EndWith

GUISetState ();Show GUI

While 1
    $msg = GUIGetMsg()

    Select
        Case $msg = $GUI_EVENT_CLOSE
;~    $oRP.SaveFile( @ScriptDir & "\RichText.rtf", 0 )
            ExitLoop
        Case $msg = $TagsPageC
            Run(@ComSpec & ' /c start [url="http://www.myplugins.info/guids/typeinfo/t...-04021C009402}"]http://www.myplugins.info/guids/typeinfo/t...-04021C009402}',''[/url], @SW_HIDE)
        Case $msg = $AboutC
            $oRP.AboutBox()
        Case $msg = $PrefsC
            $oRP.SelFontSize = 12
        Case $msg = $StatC
            $oRP.SelBold = False
            $oRP.SelItalic = False
            $oRP.SelUnderline = False
            $oRP.SelFontSize = 8
        Case $msg = $AddText
            $oRP.text = $oRP.text & @CRLF & "gafrost added some text"
    EndSelect
WEnd

Exit

Func MyErrFunc()

  $HexNumber=hex($oMyError.number,8)

  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"       & @CRLF  & @CRLF & _
             "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
             "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "         & @TAB & $HexNumber              & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
            ,5)

  ; Will automatically continue after 5 seconds
  SetError(1)  ; to check for after this function returns
Endfunc

And this is what I see when I do... (Please see attachment)

post-772-1245163444_thumb.jpg


Everseeker

Share this post


Link to post
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
Sign in to follow this  
Followers 0