• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

VB中实现窗体自动隐藏

发布: 2007-7-01 21:48 | 作者: admin | 来源: | 查看: 11次 | 进入软件测试论坛讨论

领测软件测试网

OICQ聊天时的窗体自动隐藏功能,用VC 或CBC都可以很简单地实现,前几天看到有一则用CBC实现的例子,便想用VB实现一下,可惜当窗体上放满控件时,FORM的MOUSEMOVE事件不能很好地触发,所以只好用以下的笨办法,现把代码贴上,窗体上需放一TIMER控件,Interval属性为200。大伙如有好的意见,不妨贴出来,让我学习学习。

Option Explicit

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type
Private Type POINTAPI
        X As Long
        Y As Long
End Type

Private Const HWND_TOPMOST = -1
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const HWND_TOP = 0
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_SHOWWINDOW = &H40


Private Sub Form_Load()
´窗体放在最前面
    SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub

Private Sub Timer1_Timer()
    Dim p As POINTAPI
    Dim f As RECT
    GetCursorPos p  ´得到MOUSE位置
    GetWindowRect Me.hwnd, f    ´得到窗体的位置
    If Me.WindowState <> 1 Then
        If p.X > f.Left And p.X < f.Right And p.Y > f.Top And p.Y < f.Bottom Then
        ´MOUSE 在窗体上
            If Me.Top < 0 Then
                Me.Top = -10
                Me.Show
            ElseIf Me.Left < 0 Then
                Me.Left = -10
                Me.Show
            ElseIf Me.Left + Me.Width >= Screen.Width Then
                Me.Left = Screen.Width - Me.Width + 10
                Me.Show
            End If
   
        Else
            If f.Top <= 4 Then
                Me.Top = 40 - Me.Height
            ElseIf f.Left <= 4 Then
                Me.Left = 40 - Me.Width
            ElseIf Me.Left + Me.Width >= Screen.Width - 4 Then
                Me.Left = Screen.Width - 40
            End If
        End If
    End If

End Sub


文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网