Jump to content

Problem using GUICTrlSetData() (Solved)


Recommended Posts

Hello to all :)

I want to add text in a read-only edit control. When I highlight using the mouse in Edit box I can change the position of outputted words, how can I fix this? I think that the problem is from GuiCtrlSetData()

#include <GuiEdit.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>


Global $hGUI,$Exit
Local $logs, $String
ReadOnlyGUI()

Func ReadOnlyGUI()
Opt("GUIOnEventMode", 1)
$hGUI=GuiCreate("Test", 625, 480, -1, -1, $WS_CAPTION + $WS_SYSMENU + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_MINIMIZEBOX + $WS_EX_TOOLWINDOW)
GUISetOnEvent($GUI_EVENT_CLOSE,"Exits")
GUISwitch($hGUI)
GUISetState(@SW_SHOW, $hGui)
Global $ReadOnly = GUICtrlCreateEdit(" ReadOnly" & @CRLF, 400, 50, 200, 400, + $ES_READONLY + $ES_MULTILINE + $WS_BORDER + $ES_AUTOVSCROLL )
GUICtrlSetStyle($ReadOnly, 0)
EndFunc

Func SetLogs($String)
   $logs = " " & $String
   GUICtrlSetData($ReadOnly, $logs & @CRLF,1)
EndFunc

Func Exits()
   Exit
EndFunc


while 1
   Sleep(1000)
   SetLogs("Testing")
WEnd

Best Regards

Edited by Zag8888
Link to comment
Share on other sites

Edit: Fixed by using _GUICtrlEdit_AppendText() instead of GuiCtrlSetData()

I still have the problem, but now works better.

 

2 Edit: I used _GUICtrlEdit_InsertText instead of GuiCtrlSetData() and I removed

GUICtrlSetStyle($ReadOnly, 0)

Now its work perfect.

Edited by Zag8888
Link to comment
Share on other sites

Here is more simple solution without _GUICtrlEdit_xxxx():

#include <GuiEdit.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>

Global $hGUI, $Exit
Local $logs, $String

ReadOnlyGUI()

Func ReadOnlyGUI()
    Opt("GUIOnEventMode", 1)
    $hGUI = GUICreate("Test", 625, 480, -1, -1, $WS_CAPTION + $WS_SYSMENU + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_MINIMIZEBOX + $WS_EX_TOOLWINDOW)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Exits")
    GUISetState(@SW_SHOW, $hGUI)
    Global $ReadOnly = GUICtrlCreateEdit(" ReadOnly" & @CRLF, 400, 50, 200, 400, +$ES_READONLY + $ES_MULTILINE + $WS_BORDER + $ES_AUTOVSCROLL)
    GUICtrlSetStyle($ReadOnly, 0)
EndFunc   ;==>ReadOnlyGUI

Func SetLogs($String)
    $logs = GUICtrlRead($ReadOnly)
    $logs &= @CRLF & " " & $String
    GUICtrlSetData($ReadOnly, $logs)
EndFunc   ;==>SetLogs

Func Exits()
    Exit
EndFunc   ;==>Exits


While 1
    Sleep(1000)
    SetLogs("Testing")
WEnd

 

Link to comment
Share on other sites

19 hours ago, Zedna said:

Here is more simple solution without _GUICtrlEdit_xxxx():

#include <GuiEdit.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>

Global $hGUI, $Exit
Local $logs, $String

ReadOnlyGUI()

Func ReadOnlyGUI()
    Opt("GUIOnEventMode", 1)
    $hGUI = GUICreate("Test", 625, 480, -1, -1, $WS_CAPTION + $WS_SYSMENU + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_MINIMIZEBOX + $WS_EX_TOOLWINDOW)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Exits")
    GUISetState(@SW_SHOW, $hGUI)
    Global $ReadOnly = GUICtrlCreateEdit(" ReadOnly" & @CRLF, 400, 50, 200, 400, +$ES_READONLY + $ES_MULTILINE + $WS_BORDER + $ES_AUTOVSCROLL)
    GUICtrlSetStyle($ReadOnly, 0)
EndFunc   ;==>ReadOnlyGUI

Func SetLogs($String)
    $logs = GUICtrlRead($ReadOnly)
    $logs &= @CRLF & " " & $String
    GUICtrlSetData($ReadOnly, $logs)
EndFunc   ;==>SetLogs

Func Exits()
    Exit
EndFunc   ;==>Exits


While 1
    Sleep(1000)
    SetLogs("Testing")
WEnd

 

I've tried to use  _GUICtrlRichEdit_Create_  instead of GUICtrlCreateEdit, I found _GUICtrlRichEdit_Create_ better, I've used _GUICtrlRichEdit_AppendText to add text, but with the mouse, I can move all the outputted words.

Edited by Zag8888
Link to comment
Share on other sites

On 6/9/2019 at 10:12 PM, Zag8888 said:

I've tried to use  _GUICtrlRichEdit_Create_  instead of GUICtrlCreateEdit, I found _GUICtrlRichEdit_Create_ better, I've used _GUICtrlRichEdit_AppendText to add text, but with the mouse, I can move all the outputted words.

 

Post small reproducing script to increase your chance for getting help ...

 

EDIT: As far as I think you want to completely disable richedit control and use it only as LOG output?

Edited by Zedna
Link to comment
Share on other sites

On 6/12/2019 at 11:10 AM, Zedna said:

 

Post small reproducing script to increase your chance for getting help ...

 

EDIT: As far as I think you want to completely disable richedit control and use it only as LOG output?

right! I'm trying to make a log output

Link to comment
Share on other sites

On 6/12/2019 at 11:10 AM, Zedna said:

 

Post small reproducing script to increase your chance for getting help ...

 

EDIT: As far as I think you want to completely disable richedit control and use it only as LOG output?

I followed your last example.  Now it works perfect, thanks for your help.

Func SetLogs($String)
   $logs = _GUICtrlRichEdit_GetText($ReadOnly)
   $logs &= @CRLF & "[" & _NowTime() & "] " & $String
   _GUICtrlRichEdit_SetText($ReadOnly, $logs)
EndFunc

 

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