Jump to content

Put number into 1st word of string buffer


 Share

Recommended Posts

Not sure how to go about it in Autoit

Edit Controls

EM_GETLINE function is what I'm trying to figure out.

Param

Pointer to the buffer that receives a copy of the line. Before sending the message, set the first word of this buffer to the size, in TCHARs, of the buffer. For ANSI text, this is the number of bytes; for Unicode text, this is the number of characters. The size in the first word is overwritten by the copied line.

#include <GuiEdit.au3>
#include <Misc.au3>

Global Const $EM_GETLINE = 0xC4

Run("Notepad")
WinWait("Untitled - Notepad")
;~ Sleep ( 5000 )
$h_Edit = ControlGetHandle("Untitled - Notepad", "", "Edit1")
$text = "this is line 1" & @CRLF & "Line 2" & @CRLF & "Line 3"
_WM_SETTEXT($h_Edit, $text)
ConsoleWrite(_GUICtrlEditGetLine($h_Edit, 2) & @LF)

Func _WM_SETTEXT($h_Edit, $s_Text)
    Local Const $WM_SETTEXT = 0xC
    Local $struct_string = DllStructCreate("char[" & StringLen($s_Text) + 1 & "]")
    DllStructSetData($struct_string, 1, $s_Text)
    _SendMessage($h_Edit, $WM_SETTEXT, 0, DllStructGetPtr($struct_string))
EndFunc   ;==>_WM_SETTEXT

Func _GUICtrlEditGetLine($h_Edit, $i_line)
    $i_index = _GUICtrlEditLineIndex($h_Edit, $i_line)
    ConsoleWrite("$i_index: " & $i_index & @LF)
    $length = _GUICtrlEditLineLength($h_Edit, $i_index)
    ConsoleWrite("Length: " & $length & @LF)
;************************************************************************************
; lines in question, how to set 1st word to length?
;************************************************************************************
    $struct_Buffer = DllStructCreate("char[" & $length & "]") ; need to set 1st word to length?
    If @error Then Return SetError(-1, -1, "")
    Local $iResult = _SendMessage($h_Edit, $EM_GETLINE, $i_index, DllStructGetPtr($struct_Buffer))
    If @error Then Return SetError(-2, -2, "")
    Return DllStructGetData($struct_Buffer, 1)
;************************************************************************************
;************************************************************************************
;************************************************************************************
EndFunc   ;==>_GUICtrlEditGetLine

Gary

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

Sorry, i tried a bit and couldn't get it to work.

Wouldn't it just be easier to read the whole control, split the text into an array by line, and then read the corresponding element of the array to get the text you want?

[EDIT]

Here is something i whipped up, but i bet you already knew how to do this:

Dim $i_LineNumberToGetTextFrom = 3
Dim $s_ControlText = ControlGetText("Untitled - Notepad", "", "Edit1")
Dim $as_ControlText = StringSplit( StringStripCR($s_controltext), @LF)

If UBound($as_ControlText)-1 >= $i_LineNumberToGetTextFrom  Then
    ConsoleWrite("Line Text:" & $as_ControlText[$i_LineNumberToGetTextFrom]&@LF)
    Msgbox(0,"Line " & $i_LineNumberToGetTextFrom & " text is:",$as_ControlText[$i_LineNumberToGetTextFrom])
Endif
Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

Sorry, i tried a bit and couldn't get it to work.

Wouldn't it just be easier to read the whole control, split the text into an array by line, and then read the corresponding element of the array to get the text you want?

[EDIT]

Here is something i whipped up, but i bet you already knew how to do this:

Dim $i_LineNumberToGetTextFrom = 3
Dim $s_ControlText = ControlGetText("Untitled - Notepad", "", "Edit1")
Dim $as_ControlText = StringSplit( StringStripCR($s_controltext), @LF)

