龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VB开发 >

利用VB产生屏幕变暗的效果

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
想利用VB编程实现屏幕变暗的效果(像关闭Win95时的效果),只要按下面的步骤来做: 1.在Form1中加入两个CommandButton和一个PictureBox. 2.在Form1的代码窗口中添加以下代码: PrivateTypeRECT Lef
想利用VB编程实现屏幕变暗的效果(像关闭Win95时的效果),只要按下面的步骤来做:

1.在Form1中加入两个CommandButton和一个PictureBox.

2.在Form1的代码窗口中添加以下代码:
  PrivateTypeRECT
  LeftAsLong
  TopAsLong
  RightAsLong
  BottomAsLong
  EndType

PrivateDeclareFunctionGetDCLib"user32"(ByValhwndAsLong)AsLong
  PrivateDeclareFunctionReleaseDCLib"user32"(ByValhwndAsLong,ByValhdcAsLong)AsLong
  PrivateDeclareFunctionCreatePatternBrushLib"gdi32"(ByValhBitmapAsLong)AsLong
  PrivateDeclareFunctionPatBltLib"gdi32"(ByValhdcAsLong,ByValxAsLong,ByValyAsLong,ByValnWidthAsLong,ByValnHeightAsLong,ByValdwRopAsLong)AsLong
  PrivateDeclareFunctionDeleteObjectLib"gdi32"(ByValhObjectAsLong)AsLong
  PrivateDeclareFunctionCreateBitmapLib"gdi32"(ByValnWidthAsLong,ByValnHeightAsLong,ByValnPlanesAsLong,ByValnBitCountAsLong,lpBitsAsAny)AsLong
  PrivateDeclareFunctionSelectObjectLib"gdi32"(ByValhdcAsLong,ByValhObjectAsLong)AsLong
  PrivateDeclareFunctionInvalidateRectLib"user32"(ByValhwndAsLong,ByVallpRectAsLong,ByValbEraseAsLong)AsLong
  Privatebybits(1To16)AsByte
  PrivatehBitmapAsLong,hBrushAsLong
  PrivatehDesktopWndAsLong

PrivateSubCommand1_Click()
  DimropAsLong,resAsLong
  Dimhdc5AsLong,width5AsLong,height5AsLong
  hdc5=GetDC(0)
  width5=Screen.WidthScreen.TwipsPerPixelX
  height5=Screen.HeightScreen.TwipsPerPixelY
  rop=&HA000C9
  CallSelectObject(hdc5,hBrush)
  res=PatBlt(hdc5,0,0,width5,height5,rop)
  CallDeleteObject(hBrush)
  res=ReleaseDC(0,hdc5)
  EndSub

PrivateSubCommand2_Click()
  DimaaAsLong
  aa=InvalidateRect(0,0,1)
  EndSub
  PrivateSubForm_Load()
  Dimary
  DimiAsLong
  ary=Array(&H55,&H0,&HAA,&H0,_
  &H55,&H0,&HAA,&H0,_
  &H55,&H0,&HAA,&H0,_
  &H55,&H0,&HAA,&H0)
  Fori=1To16
  bybits(i)=ary(i-1)
  Nexti
  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
  EndSub

运行程序,按Command1就可以使屏幕暗下来,按Command2恢复。

->

精彩图集

赞助商链接