News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

TreeView and Unicode Strings!!!

Started by xandaz, November 02, 2011, 01:22:21 AM

Previous topic - Next topic

xandaz

   Why would a treeview control not accept unicode strings? I used TVM_SETUNICODEFORMAT and also CCM_.... but the item only shows the first character.hanks in advance and later.


MichaelW

How did you create the tree-view control?
eschew obfuscation

ToutEnMasm

Some useful informations:
There is no unicode class for the treeview but ...
There is a unicode CreateWindowExW
With windows.inc , specified this one.
Take care that windows.inc,at the instant,don't allow unicode in a simple way.
add a W at all your functions to see if they have  a unicode version.
better in this case is the used of .sdk translate ,other definitions could have unicode versions.
With it , you have just to add "UNICODE equ 1" on your code and all is made

Quote
;API
CreateWindowExA PROTO :DWORD ,:DWORD ,:DWORD ,:DWORD ,:DWORD ,:DWORD ,:DWORD ,:DWORD ,:DWORD ,:DWORD ,:DWORD ,:DWORD
;API
CreateWindowExW PROTO :DWORD ,:DWORD ,:DWORD ,:DWORD ,:DWORD ,:DWORD ,:DWORD ,:DWORD ,:DWORD ,:DWORD ,:DWORD ,:DWORD
IFDEF UNICODE
CreateWindowEx   equ   < CreateWindowExW>
ELSE
CreateWindowEx   equ   < CreateWindowExA>
ENDIF ; !UNICODE


Quote
IFDEF _WIN32
WC_TREEVIEWA   equ   <"SysTreeView32">
WC_TREEVIEWW   equ   <"SysTreeView32">
IFDEF UNICODE
WC_TREEVIEW   equ   < WC_TREEVIEWW>
ELSE
WC_TREEVIEW   equ   < WC_TREEVIEWA>
ENDIF
ELSE
WC_TREEVIEW   equ   <"SysTreeView">
ENDIF

MichaelW

From the Microsoft CommCtrl.h:

//====== TREEVIEW CONTROL =====================================================

#ifndef NOTREEVIEW

#ifdef _WIN32
#define WC_TREEVIEWA            "SysTreeView32"
#define WC_TREEVIEWW            L"SysTreeView32"

#ifdef UNICODE
#define  WC_TREEVIEW            WC_TREEVIEWW
#else
#define  WC_TREEVIEW            WC_TREEVIEWA
#endif

#else
#define WC_TREEVIEW             "SysTreeView"
#endif
eschew obfuscation

ToutEnMasm


a usefull info:
With the unicode function ,all the chains are in unicode.

MichaelW

For a test app I used a modified version of the Iczelion's tutorial 19 from the MASM32 version 9 distribution. If I create the tree-view control by passing a Unicode class name to CreateWindowExW, then the created control is a native Unicode window. I didn't have time to properly translate the Unicode structures and constants from the PSDK CommCtrl.h, so I just modified the TVM_INSERTITEM message value to match this definition:

#define TVM_INSERTITEMA         (TV_FIRST + 0)
#define TVM_INSERTITEMW         (TV_FIRST + 50)


And the code then displayed the full Unicode item names.


;========================================================================================
include \masm32\include\masm32rt.inc
include \masm32\macros\ucmacros.asm
;========================================================================================

WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
.const
IDB_TREE equ 4006
.data
ClassName       db "TreeViewWinClass",0
AppName         db "Tree View Demo",0

;TreeViewClass   db "SysTreeView32",0

WSTR TreeViewClass,"SysTreeView32"

;Parent          db "Parent Item",0
WSTR Parent,"Parent Item"

;Child1          db "child1",0
WSTR Child1,"child1"

;Child2          db "child2",0
WSTR Child2,"child2"

DragMode        dd FALSE

.data?
hInstance       HINSTANCE ?
hwndTreeView    dd ?
hParent         dd ?
hImageList      dd ?
hDragImageList  dd ?

.code
start:
    invoke GetModuleHandle, NULL
    mov    hInstance,eax
    invoke WinMain, hInstance,NULL,NULL, SW_SHOWDEFAULT
    invoke ExitProcess,eax
    invoke InitCommonControls

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
    LOCAL wc:WNDCLASSEX
    LOCAL msg:MSG
    LOCAL hwnd:HWND
    mov   wc.cbSize,SIZEOF WNDCLASSEX
    mov   wc.style, CS_HREDRAW or CS_VREDRAW
    mov   wc.lpfnWndProc, OFFSET WndProc
    mov   wc.cbClsExtra,NULL
    mov   wc.cbWndExtra,NULL
    push  hInst
    pop   wc.hInstance
    mov   wc.hbrBackground,COLOR_APPWORKSPACE
    mov   wc.lpszMenuName,NULL
    mov   wc.lpszClassName,OFFSET ClassName
    invoke LoadIcon,NULL,IDI_APPLICATION
    mov   wc.hIcon,eax
    mov   wc.hIconSm,eax
    invoke LoadCursor,NULL,IDC_ARROW
    mov   wc.hCursor,eax
    invoke RegisterClassEx, addr wc
    invoke CreateWindowEx,WS_EX_CLIENTEDGE,ADDR ClassName,ADDR AppName,
           WS_OVERLAPPED+WS_CAPTION+WS_SYSMENU+WS_MINIMIZEBOX+WS_MAXIMIZEBOX+WS_VISIBLE,
           CW_USEDEFAULT,CW_USEDEFAULT,200,400,NULL,NULL,
           hInst,NULL
    mov   hwnd,eax
    .while TRUE
        invoke GetMessage, ADDR msg,NULL,0,0
        .BREAK .IF (!eax)
        invoke TranslateMessage, ADDR msg
        invoke DispatchMessage, ADDR msg
    .endw
    mov eax,msg.wParam
    ret
