制作屏保程序有現(xiàn)成的工具,別費勁了,又賣不出去,浪費生命
10年的蓬萊網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。成都營銷網(wǎng)站建設(shè)的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整蓬萊建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。創(chuàng)新互聯(lián)從事“蓬萊網(wǎng)站設(shè)計”,“蓬萊網(wǎng)站推廣”以來,每個客戶項目都認真落實執(zhí)行。
'這個拿去試一試,兩個時鐘,兩個圖片框,自己設(shè)定圖片框2的大小,比如讓它和窗體一樣大
'查一查PaintPicture的用法,就明白了
'去掉Picture2
Dim Pic_num As Long
Dim Pic_name() As String
Dim pic_star As Long
Dim p_width As Single
Dim p_height As Single
Dim bili_w As Single
Dim bili_h As Single
Dim v_mod As Long
Private Sub Form_Load()
Dim L_name As String
Pic_num = 0
ReDim Pic_name(Pic_num)
L_name = Dir(App.Path "\pic\*.JPG")
Do While L_name ""
ReDim Preserve Pic_name(Pic_num)
Pic_name(Pic_num) = L_name
Pic_num = Pic_num + 1
L_name = Dir
Loop
L_name = Dir(App.Path "\pic\*.BMP")
Do While L_name ""
ReDim Preserve Pic_name(Pic_num)
Pic_name(Pic_num) = L_name
Pic_num = Pic_num + 1
L_name = Dir
Loop
Picture1.AutoSize = True
Picture1.AutoRedraw = True
Picture1.Visible = False
' Me.AutoSize = False
Me.AutoRedraw = True
Me.Visible = True
Timer1.Interval = 10
Timer1.Enabled = False
Timer2.Interval = 50
Timer2.Enabled = False
If Pic_num 0 Then
Picture1.Picture = LoadPicture(App.Path "\pic\" Pic_name(0))
Me.PaintPicture Picture1.Picture, 0, 0, Me.ScaleWidth, Me.ScaleHeight, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight
Timer1.Enabled = True
Timer1.Interval = 2000
Else
MsgBox ("沒有圖片顯示!")
End If
End Sub
Private Sub Form_Resize()
Me.Width = Me.Width
Me.Height = Me.Width
Me.Top = 0
Me.Left = 0
End Sub
Private Sub Timer1_Timer()
Dim L_id As Long
Randomize
L_id = Int((Pic_num) * Rnd)
Picture1.Picture = LoadPicture(App.Path "\pic\" Pic_name(L_id))
bili_w = Picture1.ScaleWidth / Me.ScaleWidth
bili_h = Picture1.ScaleHeight / Me.ScaleHeight
p_width = Me.Width / 100
p_height = Me.Height / 100
pic_star = 0
Randomize
v_mod = Int(10 * Rnd)
'v_mod = 9'取消單引號并修改常數(shù)數(shù)可看單一效果
Timer1.Enabled = False
Timer2.Enabled = True
End Sub
Private Sub Timer2_Timer()
If pic_star 101 Then
pic_star = pic_star + 1
Select Case v_mod
Case 0
Me.PaintPicture Picture1.Picture, 0, 0, Me.Width, pic_star * p_height, 0, 0, Picture1.Width, bili_h * pic_star * p_height '從上向下
Case 1
Me.PaintPicture Picture1.Picture, 0, 0, pic_star * p_width, Me.Height, 0, 0, bili_w * pic_star * p_width, Picture1.Height '從左向右
Case 2
Me.PaintPicture Picture1.Picture, 0, 0, Me.Width, pic_star * p_height, 0, 0, Picture1.Width, Picture1.Height '壓縮的從上向下
Case 3
Me.PaintPicture Picture1.Picture, 0, 0, pic_star * p_width, Me.Height, 0, 0, Picture1.Width, Picture1.Height '壓縮的從左向右
Case 4
Me.PaintPicture Picture1.Picture, 0, 0, pic_star * p_width, pic_star * p_height, 0, 0, Picture1.Width, Picture1.Height '壓縮的從左上向右下
Case 5
Me.PaintPicture Picture1.Picture, Me.Width - pic_star * p_width, Me.Height - pic_star * p_height, pic_star * p_width, pic_star * p_height, 0, 0, Picture1.Width, Picture1.Height '壓縮的從右下向左上
Case 6
Me.PaintPicture Picture1.Picture, Me.Width / 2 - pic_star * p_width / 2, 0, pic_star * p_width / 2, Me.Height, 0, 0, Picture1.Width / 2, Picture1.Height '壓縮的從中向左
Me.PaintPicture Picture1.Picture, Me.Width / 2, 0, pic_star * p_width, Me.Height, Picture1.Width / 2, 0, Picture1.Width, Picture1.Height '壓縮的從中向右
Case 7
Me.PaintPicture Picture1.Picture, 0, Me.Height / 2 - pic_star * p_height / 2, Me.Width, pic_star * p_height / 2, 0, 0, Picture1.Width, Picture1.Height / 2 '壓縮的從中向上
Me.PaintPicture Picture1.Picture, 0, Me.Height / 2, Me.Width, pic_star * p_height, 0, Picture1.Height / 2, Picture1.Width, Picture1.Height '壓縮的從中向下
Case 8
Me.PaintPicture Picture1.Picture, Me.Width / 2 - pic_star * p_width / 2, Me.Height / 2 - pic_star * p_height / 2, pic_star * p_width / 2, pic_star * p_height / 2, 0, 0, Picture1.Width / 2, Picture1.Height / 2 '壓縮的從中向左上
Me.PaintPicture Picture1.Picture, Me.Width / 2, Me.Height / 2, pic_star * p_width, pic_star * p_height, Picture1.Width / 2, Picture1.Height / 2, Picture1.Width, Picture1.Height '壓縮的從中向右下
Me.PaintPicture Picture1.Picture, Me.Width / 2, Me.Height / 2 - pic_star * p_height / 2, pic_star * p_width / 2, pic_star * p_height / 2, Picture1.Width / 2, 0, Picture1.Width / 2, Picture1.Height / 2 '壓縮的從中向右上
Me.PaintPicture Picture1.Picture, Me.Width / 2 - pic_star * p_width / 2, Me.Height / 2, pic_star * p_width / 2, pic_star * p_height / 2, 0, Picture1.Height / 2, Picture1.Width / 2, Picture1.Height / 2 '壓縮的從中向左下
Case 9
For k = 0 To 9
Me.PaintPicture Picture1.Picture, 0, k * Me.Height / 10, Me.Width, 5 * pic_star * p_height / 10, 0, k * (Picture1.Height / 10), Picture1.Width, (Picture1.Height / 10) '水平百葉窗
Next
If pic_star = 21 Then
pic_star = 101
End If
End Select
Else
pic_star = 0
Timer1.Enabled = True
Me.PaintPicture Picture1.Picture, 0, 0, Me.ScaleWidth, Me.ScaleHeight, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight
Timer2.Enabled = False
End If
End Sub
'這回做了9個,應(yīng)該明白了吧,其實你第一回的5分也應(yīng)該給選我,估計是你沒明白用法
本實例的項目文件SCRNSAVE.MAK中包括兩個文件: SCRNSAVE.BAS、BLANK.FRM。這兩個文件的作用分別說明如下。
一、SCRNSAVE.BAS
此模塊文件包含四個子程序: HideMouse,ShowMouse,EndScrnsave,Main。前三個子程序分別用于隱藏鼠標(biāo)光標(biāo)、重新顯示鼠標(biāo)光標(biāo)和結(jié)束屏幕保護程序返回Windows。當(dāng)在Windows控制面板的桌面對話框中對屏幕保護程序進行“設(shè)置”時,Windows會傳給相應(yīng)的屏幕保護程序一個命令行參數(shù)Command$,此命令行參數(shù)含有“/c”開關(guān),要求屏幕保護程序提供自己的設(shè)置對話框。當(dāng)在桌面對話框中對屏幕保護程序進行“測試”或在設(shè)定的時間內(nèi)無鍵盤和鼠標(biāo)操作而激活屏幕保護程序時,Command$中含有“/s”開關(guān),要求屏幕保護程序立即開始運行。本文提供的屏幕保護程序?qū)嵗趩訒r首先執(zhí)行Main子程序,Main子程序通過檢查Command$來決定后續(xù)操作。若Command$中含有“/c”開關(guān),則利用MsgBox顯示簡單的提示信息, 說明本程序未提供任何設(shè)置選項;若Command$中含有“/s”開關(guān),則啟動一覆蓋全屏幕的黑色窗體BlankForm,并在此窗體上顯示動畫,進行正常的屏幕保護工作。
為了在程序啟動時首先執(zhí)行Main子程序,應(yīng)從VB的Options菜單中選擇“Project...”項,在Project Options對話框中把Start Up Form設(shè)置為“Sub Main”。
二、BLANK.FRM
此文件是屏幕保護程序的主體。它負責(zé)建立一個覆蓋全屏幕的黑色窗體BlankForm,并在此窗體上顯示動畫。它還負責(zé)監(jiān)視鍵盤和鼠標(biāo)事件,一旦有鍵盤或鼠標(biāo)動作,則立即結(jié)束屏幕保護程序的運行返回Windows。為了建立一個無邊框、無標(biāo)題條的覆蓋全屏幕的黑色窗體,需將BlankForm窗體屬性中的BorderStyle置為0-None,Caption置為空,ControlBox置為False,BackColor置為&H00000000&,并在Form_Load中利用Move 0,0,Screen.Width,Screen.Height將其放大為覆蓋整個屏幕。
本例顯示的動畫是根據(jù)《電腦愛好者》1995年第8期“動畫制作秘籍(一)”中的CIRCSHOW.BAS程序改編而成。動畫部分是屏幕保護程序中最精彩的部分。實際上,它也是讀者為了編寫自己的屏幕保護程序而唯一需要修改的部分,也是讀者的創(chuàng)意可以盡情發(fā)揮的部分。讀者可以充分發(fā)揮自己的想象力和創(chuàng)造力,編寫出精美動人的動畫。本例通過Form_KeyDown和Form_MouseMove來監(jiān)視鍵盤和鼠標(biāo)事件的發(fā)生。一旦有鍵盤輸入,則立即結(jié)束屏幕保護程序的運行,返回Windows。鼠標(biāo)則必須在移動了至少三個像素時方能結(jié)束屏幕保護程序的運行,這樣可避免因敲工作臺等偶然的事件而使屏幕保護程序的運行中斷。
在建立了以上兩個文件后,將其加到項目文件SCRNSAVE.MAK中,生成EXE文件。在生成EXE文件時, 應(yīng)注意如下兩點:
1.在Make EXE File對話框的“Application Title”域中應(yīng)填寫一個特殊的名字。這個名字必須以“SCRNSAVE”打頭,隨后是你要在控制面板的屏幕保護程序清單中顯示的名字。例如, 本例所用標(biāo)題為“SCRNSAVE VB Screen Saver”。
2.生成的EXE文件的擴展名必須為SCR而不能是EXE。本例所取EXE文件名為SSVB.SCR(按照慣例所有的屏幕保護程序的名字都以SS打頭)。讀者所要做的最后一件事是將SSVB.SCR拷到自己的Windows目錄下, 這樣Windows才能找到它, 并在控制面板的屏幕保護程序清單中顯示出來。本文實例在PWIN 3.2、VB 3.0環(huán)境下調(diào)試通過。
清單1: SCRNSAVE.BAS
Declare Function ShowCursor Lib 〃USER〃 (ByVal fShow As Integer) As Integer
Sub EndScrnsave ()
ShowMouse ′使鼠標(biāo)重新可見
End ′然后退出屏幕保護程序
End Sub
Sub ShowMouse ()
′這個子程序使鼠標(biāo)箭頭重新出現(xiàn)在屏幕上
While ShowCursor(True) 0
Wend
End Sub
Sub HideMouse ()
′這個子程序把屏幕上的鼠標(biāo)箭頭隱蔽起來
While ShowCursor(False) = 0
Wend
End Sub
Sub Main ()
′只允許屏幕保護程序的一個實例運行
If App.PrevInstance=True Then
Exit Sub
End If
′檢查一下應(yīng)該空屏還是顯示設(shè)置對話框
If InStr(Command$, 〃/c〃) Then
MsgBox 〃No setup options for this screen saver〃 ′顯示設(shè)置對話框
ElseIf InStr(Command$, 〃/s〃) Then
BlankForm.Show ′開始運行屏幕保護程序
End If
′等到?jīng)]有要顯示的窗體時就退出
While DoEvents() 0
Wend
End Sub
清單2: BLANK.FRM
(1)窗體和控制屬性
對象 屬性設(shè)置
FormBackColor &H00000000&
BorderStyle 0-None
Caption
ControlBox False
Name BlankForm
ScaleMode3-PixelTimerInterval1NameTick
(2)窗體程序
Dim r, f, p, X0, Y0
Dim lastX, lastY
Const pi = 3.14159
Sub Form_Load ()
Move 0, 0, Screen.Width, Screen.Height ′將窗體放大到覆蓋全屏幕
HideMouse
r = 50
p = 0
f = 0
X0 = ScaleWidth / 2 - 1
Y0 = ScaleHeight / 2 - 1
End Sub
Sub Form_KeyDown (KeyCode As Integer, Shift As Integer)
EndScrnsave ′結(jié)束屏幕保護程序的運行
End Sub
Sub Form_MouseMove (Button As Integer, Shift As Integer,
X As Single, Y As Single)
If IsEmpty(lastX) Or IsEmpty(lastY) Then
lastX = X
lastY = Y
End If
′僅當(dāng)鼠標(biāo)移動足夠迅速(一次2個象素以上)才恢復(fù)屏幕
If Abs(lastX - X) 2 Or Abs(lastY - Y) 2 Then
EndScrnsave ′結(jié)束屏幕保護程序
End If
lastX = X
lastY = Y ′記住最后的位置
End Sub
Sub Tick_Timer ()
Dim X As Single
Dim Y As Single
If f = 0 Then
c = RGB(255 * Rnd, 255 * Rnd, 255 * Rnd)
X = r * Cos(2 * pi * p / 360) + X0
Y = r * Sin(2 * pi * p / 360) + Y0
Line (X0, Y0)-(X, Y), c
Circle (X, Y), 2, c
If r = 200 Then
f = 1
Exit Sub
End If
r = r + 1 / 2
p = p + 7
ElseIf f = 1 Then
c = RGB(0, 0, 0)
X = r * Cos(2 * pi * p / 360) + X0
Y = r * Sin(2 * pi * p / 360) + Y0
Line (X0, Y0)-(X, Y), c
Circle (X, Y), 2, c
If r = 50 Then
f = 0
Exit Sub
End If
r = r - 1 / 2
p = p - 7
End If
End Sub
系統(tǒng)就有這個屏保啊!~!
Option EXPlicit
Dim quitflag As Boolean '聲明終止程序標(biāo)志變量
Dim lleft
'聲明隱藏或顯示鼠標(biāo)的API函數(shù)
Private Declare Function ShowCursor Lib "user32"
(ByVal bShow As Long) As Long
'檢測鼠標(biāo)單擊或移動
Private Sub Form_Click()
quitflag = True
End Sub
Private Sub Form_MouseMove(Button As Integer,Shift As Integer, X As Single, Y As Single)
Static xlast, ylast
Dim xnow As Single
Dim ynow As Single
xnow = X
ynow = Y
If xlast = 0 And ylast = 0 Then
xlast = xnow
ylast = ynow
Exit Sub
End If
If xnow xlast Or ynow ylast Then
quitflag = True
End If
End Sub
'檢測按鍵
Private Sub Form_KeyDown(KeyCode As Integer,Shift As Integer)
quitflag = True
End Sub
Private Sub Form_Load()
Dim X As Long
lleft = 0
'橫向滾動文字的起始X坐標(biāo)
If App.PrevInstance = True Then
'用APP對象的PrevInstance屬性
Unload Me
'防止同時運行屏幕保護程序的兩個實例
Exit Sub
End If
Select Case Ucase$(Left$(Command$, 2))
'裝載命令行參數(shù)
Case "/S" '在顯示器屬性對話框中單擊了
預(yù)覽按鈕或屏幕保護程序被系統(tǒng)正常調(diào)用。
Show
'全屏顯示Form1窗體
Randomize
'初始化隨機數(shù)生成器
X = ShowCursor(False)
'隱藏鼠標(biāo)
BackColor = VBBlack
Do
Timer2.Enabled = True
'啟動Timer2 ,顯示屏幕保護滾動文字
DoEvents
'轉(zhuǎn)讓控制權(quán),以便檢測鼠標(biāo)和按鍵行為
Loop Until quitflag = True
'運行屏幕保護滾動文字直至有鼠標(biāo)和按鍵行為
Timer2.Enabled = False
'終止?jié)L動文字
Timer1.Enabled = True
'啟動Timer1,退出屏幕保護程序
Case Else
Unload Me
Exit Sub
End Select
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim X
X = ShowCursor(True)
'顯示鼠標(biāo)
End Sub
Private Sub Timer1_Timer()
Unload Me
'退出屏幕保護程序
End Sub
Private Sub Timer2_Timer()
顯示橫向滾動文字
lleft = lleft + 100
If lleft = 11810 Then
lleft = 0
Lab1.Top = Int(Rnd * 7000)
End If
Lab1.Left = lleft
Timer2.Enabled = False
End Sub
思路:
利用幾個可以作為容器的控件,添加滾動條就可以了:
我舉個例子:(這個問題我記得回答過的?。?/p>
添加1個PicTureBox1,作為容器
在PicTureBox1里添加PicTureBox2,在窗體上添加一個垂直滾動條。
把你所謂的許多控件放到PicTureBox2里,滾動條改變的是PicTureBox2在PicTureBox1里的Top屬性,我想你通過一定的空間想象力,可以想到效果了吧?
注意:默認狀態(tài)設(shè)置PicTureBox2的Top屬性為0,當(dāng)該屬性為負值的時候,PicTureBox2顯示的效果是向上移動,即下面原來隱藏的內(nèi)容為可見了。
要設(shè)置PicTureBox2的AutoRedraw 屬性為True。
若要左右移動效果,那么改變其 Left 屬性,原理不再贅述了。
在窗體上建立2個文本框text1和text2,一個按鈕command1,text1里面輸入你要轉(zhuǎn)換的字符串,text2里面顯示結(jié)果,代碼如下:
Dim MyString As String
Dim EveryStr(50) As String
Dim TargetStr As String
Private Sub Command1_Click()
MyString = Text1
For i = 1 To Len(MyString)
EveryStr(i) = Right(Left(MyString, i), 1)
If Asc(EveryStr(i)) 123 And Asc(EveryStr(i)) 96 Then EveryStr(i) = \"_\"
If Asc(EveryStr(i)) 91 And Asc(EveryStr(i)) 64 Then EveryStr(i) = \"_\"
TargetStr = TargetStr EveryStr(i)
Next i
Text2 = TargetStr
TargetStr = \"\"
End Sub
引號前面怎么自動給加了個“\”?用的時候請手動把那幾個“\”去掉