Jump to content

formatted edit box or ?


Brickoneer
 Share

Recommended Posts

Hey guys,

Is there a way to format each line in an edit control? For example if I want the first line to be red, the next to be green, the next bold, etc. I tried GUICtrlSetFont, but that changes the entire edit box.

I'm trying to make a console-ish thing for my script where the script outputs status messages. I would like Error messages to be red, success messages to be green, that sort of thing.

Thanks for your help!

Brick

[edit] changed title to represent problem better.

Edited by Brickoneer
Link to comment
Share on other sites

Hey guys,

Is there a way to format each line in an edit control? For example if I want the first line to be red, the next to be green, the next bold, etc. I tried GUICtrlSetFont, but that changes the entire edit box.

I'm trying to make a console-ish thing for my script where the script outputs status messages. I would like Error messages to be red, success messages to be green, that sort of thing.

Thanks for your help!

Brick

You will need a richedit to do that.

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.
Link to comment
Share on other sites

Are the edit control phrases static? If so, you simply need to change the color depending on the message being displayed.

Try this example:

#include <GuiConstants.au3>

GuiCreate("MyGUI", 224, 151,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Edit_1 = GuiCtrlCreateEdit("", 40, 20, 130, 20, $ES_READONLY)
$button = GUICtrlCreateButton("Change text", 70, 100, 80, 30)
$x=1
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $button 
        if $x = 4 then $x=1
        if $x = 3 then
            GUICtrlSetData($Edit_1, "Problem")
            GUICtrlSetFont($Edit_1, 10, 900)
            GUICtrlSetColor($Edit_1, 0x00ffff)
            $x = $x +1
        endif
        if $x = 2 then
            GUICtrlSetData($Edit_1, "ERROR")
            GUICtrlSetFont($Edit_1, 10, 900)
            GUICtrlSetColor($Edit_1, 0xFF0000)
            $x = $x +1
        endif
        if $x = 1 then
            GUICtrlSetData($Edit_1, "Success!")
            GUICtrlSetFont($Edit_1, 10, 400)
            GUICtrlSetColor($Edit_1, 0x00ff00)
            $x = $x +1
        endif
        
    Case Else
        ;;;
    EndSelect
WEnd
Exit
Link to comment
Share on other sites

Thanks for the replies.

Martin...

I couldn't figure out how to get richedit to change font/color of certain portions of text... maybe I'm just stupid. :)

Volly...

That would work great, except the color/font applies to the entire content of the edit control. So if I had an edit box that displayed:

Welcome....

Starting to do whatever....

YAY! It worked.

Starting project number 2.....

ERROR! it failed.

The Final error message would turn all of the text red. Obviously thats a problem. <_<

Maybe an edit control is not what I need... really it sounds like I want a 'console' - ish thing like scite has.

Any ideas?

Thanks for your help!

Brick

Edited by Brickoneer
Link to comment
Share on other sites

Thanks for the replies.

Martin...

I couldn't figure out how to get richedit to change font/color of certain portions of text... maybe I'm just stupid. <_<

I don't think you're stupid.

have a look at this example.

$oRP.selcolor = 0x0000ff gives red text, 0xff0000 for blue

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.
Link to comment
Share on other sites

When trying to run the example I get this error:

New AutoIt v3 Script.au3 (23) : ==> Only Object-type variables allowed in an "With" statement.: 
With $oRP 
With ^ ERROR

I figured out that the richedit was not being created. (it returned a 0)

Is there a missing include?

Thanks,

brick

P.S. Volly... that was sorta my idea... almost exactly like the console in scite.

Edited by Brickoneer
Link to comment
Share on other sites

When trying to run the example I get this error:

New AutoIt v3 Script.au3 (23) : ==> Only Object-type variables allowed in an "With" statement.: 
With $oRP 
With ^ ERROR

I figured out that the richedit was not being created. (it returned a 0)

Is there a missing include?

Thanks,

brick

P.S. Volly... that was sorta my idea... almost exactly like the console in scite.

This is correct error handling:

...
$oRP = ObjCreate("RICHTEXT.RichtextCtrl")
if not IsObj($oRP) then
      Msgbox(0,"Error","Error when creating RICHTEXT.RichtextCtrl object.")
      Exit
