VB 窗体在屏幕上方自动伸缩

一个Form1,一个Module1, Form1上再添个Timer控件 interval 为100

 


添加一个模块Module1,里面代码如下: 

Public   Declare   Function   GetWindowRect   Lib   "user32 "   (ByVal   hWnd   As   Long,   lpRect   As   RECT)   As   Long 
Public   Declare   Function   GetCursorPos   Lib   "user32 "   (lpPoint   As   POINTAPI)   As   Long 
Public   Declare   Function   PtInRect   Lib   "user32 "   (lpRect   As   RECT,   ByVal   ptx   As   Long,   ByVal   pty   As   Long)   As   Long 
Public   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 
Public   MyRect   As   RECT,   MyCur   As   POINTAPI 
Public   Type   RECT 
                Left   As   Long 
                Top   As   Long 
                Right   As   Long 
                Bottom   As   Long 
End   Type 
Public   Type   POINTAPI 
                x   As   Long 
                y   As   Long 
End   Type 

Public   Sub   QQ(Myform   As   Form) ' '哈哈,我把它做成个函数,就可以到处引用了 
On   Error   Resume   Next 
Dim   dl   As   Long 
dl   =   GetWindowRect(Myform.hWnd,   MyRect) 
dl   =   GetCursorPos(MyCur) 
If   (PtInRect(MyRect,   MyCur.x,   MyCur.y))   And   Myform.Top   <=   0   Then 
    Myform.Top   =   0 
    Exit   Sub 
End   If 
If   Not   (PtInRect(MyRect,   MyCur.x,   MyCur.y))   And   Myform.Top   <=   0   Then 
    Myform.Top   =   0   -   Myform.Height   +   330   /   4 
    Exit   Sub 
End   If 
End   Sub 

Public   Sub   SetOnTop(xForm   As   Form)   '窗体最顶,象QQ这样的窗体,必须最顶,不然有窗体遮住它且是最大化的,它缩上去屏幕上方,用鼠标指它,它也下不来的 
SetWindowPos   xForm.hWnd,   -1,   0,   0,   0,   0,   3 
End   Sub 

' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '窗体里的代码 
Private   Sub   Form_Load() 
SetOnTop   Me 
End   Sub 

Private   Sub   Timer1_Timer() 'Timer的Interval值设为500吧 
Call   QQ(Me) 
End   Sub 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值