G'day All,

I am trying to use a Treeview control in a way that changes the item image of a particular item when some other item is clicked. This is used to indicate that a particular item is a valid drop target.

I have got this Treeview control to work, based on Iczelion?s Treeview tutorial #19 .


The problem is that the "WM_LBUTTONUP" mouse-up in a Treeview item does not work as expected.

When left-clicking a Treeview item, a "WM_LBUTTONUP" message is not sent to the Treeview window procedure on left-mouse-up. It works if the cursor is moved to another node before the left-mouse-up, but that is not very practical.



TreeViewProc proc hWin:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
...
mov eax, uMsg

.if(eax==WM_COMMAND)
;
...
.elseif(uMsg==WM_LBUTTONUP)
; Mouse-up in a Treeview item does not work as expected !!!
...


A workaround that seems to work - but not idealy - is to send a custom
"WM_LBUTTONUP" message to the Treeview procedure


...
.elseif(uMsg==WM_MOUSEMOVE)

; Simulate a "WM_LBUTTONUP" event ...
.if(...)
invoke SendMessage, hPrjTrv, WM_LBUTTONUP_X, wParam, lParam
.endif

; Custom WM_LBUTTONUP message
.elseif(uMsg==WM_LBUTTONUP_X)
; Handle the mouse-up in the Treeview item
...


Does anyone know how to handle the "WM_LBUTTONUP" message correctly,
in the Treeview item ?


Thanks
Dorf
Posted on 2004-09-14 18:12:42 by dorf
how about processing the TVN_SELCHANGING or TVN_SELCHANGED?

you can also process the NM_CLICK message. then use GetCursorPos,ScreenToClient,TVM_HITTEST to determine the what item is clicked.

WM_LBUTTONUP is processed only when someone clicks in the treeview but not on an item or subitem.
Posted on 2004-09-15 13:50:12 by smurf
Thanks smurf,

I still cannot handle any of these messages on a mouse-up in the
Treeview node (with no mouse move).

But that gave me an idea :)
I'll just add another call to my custom mouse-up message handler
in the regular "WM_LBUTTONUP" handler to handle all scenarios.

Any better ideas ...



TreeViewProc proc hWin:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
...
.elseif(uMsg==WM_MOUSEMOVE)

; Handle a mouse-up event in the Treeview item
; (not on a Treeview client area).
.if(DragTargetLive == TRUE && DragMode == FALSE)
; Custom mouse-up message
invoke SendMessage, hPrjTrv, WM_LBUTTONUP_X, wParam, lParam
.endif
...

; Custom WM_LBUTTONUP message
.elseif(uMsg==WM_LBUTTONUP_X)
; Note: Mouse-up in a Treeview item does not work as expected !!!
; Revert the original "target" (drag-n-drop candidate) node images if we
; have a WM_LBUTTONUP or WM_MOUSEMOVE
.if(DragTargetLive == TRUE)
mov tvi.imask, TVIF_IMAGE ; The Treeview image is changing
m2m tvi.hItem, hTVItem01 ; The "target" node handle
mov tvi.iImage, 1 ; The old "target" image index. zero based
invoke SendMessage, hPrjTrv, TVM_SETITEM, 0, addr tvi
mov DragTargetLive, FALSE ; The "target" node is no longer "live"
.endif


.elseif(uMsg==WM_LBUTTONUP)

; Handle a mouse-up event in the Treeview client area
; (not on a Treeview item).
.if(DragTargetLive == TRUE && DragMode == FALSE)
; Custom mouse-up message if any drag targets are "live"
; (and user is not draging).
invoke SendMessage, hPrjTrv, WM_LBUTTONUP_X, wParam, lParam
.endif

...



Heres my revised Treeview drag-and-drop demo.



Thanks to all the ASM guys for the awesome tutorials and source/examples.

Dorf
Posted on 2004-09-15 21:24:26 by dorf