endif
...

BTW: I don't know exactly why "RICHTEXT.RichtextCtrl" is not created. There was some scripts on the forum for enumerating available objects in system but I cant remember its name

Link to comment
Share on other sites

Thanks for your reply.

I did some searching and couldn't seem to find the script you mentioned... :) So I'm stuck again.

Basically guys, this is what I want to have embedded in a GUI: (as a status box, or log of the progress of the program)

CODE
Starting program...

Starting task one...

Task Successful!

Starting task two...

ERROR: Task Failed!

Starting task three...

etc, etc, etc.

First, I started using an edit box, but soon found out that the edit box cannot have individual line formatting.

I'm not even sure if its an edit box that I should be using, quite frankly. <_<

Is there another 'individually formatable' multi-line display that can be put in a gui???

Thanks for your help!!

Much appreciated!

Brick

Link to comment
Share on other sites

Thanks for your reply.

I did some searching and couldn't seem to find the script you mentioned... :) So I'm stuck again.

Basically guys, this is what I want to have embedded in a GUI: (as a status box, or log of the progress of the program)

CODE
Starting program...

Starting task one...

Task Successful!

Starting task two...

ERROR: Task Failed!

Starting task three...

etc, etc, etc.

First, I started using an edit box, but soon found out that the edit box cannot have individual line formatting.

I'm not even sure if its an edit box that I should be using, quite frankly. <_<

Is there another 'individually formatable' multi-line display that can be put in a gui???

Thanks for your help!!

Much appreciated!

Brick

Look here

It's not finished yet.

Link to comment
Share on other sites

Yes, I have seen that, but cannot seem to make it work. The example given with the release works fine, but doesn't do any formatting. The example on formatting doesn't work. I can't seem to figure it out by myself... any chance you could post a working example including formatting?

Thanks,

Brick

Link to comment
Share on other sites

Another approach... with Demo

#include <GuiConstants.au3>
#Include <GuiEdit.au3>
#include <date.au3>

opt("GUIOnEventMode", 1)

Demo()

;------------------------------------------------------------------------------------------------------
;-                                      C O N S O L E   D E M O
;------------------------------------------------------------------------------------------------------
Func Demo()
    Global $ConsoleID=0
    $ConsoleID = ConsoleWinCreate( -1, -1, 638, 326, "Age Demo...", "Starting demo..." & @CRLF, True)
    $answer1 = ConsoleWinInput($ConsoleID, "Please input your Year of Birth (example.. 1985) ?", 15, 1 )
    $Vanswer1 =ConsoleWinVerify($ConsoleID, $answer1, "Please input your Year of Birth (example.. 1985) ?", True, 4, 4)
    ConsoleWinWrite($ConsoleID, "OK.. " & @CRLF, 30, 1)
    $answer2 = ConsoleWinInput($ConsoleID, "Please input your Month of Birth (example.. 3 = March) ?", 45, 1 )
    $Vanswer2 =ConsoleWinVerify($ConsoleID, $answer2, "Please input your Month of Birth (example.. 3 = March) ?", True, 1, 2)
    ConsoleWinWrite($ConsoleID, "Good.. " & @CRLF, 60, 1)
    $answer3 = ConsoleWinInput($ConsoleID, "Please input your Day of Birth (ex.. 22) ?" , 75, 1 )
    $Vanswer3 =ConsoleWinVerify($ConsoleID, $answer3, "Please input your Month of Birth (example.. 22) ?", True, 1, 2)
    ConsoleWinWrite($ConsoleID, "Great!.. Please wait while i calculate your age..." & @CRLF, 90, 1)
    Sleep(1000)
    ConsoleWinWrite($ConsoleID, " You have been alive " & _DateDiff( 'd',$Vanswer1 &"/"& $Vanswer2 &"/"& $Vanswer3,_NowCalc()) & " days!" & @CRLF, 100, 1)
    Sleep(5000)
    ConsoleWinWrite($ConsoleID, "Example: Clearing console in five seconds...Thanks Valuater 8) ")
    Sleep(5000)
    ConsoleWinClear($ConsoleID)
    ConsoleWinColor( $ConsoleID, 0xFF0000, "")
    For $x = 1 to 5
    ConsoleWinWrite($ConsoleID, "ERROR.... " & @CRLF)
    Sleep(700)
    Next
    Sleep(5000)
    ConsoleWinClear($ConsoleID)
    ConsoleWinColor($ConsoleID)
    ConsoleWinWrite($ConsoleID, "Demo finished! Exiting in five seconds...")
    Sleep(5000)
    Exit
