新聞| | PChome| 登入
2007-10-25 23:42:15 | 人氣45| 回應0 | 上一篇 | 下一篇
推薦 0 收藏 0 轉貼0 訂閱站台

如何將整個畫面暗下來,如同關機前一般

原始來源: cww 

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
'如果只要讓Picture1有效果將底下三行unMark取代 hdc5, width5, height5三個值
'hdc5 = Picture1.hdc
'width5 = Picture1.ScaleWidth
'height5 = Picture1.ScaleHeight

'底下三行設定整個螢幕都暗下來
hdc5 = GetDC(0)
width5 = Screen.Width \ Screen.TwipsPerPixelX
height5 = Screen.Height \ Screen.TwipsPerPixelY

rop = &HA000C9 '與原圖做and運算
Call SelectObject(hdc5, hBrush)
res = PatBlt(hdc5, 0, 0, width5, height5, rop)
Call DeleteObject(hBrush)
'如果只暗picture1則底下這一行要mark起來
res = ReleaseDC(0, hdc5)
End Sub
'回復原本的畫面
Private Sub Command2_Click()
Dim aa As Long
'如果只暗picture1則底下這一行要unMark起來
'Picture1.Refresh

'如果只暗picture1則底下這一行要mark起來
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

                                                        

台長: Kenny
人氣(45) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 教育學習(進修、留學、學術研究、教育概況) | 個人分類: 程式設計 |
此分類下一篇:VB中顯示動態GIF
此分類上一篇:製作圖形的Mask圖

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文