;************************************************************************************
; Get the text of the [Control] using WM_GETTEXT and returns a handle of the string.
;************************************************************************************
proc GetControlTextUtf8, .Control
begin
        push    ebx ecx edx

        invoke  SendMessageW, [.Control], WM_GETTEXTLENGTH, 0, 0
        lea     ecx, [eax+1]
        lea     eax, [4*eax]
        stdcall GetMem, eax
        mov     ebx, eax

        invoke  SendMessageW, [.Control], WM_GETTEXT, ecx, ebx

        stdcall WideCharToUtf8, ebx

        pop     edx ecx ebx
        return
endp



;*******************************************************************************
; Get the text of the [Control] using WM_GETTEXT and put it to the string with
; handle (only) in [string].
;
; if [string] = NULL creates new string and returns the handle.
; if [string] <> NULL just copyes the text.
;*******************************************************************************
proc GetControlText2, .Control
.len dd ?
begin
        push    ebx ecx edx

        stdcall StrNew
        mov     ebx, eax

        invoke  SendMessageA, [.Control], WM_GETTEXTLENGTH, 0, 0
        mov     [.len], eax

        stdcall StrSetCapacity, ebx, eax
        jc      .error

        push    eax
        add     [.len], 1
        invoke  SendMessageA, [.Control], WM_GETTEXT, [.len], eax
        pop     ecx
        mov     [ecx+string.len], eax
        mov     eax, ebx
        clc

.error:
        pop     edx ecx ebx
        return
endp





;*******************************************************************************
; Sets the text in control using WM_SETTEXT from string with handle or pointer
; in [string].
;*******************************************************************************
proc SetControlText, .Control, .string
begin
        push    eax ecx edx
        stdcall StrPtr, [.string]
        invoke  SendMessageA, [.Control], WM_SETTEXT, 0, eax
        pop     edx ecx eax
        return
endp
