Jump to content

Little question about GuictrlcreateEdit...


Recommended Posts

Hello everybody, i have little question, i don't know how to fix this, i have one GuiCtrlCreateEdit and i want to add words only in last line of that Edit...

I can to do it with GUICtrlSetData($ctrlID, $data, 1), (Edit is readonly) and when select text and use ..SetData command, i lose that selected lines, but i want only to add last line... here is example:

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


#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 392, 321, -1, -1)
$ctrlID = GUICtrlCreateEdit( "This is line 1..." &@CRLF& "This is line 2... Select ALL and press SEND" &@CRLF& "This is line 3...", 24, 24, 337, 249, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN,$WS_VSCROLL))
;~ $input = GUICtrlCreateInput("", 24, 280, 273, 21)
$Button1 = GUICtrlCreateButton("SEND", 304, 280, 59, 20,$BS_DEFPUSHBUTTON)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $data = @CRLF& "...something..."
            GUICtrlSetData($ctrlID, $data, 1)
    EndSwitch
WEnd
Edited by n3nE

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Link to comment
Share on other sites

LOL, do you mean on this:

$data = GUICtrlRead($ctrlID) & @CRLF & "...something..."

GUICtrlSetData($ctrlID, $data)

That way is to slow for my script (and i need to be scrolled down), because i have very big text, and i can't read and set all text every time...

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Link to comment
Share on other sites

LOL, do you mean on this:

$data = GUICtrlRead($ctrlID) & @CRLF & "...something..."

GUICtrlSetData($ctrlID, $data)

That way is to slow for my script (and i need to be scrolled down), because i have very big text, and i can't read and set all text every time...

What about _GUICtrlEdit_AppendText in GuiEdit.au3?
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

Is there a some other way?

GUIedit don't support some Unicode characters... check out this example:

#include <GuiEdit.au3>
;~ #include <ButtonConstants.au3>
;~ #include <EditConstants.au3>
#include <GUIConstantsEx.au3>
;~ #include <WindowsConstants.au3>

;~ Opt('MustDeclareVars', 1)
$Debug_Ed = False ; Check ClassName being passed to Edit functions, set to True and use a handle to another control to see it work
Local $hEdit, $Button1

    GUICreate("Edit Append Text", 400, 300)
    $Button1 = GUICtrlCreateButton("Button1", 52, 272, 75, 25, 0)
    $asd = _Ansi2Uni("Ä Ä‡ Å¡ ž Ä")
    $Input1 = GUICtrlCreateInput($asd, 130, 274, 217, 21)
    $hEdit = GUICtrlCreateEdit("", 2, 2, 394, 268)
    GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $wordtosend = _Uni2Ansi(GUICtrlRead($Input1))
            $UniWord = _Ansi2Uni($wordtosend)
;~    MsgBox(0,$UniWord,$wordtosend)
            GUICtrlSetData($hEdit, "GUICtrlSetData | Ansi 2 Uni: "& $UniWord)
            _GUICtrlEdit_AppendText($hEdit, @CRLF & "..._AppendText | Ansi 2 Uni: "& $UniWord)
            _GUICtrlEdit_InsertText($hEdit, @CRLF & "    ..._InsertText | Ansi 2 Uni: "& $UniWord)
    EndSwitch
WEnd
    
Func _Uni2Ansi($Unicode)
    $Binary = StringToBinary($Unicode, 4)
    $Hex = StringReplace($Binary, '0x', '', 1)
    $BinaryLength = StringLen($Hex)
    Local $ANSI
    For $i = 1 To $BinaryLength Step 2
        $Char = StringMid($Hex, $i, 2)
        $ANSI &= BinaryToString('0x' & $Char)
    Next
    Return $ANSI
EndFunc   ;==>_Uni2Ansi

Func _Ansi2Uni($ANSI)
$Binary = StringToBinary($ANSI)
$Unicode = BinaryToString($Binary, 4)
Return $Unicode
EndFunc   ;==>_Ansi2Uni
Edited by n3nE

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Link to comment
Share on other sites

Please look my example and say me, how to fix problem?! :S

If _GUICtrlEdit_AppendText don't support Unicode characters, how to Add text on End of CtrlEdit, without bug like in first example ...

