游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1233|回复: 1

溶化效果

 关闭 [复制链接]

187

主题

6490

帖子

6491

积分

论坛元老

团长

Rank: 8Rank: 8

积分
6491
发表于 2006-9-17 12:49:00 | 显示全部楼层 |阅读模式
Option Explicit
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source

Dim x As Integer, y As Integer
Dim Buffer As Long, hBitmap As Long, Desktop As Long, hScreen As Long, ScreenBuffer As Long

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyEscape Then
Unload Me
End If
End Sub

Private Sub Form_Load()
'To get the device context for the desktop(whole screen)
Desktop = GetWindowDC(GetDesktopWindow())

'to create a device context compatible with a known device context
'and assign it to a long variable
hBitmap = CreateCompatibleDC(Desktop)
hScreen = CreateCompatibleDC(Desktop)

'to create bitmaps in memory for temporary storage compatible with a known bitmap
Buffer = CreateCompatibleBitmap(Desktop, 32, 32)
ScreenBuffer = CreateCompatibleBitmap(Desktop, Screen.Width / 15, Screen.Height / 15)

'assign device contexts to the bitmaps
SelectObject hBitmap, Buffer
SelectObject hScreen, ScreenBuffer

'save the screen for later restoration
BitBlt hScreen, 0, 0, Screen.Width / 15, Screen.Height / 15, Desktop, 0, 0, SRCCOPY
End Sub


Private Sub Form_Unload(Cancel As Integer)
'restores the desktop to the saved picture when program ends
'try to comment out following line and see
BitBlt Desktop, 0, 0, Screen.Width / 15, Screen.Height / 15, hScreen, 0, 0, SRCCOPY

End Sub

Private Sub tmr1_Timer()
y = (Screen.Height / 15) * Rnd
x = (Screen.Width / 15) * Rnd

'copy 32x32 portion of screen into buffer at x,y
BitBlt hBitmap, 0, 0, 32, 32, Desktop, x, y, SRCCOPY

'paste back slightly shifting the values for x and y
BitBlt Desktop, x + (3 - 6 * Rnd), y + (2 - 4 * Rnd), 32, 32, hBitmap, 0, 0, SRCCOPY

End Sub

187

主题

6490

帖子

6491

积分

论坛元老

团长

Rank: 8Rank: 8

积分
6491
 楼主| 发表于 2006-9-17 12:50:00 | 显示全部楼层

Re:溶化效果

用之前麻烦在窗体上添加一个Timer,并改名为tmr1。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-25 11:32

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表