VB工程--百例94--屏幕保护

本文详细介绍了在编程过程中遇到光标无法显示的问题,并通过使用ShowCursor函数成功解决了这一问题。文章还提供了代码示例,包括如何使用ShowCursor函数控制光标的显示与隐藏,以及如何在窗体加载时调整其大小和位置。

 

敲此例题时出现了一个问题,就是程序运行后,鼠标找不到啦!经过不懈努力和高人指点,这才把问题解决啦!自己不懂的还很多,编程路任重而道远下面红色字体是注释,认真读写。

Option Explicit
Dim x, r
Private Sub Form_KeyPress(KeyAscii As Integer)
        If KeyAscii = vbKeyEscape Then  '按escape键退出
                x = ShowCursor(True)  'ShowCursor 函数功能:该函数显示或隐藏光标。
        End If
      
End Sub
Private Sub Form_Load()
         ' x = ShowCursor(False)  此句话的意思是光标隐藏  把false改成true光标同样出现
       Form1.Width = Screen.Width
       Form1.Height = Screen.Height
       Form1.BackColor = RGB(0, 0, 255)
       Label1.Top = (Screen.Height - Label1.Height) / 2
       Label1.Left = 0
       Label1.Caption = "廊坊师范学院信息技术提高班"
       Label1.ForeColor = RGB(255, 0, 0)
       Label1.FontItalic = True
       Label2.Caption = "九期学员邢金聪"
       Label2.ForeColor = RGB(0, 255, 255)
       Label2.FontItalic = True
       Label2.Left = (Screen.Width - Label2.Width) / 2
       Label2.Top = 0
End Sub

Private Sub Timer1_Timer()
        r = SetWindowPos(Form1.hwnd, -1, 0, 0, 0, 0, 3)
       ' BOOL SetWindowPos(HWND hWnd,HWND hWndlnsertAfter,int X,int Y,int cx,int cy,UNIT.Flags)
        ' h 是类型描述,表示句柄, Wnd 是变量对象描述,表示窗口,所以hWnd 表示窗口句柄
        ' 通俗地说,如果把一个到处跑的人当作指针的话,那么HWND就是该人的身份证
        'http://baike.baidu.com/view/4287577.htm
        Label1.Left = Label1.Left + 60
        If Label1.Left > Form1.Width Then
        Label1.Left = -3000
        End If
        Label2.Top = Label2.Top + 60
        If Label2.Top > Form1.Height Then
        Label2.Top = -3000
        End If
End Sub

Option Explicit
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
http://baike.baidu.com/view/1080349.htm

Public Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long
http://baike.baidu.com/view/1079919.htm

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值