Edited by n3nE

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Link to comment
Share on other sites

Anyone?! :)

Does this do what you want? I would expect not since it's a bit obvious but thought I'd try.

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


#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 392, 321, -1, -1)
$ctrlID = GUICtrlCreateEdit( "This is line 1..." &@CRLF& "This is line 2... Select ALL and press SEND" &@CRLF& "This is line 3...", 24, 24, 337, 249, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN,$WS_VSCROLL))
;~ $input = GUICtrlCreateInput("", 24, 280, 273, 21)
$Button1 = GUICtrlCreateButton("SEND", 304, 280, 59, 20,$BS_DEFPUSHBUTTON)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $data = @CRLF& "...something..."
            $oldtext = GUICtrlRead($ctrlID)
            GUICtrlSetData($ctrlID, $oldtext & $data)
    EndSwitch
WEnd
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

know that...and i think this is too slow way ;/ and it's not scrolling to down...Well... I need something for chat, to scroll down and to support Unicode characters... and to not be bugged :)

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Link to comment
Share on other sites

  • 2 weeks later...

I sad already about that... not support Unicode characters...

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Link to comment
Share on other sites

  • 1 month later...

Hello again, command _GUICtrlEdit_AppendText is bugged like GuiCtrlSetData, check this out:

Posted Image

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

$Form1 = GUICreate("Form1", 633, 447, 0, 0)
$Edit1 = GUICtrlCreateEdit("Line number: 1/100", 100, 100, 200, 200)
GUISetState(@SW_SHOW)
MsgBox(0,"","Just hold down left click and shake mouse up/down over Edit ctrl!")
MouseMove(150,150, 0)
For $a = 2 To 100
    MouseMove(120,150, 1)
    _GUICtrlEdit_AppendText($Edit1,@CRLF & "Line number: "& $a&"/100")
    Sleep(50)
Next
MsgBox(0,"_GUICtrlEdit_GetLineCount",_GUICtrlEdit_GetLineCount($Edit1) &" (Should be 100)")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Somebody help, is there any way to add text in Edit but without deleting selected words ?

Edited by n3nE

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Link to comment
Share on other sites

n3nE

Seem works fine for me:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIEdit.au3>

$Form1 = GUICreate("Form1", 633, 447, 0, 0)
$Edit1 = GUICtrlCreateEdit("Line number: 1/100", 100, 100, 200, 200)

GUISetState(@SW_SHOW)


For $a = 2 To 100
    GUICtrlSetData($Edit1, "Line number: " & $a & "/100" & @CRLF, 1)
    Sleep(50)
Next

MsgBox(0,"_GUICtrlEdit_GetLineCount",_GUICtrlEdit_GetLineCount($Edit1) &" (Should be 100)")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

;)

Link to comment
Share on other sites

LOL, not works... just hold down left click and select some text in Edit ctrl and shake mouse up and down ;d ...& you will see...

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Link to comment
Share on other sites

@n3nE

This was probably addressed somewhere on the forums, but with a quick look at the includes I could see the problem.

_GUICtrlEdit_AppendText() uses a char array and not a wide char array

and _SendMessage() is using SendMessage and not SendMessageW

I'm not that well versed in Unicode support in AutoIt, perhaps someone else can comment.

Try this

Edit: added _GUICtrlEdit_InsertTextW()

;2 modified functions from GuiEdit.au3
;and 1 modified function from SendMessage.au3
#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>

Opt('MustDeclareVars', 1)
Local $hEdit, $Button1, $asd, $hEdit, $Input1, $nMsg
Local  $wordtosend, $UniWord

GUICreate("Edit Append Text", 400, 300)
$Button1 = GUICtrlCreateButton("Button1", 52, 272, 75, 25, 0)
$asd = _Ansi2Uni("Ä Ä Å¡ ž Ä")
$Input1 = GUICtrlCreateInput($asd, 130, 274, 217, 21)
$hEdit = GUICtrlCreateEdit("", 2, 2, 394, 268)
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $wordtosend = _Uni2Ansi(GUICtrlRead($Input1))
            $UniWord = _Ansi2Uni($wordtosend)
            GUICtrlSetData($hEdit, "GUICtrlSetData | Ansi 2 Uni: "& $UniWord)
            _GUICtrlEdit_AppendTextW($hEdit, @CRLF & "..._AppendText | Ansi 2 Uni: "& $UniWord)
            _GUICtrlEdit_InsertTextW($hEdit, @CRLF & "    ..._InsertText | Ansi 2 Uni: "& $UniWord)
    EndSwitch
