作者:balloonman2002 2004年6月26日
三、自动显示/隐藏窗口功能实现
1、处理该window的other事件,借助此事件来捕获wm_mouseleave消息,来获取并处理鼠标移出事件:
str_rect ls_rect
str_point ls_point,ls_tmp
//注:wm_mouseleave消息一旦离开窗口的client区域就会发送,如:当鼠标移至窗口上的控件时也会发送此消息,当鼠标移到窗口的caption或者menu或者border时也会发送此消息,故不能不加任何判断而直接隐藏窗口,并且此消息只发送一遍,若需继续跟踪鼠标,则需再次调用trackmouseevent函数;
if message.number = wm_mouseleave then
ib_onform = false
getcursorpos(ls_point)
getclientrect(handle(this),ls_rect)
ls_tmp.x = ls_rect.left
ls_tmp.y = ls_rect.top
clienttoscreen(handle(this),ls_tmp)
offsetrect(ls_rect,ls_tmp.x,ls_tmp.y)
//判断鼠标如果超出客户区,则自动隐藏窗口
//只能使用客户区判断,不能使用整个窗口rect,否则当鼠标移至border时可能会无法隐藏窗口
if (ptinrect(ls_rect,ls_point.x,ls_point.y) = 0) and ((this.x <= 0) or (this.y <= 0)) then
if this.y <= 0 then
wf_hide_v(this) //首先保证在v方向收缩滑动
else
wf_hide_h(this) //其次保证在h方向收缩滑动
end if
ib_display = false
end if
end if
2、处理该window的mousemove事件来处理鼠标移入事件:
if ib_onform = false then
ib_onform = true
if ib_display = false then
if this.y <= 0 then
wf_display_v(this)
else
wf_display_h(this)
end if
ib_display = true
end if
wf_capmouse(this)
end if
3、创建该窗口的open事件,以设置该窗口运行的初始位置:
this.backcolor = 16574393
this.title = “自动隐藏窗口示例___双击关闭窗口”
this.setposition(topmost!)
this.width = p_1.width
this.height = p_1.height
this.x = 100
this.y = -this.height
wf_display_v(this)
4、创建相应的窗口函数wf_capmouse以调用鼠标消息捕获函数:
str_track_mouse str_trm
str_trm.nsize = 16
str_trm.hwndtrack = handle(ag_dest)
str_trm.nflags = 2
trackmouseevent(str_trm)
5、创建相应的窗口函数wf_display_h以设置窗口如何在水平方向滑动显示:
integer li_left
str_rect ls_rect1,ls_rect2
str_point ls_tmp
getwindowrect(handle(this),ls_rect1)
getclientrect(handle(this),ls_rect2)
ls_tmp.x = ls_rect2.left
ls_tmp.y = ls_rect2.top
clienttoscreen(handle(this),ls_tmp)
offsetrect(ls_rect2,ls_tmp.x,ls_tmp.y)
li_left = ls_rect2.left – ls_rect1.left //计算出窗口边框宽度
//计算窗口边框还可以用getsystemmetrics+sm_cxborder/sm_cyborder/sm_cxframe/sm_cyframe,但是需要判断窗口状态是可变边框还是不可变边框还是无边框,因此不如直接采用上述方法
do while as_win.x < -15
as_win.x = as_win.x + 10 //这里的10主要用于控制窗口滑动速度
if ib_first_display then
p_1.draw(0,0) //这里主要防止第一次滑动窗口时不显示图象
end if
sleep(0.01) //这里的sleep函数主要用于控制窗口滑动速度
loop
as_win.x = -3*li_left //这里值不能太小否则,鼠标移到左侧时易出边界
ib_first_display = false
注:用于设置窗口如何在垂直方向滑动显示的wf_display_v函数不再赘述,修改as_win.y属性即可。
6、创建相应的窗口函数wf_display_h以设置窗口如何在水平方向滑动隐藏:
do while as_win.x > -as_win.width + 25
as_win.x = as_win.x – 10
if ib_first_hide then
p_1.draw(0,0) //这里主要防止第一次隐藏窗口时不显示图象
end if
sleep(0.005)
loop
as_win.x = -as_win.width + 10 //这里的10用于控制最后窗口隐藏后留在外侧的边距
ib_first_hide = false
注:用于设置窗口如何在垂直方向滑动显示的wf_display_v函数不再赘述,修改as_win.y属性即可。
7、由于该窗口为no titlebar窗口,因此无法拖动,需要专门编写脚本来实现拖动效果,方法为处理窗口的mousedown事件:
ulong ll_arg
releasecapture() //释放对mouse消息的捕获,故在拖动期间不会发生wm_mouseleave事件
ll_arg = 0
sendmessage(handle(this),wm_nclbuttondown,htcaption,ll_arg)
//即发送wm_nclbuttondown消息,模拟用户拖动titlebar效果