EndFunc

;------------------------------------------------------------------------------------------------------
;-                                      C O N S O L E   L I B R A R Y 
;------------------------------------------------------------------------------------------------------

;===============================================================================
; Description:      Create a Window console to display status text information with history
; Parameter(s):     $x                - x position of the window
;                    $y                - y position of the window
;                    $width            - Optional - Window width
;                    $height            - Optional - Window height
;                    $Title            - Optional - Console Window title
;                    $text            - Optional - Initial text to display.
;                    $CreateProgress    - Optional - Create Progress (True/False)
;                    $BgColor        - Optional - background color
;                    $FgColor        - Optional - Foreground color
;                    $Transparency    - Optional - Transparency (0=Invisible, 255=Visible)
; Requirement(s):   None
; Return Value(s):  The Console ID
; Author(s):        Jerome DERN  (jdern "at" free "dot" fr)
; Note(s):            None
;===============================================================================
Func ConsoleWinCreate($x, $y, $width=638, $height=126, $Title="Console", $Text="", $CreateProgress=False, $BgColor=0xFFFFFF, $FgColor=0xFF0000, $Transparency=255)
    Dim $Console[3]
    $Console[0] = GuiCreate($Title, $width, $height, $x, $y, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS), $WS_EX_TOOLWINDOW)
    GUISetOnEvent($GUI_EVENT_CLOSE, "ConsoleWinExitEvent")
    If $CreateProgress Then $height -= 20
    $Console[1] = GuiCtrlCreateEdit($Text & @CRLF, 0, 0, $width-1, $height-1, BitOR($ES_MULTILINE, $ES_READONLY, $ES_AUTOVSCROLL,$WS_HSCROLL,$WS_VSCROLL))
    GUICtrlSetBkColor($Console[1],    $BgColor)
    GUICtrlSetColor($Console[1],    $FgColor)
    GUICtrlSetResizing($Console[1],    $GUI_DOCKBORDERS)
    GUICtrlSetFont($Console[1], 12, 400, 0, "Courrier New")
    $Console[2] =0
    If $CreateProgress Then $Console[2] = GUICtrlCreateProgress(0, $height+5, $width-1, 12)
    WinSetTrans($Console[0], "", $Transparency)
    GuiSetState()
    Return $Console
EndFunc

Func ConsoleWinExitEvent()
    GUIDelete(@GUI_WinHandle)
    Exit
EndFunc

;===============================================================================
; Description:      Create a Widget console to display status text information with history
; Parameter(s):     $gui            - Gui window to include widget
;                    $x                - x position of the Widget
;                    $y                - y position of the Widget
;                    $width            - Optional - Widget width
;                    $height            - Optional - Widget height
;                    $Title            - Optional - Console Window title
;                    $text            - Optional - Initial text to display.
;                    $CreateProgress    - Optional - Create Progress (True/False)
;                    $BgColor        - Optional - background color
;                    $FgColor        - Optional - Foreground color
;                    $LogFile        - Optional - File to log all console text
; Requirement(s):   None
; Return Value(s):  The Console ID
; Author(s):        Jerome DERN  (jerome "at" dern "dot" fr)
; Note(s):            None
;===============================================================================
Func ConsoleCreate($gui, $x, $y, $width=638, $height=126, $Text="", $CreateProgress=False, $BgColor=0xFFFFFF, $FgColor=0xFF0000, $LogFile="")
    Dim $Console[4]
    If $Text <> "" Then $Text=$Text & @CRLF
    $Console[0] = $gui
    If $CreateProgress Then $height -= 20
    $Console[1] = GuiCtrlCreateEdit($Text, $x, $y, $width-1, $height-1, BitOR($ES_MULTILINE, $ES_READONLY, $ES_AUTOVSCROLL,$WS_HSCROLL,$WS_VSCROLL))
    GUICtrlSetBkColor($Console[1],    $BgColor)
    GUICtrlSetColor($Console[1],    $FgColor)
    GUICtrlSetResizing($Console[1],    $GUI_DOCKBORDERS)
    GUICtrlSetFont($Console[1], 8, 400, 0, "Courrier New")
    $Console[2] =0
    If $CreateProgress Then $Console[2] = GUICtrlCreateProgress($x, $y+$height+5, $width-1, 12)
    $Console[3] = $LogFile
    Return $Console