If UBound($as_ControlText)-1 >= $i_LineNumberToGetTextFrom  Then
    ConsoleWrite("Line Text:" & $as_ControlText[$i_LineNumberToGetTextFrom]&@LF)
    Msgbox(0,"Line " & $i_LineNumberToGetTextFrom & " text is:",$as_ControlText[$i_LineNumberToGetTextFrom])
Endif

Wasn't the point http://www.autoitscript.com/forum/index.ph...st&p=280409

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

  • Developers

Does this help?

$struct_Buffer = DllStructCreate("char[" & $length & "]") ; need to set 1st word to length?
    If @error Then Return SetError(-1, -1, "")
    DllStructSetData($struct_Buffer,1,$length,1)
    Local $iResult = _SendMessage($h_Edit, $EM_GETLINE, $i_line-1, DllStructGetPtr($struct_Buffer))
    If @error Then Return SetError(-2, -2, "")
    Return DllStructGetData($struct_Buffer, 1)

Looks like you need to set the first Byte of the struct to the length ...

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Does this help?

$struct_Buffer = DllStructCreate("char[" & $length & "]") ; need to set 1st word to length?
    If @error Then Return SetError(-1, -1, "")
    DllStructSetData($struct_Buffer,1,$length,1)
    Local $iResult = _SendMessage($h_Edit, $EM_GETLINE, $i_line-1, DllStructGetPtr($struct_Buffer))
    If @error Then Return SetError(-2, -2, "")
    Return DllStructGetData($struct_Buffer, 1)

Looks like you need to set the first Byte of the struct to the length ...

Yes, worked for me. Spent a while trying to figure out why it wasn't working. :P

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

Does this help?

$struct_Buffer = DllStructCreate("char[" & $length & "]") ; need to set 1st word to length?
    If @error Then Return SetError(-1, -1, "")
    DllStructSetData($struct_Buffer,1,$length,1)
    Local $iResult = _SendMessage($h_Edit, $EM_GETLINE, $i_line-1, DllStructGetPtr($struct_Buffer))
    If @error Then Return SetError(-2, -2, "")
    Return DllStructGetData($struct_Buffer, 1)

Looks like you need to set the first Byte of the struct to the length ...

Yep, that worked, thanks.

Thought I tried that, but must of done it wrong.

Edit: yep did try that, just forgot to subtract 1 from the line.

Gary

Edited by gafrost

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

Make sure you set the first word, not necessarily the first byte. A word is 16 bits and a byte is 8 bits. I would probably create the structure as:

$struct_Buffer = DllStructCreate("short;char[" & $length - 2 & "]")oÝ÷ Ù8^*.q©ìzÛayø«²ÛÚ籪i®k«^N§«^¯^*.ç¶që,¶¬¶¸§)íæî}÷«r·µæ§{-®ç-º·®²)ඩ¢)íz»h¶¨®("©l¶»¶êÞjëh×6$struct_String = DllStructCreate("char[" & $length & "]", DllStructGetPtr($struct_Buffer))

The main reason for doing that is the method shown above is limited to a string length of 255. Trying to assign a value larger than that to a char will result in overflowing the char. Also, the only reason the code works at all is because Windows is little endian so the first byte is the low-order byte.

Edited by Valik
Typo fix.
Link to comment
Share on other sites

Make sure you set the first word, not necessarily the first byte. A word is 16 bits and a byte is 8 bits. I would probably create the structure as:

$struct_Buffer = DllStructCreate("short;char[" & $length - 2 & "]")oÝ÷ Ù8^*.q©ìzÛayø«²ÛÚ籪i®k«^N§«^¯^*.ç¶që,¶¬¶¸§)íæî}÷«r·µæ§{-®ç-º·®²)ඩ¢)íz»h¶¨®("©l¶»¶êÞjëh×6$struct_String = DllStructCreate("char[" & $length & "]", DllStructGetPtr($struct_Buffer))

The main reason for doing that is the method shown above is limited to a string length of 255. Trying to assign a value larger than that to a char will result in overflowing the char. Also, the only reason the code works at all is because Windows is little endian so the first byte is the low-order byte.

Thanks for the tip/help Valik

Gary

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