WEnd
   
Func _Uni2Ansi($Unicode)
    Local $Binary, $Hex, $BinaryLength, $ANSI, $Char
    $Binary = StringToBinary($Unicode, 4)
    $Hex = StringReplace($Binary, '0x', '', 1)
    $BinaryLength = StringLen($Hex)
    For $i = 1 To $BinaryLength Step 2
        $Char = StringMid($Hex, $i, 2)
        $ANSI &= BinaryToString('0x' & $Char)
    Next
    Return $ANSI
EndFunc   ;==>_Uni2Ansi

Func _Ansi2Uni($ANSI)
    Local $Binary, $Unicode
    $Binary = StringToBinary($ANSI)
    $Unicode = BinaryToString($Binary, 4)
    Return $Unicode
EndFunc   ;==>_Ansi2Uni

;** wchar array instead of char
Func _GUICtrlEdit_AppendTextW($hWnd, $sText)
    If $Debug_Ed Then _GUICtrlEdit_ValidateClassName($hWnd)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
    Local $struct_MemMap, $struct_String, $sBuffer_pointer, $iLength
    $struct_String = DllStructCreate("wchar Text[" & StringLen($sText) + 1 & "]")
    $sBuffer_pointer = DllStructGetPtr($struct_String)
    DllStructSetData($struct_String, "Text", $sText)
    _MemInit($hWnd, StringLen($sText) + 1, $struct_MemMap)
    _MemWrite($struct_MemMap, $sBuffer_pointer)
    $iLength = _GUICtrlEdit_GetTextLen($hWnd)
    _GUICtrlEdit_SetSel($hWnd, $iLength, $iLength)
    __SendMessageW($hWnd, $EM_REPLACESEL, True, $sBuffer_pointer, 0, "wparam", "ptr")
    _MemFree($struct_MemMap)
EndFunc   ;==>_GUICtrlEdit_AppendText

;** SendMessageW instead of SendMessage
Func __SendMessageW($hWnd, $iMsg, $wParam = 0, $lParam = 0, $iReturn = 0, $wParamType = "wparam", $lParamType = "lparam", $sReturnType = "lparam")
    Local $aResult = DllCall("user32.dll", $sReturnType, "SendMessageW", "hwnd", $hWnd, "int", $iMsg, $wParamType, $wParam, $lParamType, $lParam)
    If @error Then Return SetError(@error, @extended, "")
    If $iReturn >= 0 And $iReturn <= 4 Then Return $aResult[$iReturn]
    Return $aResult
EndFunc   ;==>_SendMessage

;** wchar array instead of char
Func _GUICtrlEdit_InsertTextW($hWnd, $sText, $iIndex = -1)
    If $Debug_Ed Then _GUICtrlEdit_ValidateClassName($hWnd)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
    
    Local $struct_MemMap, $struct_String, $sBuffer_pointer

    If $iIndex = -1 Then
        _GUICtrlEdit_AppendTextW($hWnd, $sText)
    Else
        $struct_String = DllStructCreate("wchar Text[" & StringLen($sText) + 1 & "]")
        $sBuffer_pointer = DllStructGetPtr($struct_String)
        DllStructSetData($struct_String, "Text", $sText)
        _MemInit($hWnd, StringLen($sText) + 1, $struct_MemMap)
        _MemWrite($struct_MemMap, $sBuffer_pointer)
        _GUICtrlEdit_SetSel($hWnd, $iIndex, $iIndex)
        __SendMessageW($hWnd, $EM_REPLACESEL, True, $sBuffer_pointer, 0, "wparam", "ptr")
        _MemFree($struct_MemMap)
    EndIf
EndFunc   ;==>_GUICtrlEdit_InsertText

Cheers

Edited by rover

I see fascists...

Link to comment
Share on other sites

  • 2 months later...

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