EndFunc

;===============================================================================
; Description:      Write a message to the console
; Parameter(s):     $ConsoleID        - Console ID returned by ConsoleWinCreate
;                    $text            - Text to display.
;                    $Progress        - Optional - Progress value (0-100)
;                    $NoCRLF            - Optional - Don't add CRLF and the end of text
;                    $Replace        - Optional - Replace last line
; Requirement(s):   ConsoleWinCreate called first
; Return Value(s):  None
; Author(s):        Jerome DERN  (jdern "at" free "dot" fr)
; Note(s):            None
;===============================================================================
Func ConsoleWinWrite($ConsoleID, $Text, $Progress=-1, $Speak=False, $NoCRLF=False, $Replace=False)
    If $Replace Then
        $string = GUICtrlRead($ConsoleID[1])
        $pos = StringInStr($string, @CRLF, 0, -1)
        If $pos > 0 Then $pos += 1
        $end = StringLen($string)
        _GUICtrlEditSetSel($ConsoleID[1], $pos, $end)
    Else
        $pos = StringLen(GUICtrlRead($ConsoleID[1]))
        _GUICtrlEditSetSel($ConsoleID[1], $pos, $pos)
    EndIf
    If $NoCRLF = False Then $Text = $Text & @CRLF
    GUICtrlSetData ($ConsoleID[1], $Text, 1)
    If $Speak Then ConsoleSpeak($Text)
    If $ConsoleID[2] >0 And $Progress>=0 Then GUICtrlSetData($ConsoleID[2], $Progress)
EndFunc

;===============================================================================
; Description:      Ask for the user to input something
; Parameter(s):     $ConsoleID        - Console ID returned by ConsoleWinCreate
;                    $text            - Text to display, the question.
;                    $Progress        - Optional - Progress value (0-100)
; Requirement(s):   ConsoleWinCreate called first
; Return Value(s):  What user have typed.
; Author(s):        Jerome DERN  (jdern "at" free "dot" fr)
; Note(s):            $text could be an empty string
;===============================================================================
Func ConsoleWinInput($ConsoleID, $Text, $Progress=-1, $Speak = 0)
    WinSetOnTop($ConsoleID[0], "", 1)
    WinActivate($ConsoleID[0])
    $string = GUICtrlRead($ConsoleID[1])
    $pos = StringLen($string)
    _GUICtrlEditSetSel($ConsoleID[1], $pos, $pos)
    GUICtrlSetData ($ConsoleID[1], $Text, 1)
    GUICtrlSetStyle($ConsoleID[1], BitOR($ES_MULTILINE, $ES_AUTOVSCROLL, $WS_HSCROLL, $WS_VSCROLL, $ES_WANTRETURN))
    If $Speak Then ConsoleSpeak($Text)
    If $Text <> "" Then
       ; Wait for the user to input something
        While 1
            Sleep(100)
            $String=GUICtrlRead($ConsoleID[1])
            If StringRight($string, 2) = @CRLF Then ExitLoop
           ; Ensure that everything is typed at the end of edit control
            $pos = StringLen($String)
            _GUICtrlEditSetSel($ConsoleID[1], $pos, $pos)
        WEnd
        $pos = StringInStr($string, $Text, 0, -1)
        If $pos >0 Then $pos += StringLen($Text)
    Else
        $str = $string
       ; Wait for the user to input something
        While 1
            Sleep(100)
            $String=GUICtrlRead($ConsoleID[1])
            If StringRight($string, 2) = @CRLF And $string <> $str Then ExitLoop
           ; Ensure that everything is typed at the end of edit control
            $pos = StringLen($String)
            _GUICtrlEditSetSel($ConsoleID[1], $pos, $pos)
        WEnd
        $pos = StringInStr(StringLeft($string, StringLen($string)-2), @CRLF, 0, -1)
        If $pos > 0 Then $pos += 1
    EndIf
    $string = StringMid($string, $pos)
    $string = StringLeft($string, StringLen($string)-2)
    GUICtrlSetStyle($ConsoleID[1], BitOR($ES_MULTILINE, $ES_READONLY, $ES_AUTOVSCROLL,$WS_HSCROLL,$WS_VSCROLL))
    If $ConsoleID[2] >0 And $Progress>=0 Then GUICtrlSetData($ConsoleID[2], $Progress)
    Return $string
    WinSetOnTop($ConsoleID[0], "", 0)
EndFunc

;===============================================================================
; Description:      Clear the console
; Parameter(s):     $ConsoleID    - The console ID
; Requirement(s):   None
; Return Value(s):  None
; Author(s):        Jerome DERN  (jdern "at" free "dot" fr)
; Note(s):            None
;===============================================================================
Func ConsoleWinClear($ConsoleID)
    GUICtrlSetData ($ConsoleID[1], "")
    If $ConsoleID[2] >0 Then GUICtrlSetData($ConsoleID[2], 0)
EndFunc

;===============================================================================
; Description:      Save the content of the console to a file
; Parameter(s):     $ConsoleID    - The console ID
;                    $FileName    - The filename used to save
; Requirement(s):   None
; Return Value(s):  Write status, same as FileWrite
; Author(s):        Jerome DERN  (jdern "at" free "dot" fr)
; Note(s):            None
;===============================================================================
Func ConsoleWinSave($ConsoleID, $FileName)
    $string = GUICtrlRead($ConsoleID[1])
    Return FileWrite($FileName, $string)
EndFunc

;===============================================================================
; Description:      Ask for the user to verify input something
; Parameter(s):     $ConsoleID      - Console ID returned by ConsoleWinCreate
;                   $VAns            - info to verify
;                    $Text           - Text to display, the question.
;                   $VNum            - Optional - to verify an Intreger
;                     $VMin           - Optional - Minimum length of string
;                    $VMax            - Otional - Maximum length of string
; Requirement(s):   ConsoleWinCreate available and ConsoleWinInput called first
; Return Value(s):  What user has typed.
; Author(s):        Jerome DERN  (jdern "at" free "dot" fr)
; Co - Author        Valuater.... 8)
; Note(s):          $Text may not be an empty string
;===============================================================================
Func ConsoleWinVerify($ConsoleID, $VAns, $Text, $VNum = False, $VMin = 1, $VMax = 1000)
    While 1
        ConsoleWinWrite($ConsoleID, "You have answered: " & $VAns)
        $VLen = StringLen($VAns)
        If $VNum And Int($VAns) > 0 And $VLen >= $VMin And $VLen <= $VMax Then
            If ConsoleWinInput($ConsoleID, 'Is this Correct? "Y" or "N" ') = "y" Then Return $VAns
        ElseIf Not $VNum And $VLen >= $VMin And $VLen <= $VMax Then
            If ConsoleWinInput($ConsoleID, 'Is this Correct? "Y" or "N" ') = "y" Then Return $VAns
        EndIf
        $VAns = ConsoleWinInput($ConsoleID, $Text)
        Sleep(10)
    WEnd
EndFunc

; Valuater....

Func ConsoleWinColor( $ConsoleID, $BgColor=0xFFFFFF, $FgColor=0xFF0000)
    GUICtrlSetBkColor($ConsoleID[1],    $BgColor)
    GUICtrlSetColor($ConsoleID[1],    $FgColor)
EndFunc

Func ConsoleSpeak($S_text)
    Local $oi_speech = ObjCreate("SAPI.SpVoice")
    If IsObj($oi_speech) Then $oi_speech.Speak ($S_text)
    $oi_speech = ""
