程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> Visual Basic語言 >> VB綜合教程 >> 利用VB產生屏幕變暗的效果

利用VB產生屏幕變暗的效果

編輯:VB綜合教程
想利用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恢復。

->

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved