上一题下一题
跳转到
 
 
  世界如此多姿,发展如此迅速,窥一斑未必还能知全豹。但正如万花筒一样,每一个管窥都色彩斑斓。  
 
 
  知识通道 | 学习首页 | 教师首页 | PK首页 | 知识创造首页 | 企业首页 | 登录
 
本文对应知识领域
利用VB产生屏幕变暗的效果
作者:未知 申领版权
2010年11月14日 共有 1132 次访问 【添加到收藏夹】 【我要附加题目
受欢迎度:

    
    想利用VB编程实现屏幕变暗的效果(像关闭Win95时的效果),只要按下面的步骤来做:
    1.     在Form1中加入两个CommandButton和一个PictureBox.
    
    2.     在Form1的代码窗口中添加以下代码:
    Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
    End Type
    
    Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
    Private Declare Function CreatePatternBrush Lib "gdi32" (ByVal hBitmap As Long) As Long
    Private Declare Function PatBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal dwRop As Long) As Long
    Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long
    Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    Private Declare Function InvalidateRect Lib "user32" (ByVal hwnd As Long, ByVal lpRect As Long, ByVal bErase As Long) As Long
    Private bybits(1 To 16) As Byte
    Private hBitmap As Long, hBrush As Long
    Private hDesktopWnd As Long
    
    Private Sub Command1_Click()
    Dim rop As Long, res As Long
    Dim hdc5 As Long, width5 As Long, height5 As Long
    hdc5 = GetDC(0)
    width5 = Screen.Width \ Screen.TwipsPerPixelX
    height5 = Screen.Height \ Screen.TwipsPerPixelY
    rop = &HA000C9
    Call SelectObject(hdc5, hBrush)
    res = PatBlt(hdc5, 0, 0, width5, height5, rop)
    Call DeleteObject(hBrush)
    res = ReleaseDC(0, hdc5)
    End Sub
    
    Private Sub Command2_Click()
    Dim aa As Long
    aa = InvalidateRect(0, 0, 1)
    End Sub
    Private Sub Form_Load()
    Dim ary
    Dim i As Long
    ary = Array(&H55, &H0, &HAA, &H0, _
    &H55, &H0, &HAA, &H0, _
    &H55, &H0, &HAA, &H0, _
    &H55, &H0, &HAA, &H0)
    For i = 1 To 16
    bybits(i) = ary(i - 1)
    Next i
    hBitmap = CreateBitmap(8, 8, 1, 1, bybits(1))
    hBrush = CreatePatternBrush(hBitmap)
    Picture1.ForeColor = RGB(0, 0, 0)
    Picture1.BackColor = RGB(255, 255, 255)
    Picture1.ScaleMode = 3
    End Sub
    
    运行程序,按Command1就可以使屏幕暗下来,按Command2恢复。 
    

    

 

相关新闻

您可能对这些感兴趣  

用VB做定时断线程序
VisualBasic中的界面设计原则和编程技巧
VB6.0与Windows API 间的呼叫技巧
制作可以自动隐藏的弹出式菜单
ListBox中的字符串超长显示的解决方法
VB中的Unicode 和 Ansi 格式
优化程序显示速度
Visual Basic 产生渐层的 Form 背景
用VB实现客户——服务器(TCP/IP)
用VB制作注册软件的方法

题目筛选器
日期:
类型:
状态:
得分: <=
分类:
作者:
职业:
关键字:
搜索

 
 
 
  焦点事件
 
  知识体系
 
  职业列表
 
 
  最热文章
 
 
  最多引用文章
 
 
  最新文章
 
 
 
 
网站介绍 | 广告服务 | 招聘信息 | 保护隐私权 | 免责条款 | 法律顾问 | 意见反馈
版权所有 不得转载
沪ICP备 10203777 号 联系电话:021-54428255
  帮助提示    
《我的太学》是一种全新的应用,您在操作中遇到疑问或者问题,请拨打电话13564659895,15921448526。
《我的太学》