EndFunc

8)

NEWHeader1.png

Link to comment
Share on other sites

Thanks Valuater! It works great and gave me some great ideas. But it still is limited to one color at a time, isn't it?

Your example gave me an idea that may be a solution to my problem... but it might be a bit ugly. I *could* do something like this:

#include <GUIConstants.au3>
#include <IE.au3>
Global $msg
Opt("guioneventmode", 1)
_IEErrorHandlerRegister()

$oIE = _IECreateEmbedded()
GUICreate("Test", 440, 480, (@DesktopWidth - 440) / 2, (@DesktopHeight - 480) / 2)
$GUIActiveX = GUICtrlCreateObj($oIE, 10, 10, 200, 340)
GUISetOnEvent($GUI_EVENT_CLOSE, "exitme")
GUISetState()
_IENavigate($oIE, "about:blank")

$msg = "This is an example..."
appendtext($msg)
Sleep(300)

$msg = "Starting tasks..."
appendtext($msg)

$msg = ""
appendtext($msg)

For $i = 1 To 20
    Sleep(1000)
    $msg = $i & ": Success!"
    appendtext($msg, "green")

    $i += 1 ;;  
    Sleep(1000)
    $msg = $i & ": ERROR ERROR ERROR!!!"
    appendtext($msg, "red")
Next

Func appendtext($msg, $color = "black")
    $src = _IEDocReadHTML($oIE)
    $src = $src & '<font color="' & $color & '">' & $msg & '</font><br>' ;can modify to include size, weight, etc.
    $go = _IEDocWriteHTML($oIE, $src)
EndFunc   ;==>appendtext

Func exitme()
    Exit
EndFunc   ;==>exitme

There is probably a drawback to using an IE browser that I haven't seen, but this lets me have control over the HTML which gives me control over formatting.

What do you guys think?

Brick

P.S. Thanks for all your replies! (and patience!)

Edited by Brickoneer
Link to comment
Share on other sites

If output is all you want, you could also use Win API to draw text...

(Uses Auto3Lib)

#include <GUIConstantsEx.au3>
#include <A3LWinAPI.au3>
    
$sTitle = ""

$hGui = GUICreate($sTitle, 400, 300, -1, -1, -1, -1)
$lblOut = GUICtrlCreateLabel("", 50,30,300,200,-1,$WS_EX_STATICEDGE)
$btnStart = GUICtrlCreateButton("Start", 150,250,100,30)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnStart
            ;
            GUICtrlSetState($btnStart, $GUI_DISABLE)
            Cls($lblOut)
            Sleep(1000)
            WriteLn($lblOut, 1, "Starting program...", -1)
            Sleep(1000)
            WriteLn($lblOut, 2, "Starting task one...", -1)
            Sleep(1000)
            WriteLn($lblOut, 3, "Task Successful!", 0x00CC00)
            Sleep(1000)
            WriteLn($lblOut, 4, "Starting task two...", -1)
            Sleep(1000)
            WriteLn($lblOut, 5, "ERROR: Task Failed!", 0x0000FF)
            Sleep(1000)
            WriteLn($lblOut, 6, "Ending...", -1)
            Sleep(1000)
            GUICtrlSetState($btnStart, $GUI_ENABLE)
        Case $GUI_EVENT_PRIMARYDOWN, $GUI_EVENT_SECONDARYDOWN, $GUI_EVENT_MOUSEMOVE
            ;
    EndSwitch
WEnd

Func Cls($cID)
    Local $hWnd, $hDC, $tRect
    $hWnd = GUICtrlGetHandle($cID)
    $tRect = _API_GetClientRect($hWnd)
    _API_InvalidateRect($hWnd, $tRect)
    _API_UpdateWindow($hWnd)