WinMain endp

WndProc proc uses edi hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
    LOCAL tvinsert:TV_INSERTSTRUCT
    LOCAL hBitmap:DWORD
    LOCAL tvhit:TV_HITTESTINFO
    .if uMsg==WM_CREATE

        invoke CreateWindowExW,NULL,ADDR TreeViewClass,NULL,
               WS_CHILD+WS_VISIBLE+TVS_HASLINES+TVS_HASBUTTONS+TVS_LINESATROOT,
               0,0,200,400,hWnd,NULL,hInstance,NULL

        mov hwndTreeView,eax

        invoke IsWindowUnicode, hwndTreeView
        .IF eax
            MsgBox hWnd,"IS UNICODE","TreeView Control",0
        .ELSE
            MsgBox hWnd,"IS NOT UNICODE","TreeView Control",0
        .ENDIF

        invoke ImageList_Create,16,16,ILC_COLOR16,2,10
        mov hImageList,eax
        invoke LoadBitmap,hInstance,IDB_TREE
        mov hBitmap,eax
        invoke ImageList_Add,hImageList,hBitmap,NULL
        invoke DeleteObject,hBitmap
        invoke SendMessage,hwndTreeView,TVM_SETIMAGELIST,0,hImageList
        mov tvinsert.hParent,NULL
        mov tvinsert.hInsertAfter,TVI_ROOT
        mov tvinsert.item.imask,TVIF_TEXT+TVIF_IMAGE+TVIF_SELECTEDIMAGE
        mov tvinsert.item.pszText,offset Parent
        mov tvinsert.item.iImage,0
        mov tvinsert.item.iSelectedImage,1

        ;invoke SendMessage,hwndTreeView,TVM_INSERTITEM,0,addr tvinsert
        invoke SendMessage,hwndTreeView,TVM_INSERTITEM+50,0,addr tvinsert

        mov hParent,eax
        mov tvinsert.hParent,eax
        mov tvinsert.hInsertAfter,TVI_LAST
        mov tvinsert.item.pszText,offset Child1

        ;invoke SendMessage,hwndTreeView,TVM_INSERTITEM,0,addr tvinsert
        invoke SendMessage,hwndTreeView,TVM_INSERTITEM+50,0,addr tvinsert

        mov tvinsert.item.pszText,offset Child2

        ;invoke SendMessage,hwndTreeView,TVM_INSERTITEM,0,addr tvinsert
        invoke SendMessage,hwndTreeView,TVM_INSERTITEM+50,0,addr tvinsert

    .elseif uMsg==WM_MOUSEMOVE
        .if DragMode==TRUE
            mov eax,lParam
            and eax,0ffffh
            mov ecx,lParam
            shr ecx,16
            mov tvhit.pt.x,eax  ; eax is the horizontal position of the drag image
            mov tvhit.pt.y,ecx  ; ecx is the vertical position
            invoke ImageList_DragMove,eax,ecx
            invoke ImageList_DragShowNolock,FALSE
            ; check if an item is hit
            invoke SendMessage,hwndTreeView,TVM_HITTEST,NULL,addr tvhit
            .if eax!=NULL
                invoke SendMessage,hwndTreeView,TVM_SELECTITEM,TVGN_DROPHILITE,eax
            .endif
            invoke ImageList_DragShowNolock,TRUE
        .endif
    .elseif uMsg==WM_LBUTTONUP
        .if DragMode==TRUE
            invoke ImageList_DragLeave,hwndTreeView
            invoke ImageList_EndDrag
            invoke ImageList_Destroy,hDragImageList
            ; Get the currently hilited item
            invoke SendMessage,hwndTreeView,TVM_GETNEXTITEM,TVGN_DROPHILITE,0
            invoke SendMessage,hwndTreeView,TVM_SELECTITEM,TVGN_CARET,eax
            invoke SendMessage,hwndTreeView,TVM_SELECTITEM,TVGN_DROPHILITE,0
            invoke ReleaseCapture
            mov DragMode,FALSE
        .endif
    .elseif uMsg==WM_NOTIFY
        mov edi,lParam
        assume edi:ptr NM_TREEVIEW
        .if [edi].hdr.code==TVN_BEGINDRAG
            invoke SendMessage,hwndTreeView,TVM_CREATEDRAGIMAGE,0,[edi].itemNew.hItem
            mov hDragImageList,eax
            invoke ImageList_BeginDrag,hDragImageList,0,0,0
            invoke ImageList_DragEnter,hwndTreeView,[edi].ptDrag.x,[edi].ptDrag.y
            invoke SetCapture,hWnd
            mov DragMode,TRUE
        .endif
        assume edi:nothing
    .elseif uMsg==WM_DESTROY
        invoke PostQuitMessage,NULL
    .else
        invoke DefWindowProc,hWnd,uMsg,wParam,lParam
        ret
    .endif
    xor eax,eax
    ret
WndProc endp

end start


eschew obfuscation

lingo

In my "Faster DirTree View" I use in the treeview control more than 80 %  Unicode strings! 
Just download DTLight2.zip file from here. :U

xandaz

   I want to thank you all for replying. It has been very helpful. Thanks and sorry for having taken so long but i was kinda off.
   Best regards from your humble dexciple.
   X