|
作者: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效果
|