News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

How to show the char tab (9) in a treewiew control

Started by TouEnMasm, April 26, 2013, 08:02:48 PM

Previous topic - Next topic

TouEnMasm

Hello,
The treeview show a rectangle instead off the char tab.
Is there a way to correct this ?.
Fa is a musical note to play with CL

fearless

Might have to just manually replace with a couple of space 32d (20h) characters instead  if it wont process tab char for spacing

TouEnMasm

It is a soluce,not satisfying,but it is one.I search something who don't need to modify the text.

Fa is a musical note to play with CL

Tedd

You can't display tabs - it's not a character, it's more like an instruction to align the text.
You will have to do the alignment yourself by inserting the correct number of spaces (different for each line), or use customdraw.
Potato2

dedndave

you might consider using tabs to indicate "move to the next column"
at any rate, the implementation is left to you   :P

MichaelW

I didn't have much time to check this, but I think it's at least mostly correct. Originally I was planning to test it against TabbedTextOut at a variety of tab widths, but that turned out to be impractical. So since I had long ago tested the basic algorithm, I tested against whatever console-output function printf calls, at the standard tab width of 8, and then inspected the output at a few other tab width values.


;==============================================================================
    include \masm32\include\masm32rt.inc
;==============================================================================
    .data
      str1  db 9,"aaa",4 dup(9),"b",9,"c",0
    .code
;==============================================================================
GetXtabBufferSize proc pstring:DWORD, tabwidth:DWORD
    push ebx
    push edi
    push esi
    mov ebx, pstring
    xor edi, edi            ; destindex
    mov ecx, tabwidth
    mov esi, -1             ; string index
  @@:
    add esi, 1
    movzx eax, BYTE PTR [ebx+esi]
    test al, al
    jz  @F
    add edi, 1
    cmp al, 9
    jne @B
    sub edi, 1
    ; spacecount = tabwidth - (destindex % tabwidth)
    mov eax, edi
    cdq
    div ecx
    mov eax, ecx
    sub eax, edx            ; spacecount
    add edi, eax            ; update destindex
    jmp @B
  @@:
    mov eax, edi
    pop esi
    pop edi
    pop ebx
    ret
GetXtabBufferSize endp
;==============================================================================
Xtab proc pstring:DWORD, pbuff:DWORD, tabwidth:DWORD
    push ebx
    push edi
    push esi
    mov ebx, pstring
    xor edi, edi            ; destindex
    mov ecx, pbuff
    mov esi, -1             ; string index
  L0:
    add esi, 1
    movzx eax, BYTE PTR [ebx+esi]
    test al, al
    jz  L3
    cmp al, 9
    je  L1
    mov BYTE PTR [ecx+edi], al
    add edi, 1
    jmp L0
  L1:
    ; spacecount = tabwidth - (destindex % tabwidth)
    mov eax, edi
    cdq
    div tabwidth
    mov eax, tabwidth
    sub eax, edx            ; spacecount
  L2:
    mov BYTE PTR [ecx+edi], 20h
    add edi, 1
    sub eax, 1
    jnz L2
    jmp L0
  L3:
    pop esi
    pop edi
    pop ebx
    ret
Xtab endp
;==============================================================================
start:
;==============================================================================
    printf("         1         2         3         4         5         6\n")
    printf("123456789012345678901234567890123456789012345678901234567890\n")
    printf("%s\n",ADDR str1)
    invoke GetXtabBufferSize, ADDR str1, 8
    push eax
    printf("%d\n",eax)
    pop eax
    add eax, 1
    mov ebx, alloc(eax)
    invoke Xtab, ADDR str1, ebx, 8
    printf("%s\n\n", ebx)
    xor ecx, ecx
  @@:
    movzx eax, BYTE PTR[ebx+ecx]
    test eax, eax
    jz  @F
    pushad
    printf("%d ", eax)
    popad
    add ecx, 1
    jmp @B
  @@:
    printf("\n\n%d\n\n", ecx)
    inkey
    exit
;==============================================================================
end start


The simple approach is to allocate a zero-filled buffer with a length of stringlength * tabwidth.

To reuse an allocated buffer the procedure would need to copy the terminating null to the buffer, and I didn't think to do this.
Well Microsoft, here's another nice mess you've gotten us into.