作者:BALLOONMAN2002 2004年6月26日
二、如何获取当前鼠标坐标对应NODE结点信息
1、新建一窗口,内含一TREEVIEW控件;
2、声明本地外部函数:
Function ulong SendMessage1(ulong hwnd,ulong wMsg,ulong wParam,ref TVHITTESTINFO lParam) LIBRARY "user32.dll" ALIAS FOR "SendMessageA"
Function ulong SendMessage2(ulong hwnd,ulong wMsg,ulong wParam,ref TVITEM lParam) LIBRARY "user32.dll" ALIAS FOR "SendMessageA"
SUBROUTINE CopyMemory (ref string Destination , long Source, long Length) LIBRARY "kernel32" Alias for "RtlMoveMemory"
Function ulong GlobalFree(ulong hMem) LIBRARY "kernel32.dll"
Function ulong GlobalAlloc(ulong wFlags,ulong dwBytes) LIBRARY "kernel32.dll"注:上述API声明涉及到的结构请查阅MSDN或其他技术资料。
3、对于该TREEVIEW控件自定义用户事件UE_MOUSEMOVE(PBM_MOUSEMOVE),在此事件当中处理鼠标移动事件,发送TVM_HITTEST消息:
tpoint ptA
tvhittestinfo tf
TVITEM tv
ulong hItem,ll_1,ll_2,ll_3,hStr
long ret,ll_x,ll_y
string astr,bstr,ls_help
ptA.x = UnitsToPixels(xpos, XUnitsToPixels!)
ptA.y = UnitsToPixels(ypos, YUnitsToPixels!)
tf.pt = ptA
tf.flags = 4
hItem = SendMessage1(handle(tv_1),4369,0,tf)
//注:上述4369为TVM_HITTEST
//通过发送TVM_HITTEST消息来获取当前对应的NODE的句柄,,将当前NODE结点信息保存到结构变量 TF当中
If ((hItem <= 0) Or (hItem = hItemPrv)) Then return
hItemPrv = hItem
hStr = GlobalAlloc(0,1024)
If hStr > 0 Then
tv.mask = 1
tv.HTreeItem = hItem
tv.pszText = hStr
tv.cchTextMax = 1023
ret = SendMessage2(handle(tv_1), 4364, 0, tv)
//注:上述4364为TVM_GETITEM
//通过对当前NODE发送TVM_GETITEM消息,将当前NODE结点信息保存到结构变量 TV当中
astr = space(1024)
//注:此处一定要分配足够空间,否则易非法操作
CopyMemory(astr, hStr, 1024)
//bstr = Left(astr, (pos(astr, Char(0)) - 1))
ret = GlobalFree(hStr)
ids_ds.setfilter("")
ids_ds.filter()
ret = ids_ds.find("name_gn = '" + astr + "'",1,ids_ds.rowcount())
if ret > 0 then
ls_help = ids_ds.getitemstring(ret,"help")
if (isnull(ls_help) or trim(ls_help) = "") then
timer(0)
iuo_tips.hide()
else
if is_help = ls_help then
return
end if
iuo_tips.hide()
iuo_tips.uf_set_text(ls_help,astr)
ib_tipshow = false
Timer(1)
end if
is_help = ls_help
else
timer(0)
iuo_tips.hide()
end if
else
timer(0)
iuo_tips.hide()
end if