EndFunc
Func WriteLn($cID, $nLine, $sTxt, $nColor)
    Local $hWnd, $hDC, $tRect, $nFontSize = 20
    $hWnd = GUICtrlGetHandle($cID)
    $hDC = _API_GetDC($hWnd)
    $tRect = _API_GetClientRect($hWnd)
    $tLine = $tRect
    DllStructSetData($tLine, 1, 10)
    DllStructSetData($tLine, 2, $nFontSize*($nLine-1))
    DllStructSetData($tLine, 4, $nFontSize*$nLine)
    DLLCall("gdi32.dll","int","SetBkMode", "hwnd", $hDC, "int", 1)
    _API_SetTextColor($hDC, $nColor)
    _API_DrawText($hDC, $sTxt, $tLine, $DT_LEFT)
    _API_ReleaseDC($hWnd, $hDC)
EndFunc

Also note that if the window gets covered with something else, all the text will be cleared. If you need to preserve the text, there's a solution, but it ain't very short - create MemoryDC (_API_CreateCompatibleDC + _API_CreateCompatibleBitmap) and keep it as global var, upon writing text BitBlt the output DC to the MemDC, then in case window is activated and repaints itself, BitBlt from MemDC to output DC to restore your text. Maybe there's simpler solution to that, not sure.

Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

If output is all you want, you could also use Win API to draw text...

(Uses Auto3Lib)

#include <GUIConstantsEx.au3>
#include <A3LWinAPI.au3>
    
$sTitle = ""

$hGui = GUICreate($sTitle, 400, 300, -1, -1, -1, -1)
$lblOut = GUICtrlCreateLabel("", 50,30,300,200,-1,$WS_EX_STATICEDGE)
$btnStart = GUICtrlCreateButton("Start", 150,250,100,30)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnStart
            ;
            GUICtrlSetState($btnStart, $GUI_DISABLE)
            Cls($lblOut)
            Sleep(1000)
            WriteLn($lblOut, 1, "Starting program...", -1)
            Sleep(1000)
            WriteLn($lblOut, 2, "Starting task one...", -1)
            Sleep(1000)
            WriteLn($lblOut, 3, "Task Successful!", 0x00CC00)
            Sleep(1000)
            WriteLn($lblOut, 4, "Starting task two...", -1)
            Sleep(1000)
            WriteLn($lblOut, 5, "ERROR: Task Failed!", 0x0000FF)
            Sleep(1000)
            WriteLn($lblOut, 6, "Ending...", -1)
            Sleep(1000)
            GUICtrlSetState($btnStart, $GUI_ENABLE)
        Case $GUI_EVENT_PRIMARYDOWN, $GUI_EVENT_SECONDARYDOWN, $GUI_EVENT_MOUSEMOVE
            ;
    EndSwitch
WEnd

Func Cls($cID)
    Local $hWnd, $hDC, $tRect
    $hWnd = GUICtrlGetHandle($cID)
    $tRect = _API_GetClientRect($hWnd)
    _API_InvalidateRect($hWnd, $tRect)
    _API_UpdateWindow($hWnd)
EndFunc
Func WriteLn($cID, $nLine, $sTxt, $nColor)
    Local $hWnd, $hDC, $tRect, $nFontSize = 20
    $hWnd = GUICtrlGetHandle($cID)
    $hDC = _API_GetDC($hWnd)
    $tRect = _API_GetClientRect($hWnd)
    $tLine = $tRect
    DllStructSetData($tLine, 1, 10)
    DllStructSetData($tLine, 2, $nFontSize*($nLine-1))
    DllStructSetData($tLine, 4, $nFontSize*$nLine)
    DLLCall("gdi32.dll","int","SetBkMode", "hwnd", $hDC, "int", 1)
    _API_SetTextColor($hDC, $nColor)
    _API_DrawText($hDC, $sTxt, $tLine, $DT_LEFT)
    _API_ReleaseDC($hWnd, $hDC)
EndFunc

Also note that if the window gets covered with something else, all the text will be cleared. If you need to preserve the text, there's a solution, but it ain't very pretty - create MemoryDC (_API_CreateCompatibleDC + _API_CreateCompatibleBitmap) and keep it as global var, upon writing text BitBlt the output DC to the MemDC, then in case window is activated and repaints itself, BitBlt from MemDC to output DC to restore your text. Maybe there's simpler solution to that, not sure.

Look at the beta, you don't need the A3L libs for API, look for _WinAPI_xxxxx etc.

SciTE for AutoItDirections for Submitting Standard UDFs

 

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

 

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...