主题:[原创]【VB+API】屏保程序完整源码
Option Explicit
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOZORDER = &H8
Dim pic() As String
Public num, idme, sec, secl As Integer
Public str As String
Private Sub Command2_Click()
Me.Line (0, 0)-(50, 50)
End Sub
Function boxdraw(ByVal X As Integer, ByVal Y As Integer, ByVal chang As Long, ByVal kuan As Long, Optional ByVal color As Integer)
Dim fh, fw As Single
fh = Form1.Height: fw = Form1.Width
Form1.Scale (-1 * Int(fw / 2), Int(fh / 2))-(Int(fw / 2), -1 * Int(fh / 2))
If color = 0 Then color = vbBlack
Form1.Line (X, Y)-(X + chang, Y - kuan), color, B
End Function
Private Sub Command3_Click()
Call boxdraw(0, 0, 200, 200)
End Sub
Private Sub Command4_Click()
End
End Sub
Private Sub Form_Activate()
str = Dir(App.Path & "\")
Do While str <> ""
If str = App.EXEName & ".exe" Then
ElseIf kzm(str) = "bmp" Or kzm(str) = "jpeg" Or kzm(str) = "jpg" Or kzm(str) = "gif" Or kzm(str) = "png" Or kzm(str) = "tif" Then
num = num + 1
ReDim Preserve pic(num)
pic(num) = App.Path & "\" & str
End If
str = Dir
Loop
Timer1.Enabled = True
Timer1.Interval = 1000
End Sub
Private Sub Form_Click()
Timer1.Enabled = False
Dim interv
interv = InputBox("请输入间隔秒(s),小于等于零结束屏保")
If Val(interv) = 0 Or Val(interv) < 0 Then End
secl = Val(interv)
Timer1.Enabled = True
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 27 Then End
End Sub
Private Sub Form_Load()
SetWindowPos Form1.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOZORDER + SWP_NOMOVE + SWP_NOSIZE
Form1.Top = 0
Form1.Left = 0
Form1.Width = Screen.Width
Form1.Height = Screen.Height
'Image1.Top = 0
'Image1.Left = 0
'Image1.Width = Screen.Width
'Image1.Height = Screen.Height
Me.BackColor = vbBlack
secl = 3
sec = 3
End Sub
Private Sub Image1_Click()
Timer1.Enabled = False
Dim interv
interv = InputBox("请输入间隔秒(s),小于等于零结束屏保")
If Val(interv) = 0 Or Val(interv) < 0 Then End
secl = Val(interv)
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
On Error Resume Next
sec = sec + 1
If sec > secl Then
'屏蔽区begin
idme = idme + 1
If num = 0 Then Timer1.Enabled = False: End
If idme > num Then idme = 1
Image1.Visible = False
Image1.Stretch = False
Image1.Picture = LoadPicture(pic(idme))
'根据图片大小进行调整
If Image1.Height > Screen.Height Or Image1.Width > Screen.Width Then
Image1.Stretch = True
Image1.Top = 0
Image1.Left = 0
Image1.Width = Screen.Width
Image1.Height = Screen.Height
Else
Image1.Stretch = False
Image1.Top = Int((Screen.Height - Image1.Height) / 2)
Image1.Left = Int((Screen.Width - Image1.Width) / 2)
End If
'屏蔽区end
Image1.Visible = True
sec = 1
Else
End If
End Sub
Function kzm(ByVal pathme As String)
Dim qq As String
Dim qs As Long
qs = InStrRev(pathme, ".")
qq = Mid(pathme, qs + 1)
kzm = qq
End Function
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOZORDER = &H8
Dim pic() As String
Public num, idme, sec, secl As Integer
Public str As String
Private Sub Command2_Click()
Me.Line (0, 0)-(50, 50)
End Sub
Function boxdraw(ByVal X As Integer, ByVal Y As Integer, ByVal chang As Long, ByVal kuan As Long, Optional ByVal color As Integer)
Dim fh, fw As Single
fh = Form1.Height: fw = Form1.Width
Form1.Scale (-1 * Int(fw / 2), Int(fh / 2))-(Int(fw / 2), -1 * Int(fh / 2))
If color = 0 Then color = vbBlack
Form1.Line (X, Y)-(X + chang, Y - kuan), color, B
End Function
Private Sub Command3_Click()
Call boxdraw(0, 0, 200, 200)
End Sub
Private Sub Command4_Click()
End
End Sub
Private Sub Form_Activate()
str = Dir(App.Path & "\")
Do While str <> ""
If str = App.EXEName & ".exe" Then
ElseIf kzm(str) = "bmp" Or kzm(str) = "jpeg" Or kzm(str) = "jpg" Or kzm(str) = "gif" Or kzm(str) = "png" Or kzm(str) = "tif" Then
num = num + 1
ReDim Preserve pic(num)
pic(num) = App.Path & "\" & str
End If
str = Dir
Loop
Timer1.Enabled = True
Timer1.Interval = 1000
End Sub
Private Sub Form_Click()
Timer1.Enabled = False
Dim interv
interv = InputBox("请输入间隔秒(s),小于等于零结束屏保")
If Val(interv) = 0 Or Val(interv) < 0 Then End
secl = Val(interv)
Timer1.Enabled = True
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 27 Then End
End Sub
Private Sub Form_Load()
SetWindowPos Form1.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOZORDER + SWP_NOMOVE + SWP_NOSIZE
Form1.Top = 0
Form1.Left = 0
Form1.Width = Screen.Width
Form1.Height = Screen.Height
'Image1.Top = 0
'Image1.Left = 0
'Image1.Width = Screen.Width
'Image1.Height = Screen.Height
Me.BackColor = vbBlack
secl = 3
sec = 3
End Sub
Private Sub Image1_Click()
Timer1.Enabled = False
Dim interv
interv = InputBox("请输入间隔秒(s),小于等于零结束屏保")
If Val(interv) = 0 Or Val(interv) < 0 Then End
secl = Val(interv)
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
On Error Resume Next
sec = sec + 1
If sec > secl Then
'屏蔽区begin
idme = idme + 1
If num = 0 Then Timer1.Enabled = False: End
If idme > num Then idme = 1
Image1.Visible = False
Image1.Stretch = False
Image1.Picture = LoadPicture(pic(idme))
'根据图片大小进行调整
If Image1.Height > Screen.Height Or Image1.Width > Screen.Width Then
Image1.Stretch = True
Image1.Top = 0
Image1.Left = 0
Image1.Width = Screen.Width
Image1.Height = Screen.Height
Else
Image1.Stretch = False
Image1.Top = Int((Screen.Height - Image1.Height) / 2)
Image1.Left = Int((Screen.Width - Image1.Width) / 2)
End If
'屏蔽区end
Image1.Visible = True
sec = 1
Else
End If
End Sub
Function kzm(ByVal pathme As String)
Dim qq As String
Dim qs As Long
qs = InStrRev(pathme, ".")
qq = Mid(pathme, qs + 1)
kzm = qq
End Function