标题:[求助]谁可以给我解释以下原代码?
只看楼主
limaowin
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2005-3-24
 问题点数:0 回复次数:4 
[求助]谁可以给我解释以下原代码?

Private Sub ButtonPicture1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)

If MousePress Then Exit Sub

StopSounds

ButtonPicture1(Index).Picture = DownImage.Picture

lblStatus.Caption = "Mouse Down"

PlayWav MousePressMCI

MousePress = True

End Sub

Private Sub ButtonPicture1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)

If MouseOver Then Exit Sub

StopSounds

ButtonPicture1(Index).Picture = OverImage.Picture

lblStatus.Caption = "Mouse Over - Button"

PlayWav MouseOverMCI

NewIndex = Index

MouseOver = True

End Sub

Private Sub ButtonPicture1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)

If Not MousePress Then Exit Sub

StopSounds

PlayWav MouseUpMCI

ButtonPicture1(Index).Picture = UpImage.Picture

lblStatus.Caption = "Mouse Up"

MousePress = False

End Sub

Private Sub Form_Load()

Dim str1 As String

str1 = Space$(255)

MouseOverSound = "boink.wav"

MousePressSound = "bleeb.wav"

MouseUpSound = "type.wav"

''Load the sounds

LoadSound MouseOverSound, MouseOverMCI

LoadSound MousePressSound, MousePressMCI

LoadSound MouseUpSound, MouseUpMCI

Debug.Print mciSendString("PLAY WAVEUP11 FROM 0", str1, 0, 0)

Dim i As Integer

lblStatus.Caption = "Ready?"

For i = ButtonPicture1.LBound To ButtonPicture1.UBound

ButtonPicture1(i).Picture = UpImage.Picture

Next i

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Not MouseOver Then Exit Sub

StopSounds

lblStatus.Caption = "Mouse Over - Form"

MouseOver = False

MousePress = False

ButtonPicture1(NewIndex).Picture = UpImage.Picture

End Sub

Private Sub Form_Unload(Cancel As Integer)

'This shouldn't be needed but it

'can't hurt to stop the sound

StopSounds

'Unload the form and remove any references

Unload Me

Set Form1 = Nothing

End Sub

Public Function PlayWav(Alias As String)

Dim rt As Long, ErrorString As String

'Play the sound

rt = mciSendString("PLAY " & Alias & " FROM 0", 0&, 0, 0)

If rt <> 0 Then

ErrorString = Space$(255)

mciGetErrorString rt, ErrorString, Len(ErrorString)

MsgBox "Error: " & ErrorString

End If

End Function

Private Sub LoadSound(Filename As String, Alias As String)

Dim CommandString As String, ErrorString As String

Dim ShortPathName As String

Dim AppPath As String

Dim rt As Long

''Get the path name

AppPath = App.Path

If Right$(AppPath, 1) <> "\" Then

AppPath = AppPath & "\"

End If

''Allocate space for short path name

ShortPathName = Space$(255)

''Get the short path name since MCI only accepts those

GetShortPathName AppPath, ShortPathName, Len(ShortPathName)

''Remove empty spaces and the trailing NULL character

ShortPathName = Left$(ShortPathName, Len(Trim$(ShortPathName)) - 1)

'Build the command string

CommandString = "OPEN " & ShortPathName & Filename & " TYPE WAVEAUDIO ALIAS " & Alias

'Open the sound

rt = mciSendString(CommandString, 0&, 0, 0)

If rt <> 0 Then ''Non 0 = error

ErrorString = Space$(255)

mciGetErrorString rt, ErrorString, Len(ErrorString)

MsgBox "Error: " & ErrorString

End If

End Sub

Private Sub StopSounds()

mciSendString "STOP " & MouseOverMCI, 0&, 0, 0

mciSendString "STOP " & MouseUpMCI, 0&, 0, 0

mciSendString "STOP " & MousePressMCI, 0&, 0, 0

End Sub

搜索更多相关主题的帖子: 代码 解释 
2005-03-24 13:20
griefforyou
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:3336
专家分:0
注 册:2004-4-15
得分:0 
有哪里不懂的呀?不是很简单吗?

天津网站建设 http://www./
2005-03-24 14:06
limaowin
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2005-3-24
得分:0 
我是初学者,我现在想遍一个很酷的按纽,(鼠标不放去是一个颜色,放上去是一个颜色,单击它又是一个颜色,单击它的同时还要运行一段程序)
我现在连怎么语句都不动,不知道该什么办

我是新来的,希望和大家多多交流! 我的QQ:404108102 E-mail:limaowin1@
2005-03-25 12:00
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
得分:0 
可以在Button的MouseMove事件来改变颜色,比如一个按钮的名称是Command1。

Private Sub Command1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
       '这个是按钮的MouseMove事件
       Command1.Background=red
      '这里的red是颜色值可以换成RGB或其它颜色值。

End Sub
Private Sub Command1_Click()
     '这个是按钮的点击事件
       Shell "D:\xxx.exe"
       '这里D:\xxx.exe是你要运行的应用程序的路径。
End Sub
2005-03-25 14:14
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
得分:0 
补充一点 Private Sub Command1_Click() '这个是按钮的点击事件 Command1.Background=Blue '这里的Blue是颜色值可以换成RGB或其它颜色值。 Shell "D:\xxx.exe" '这里D:\xxx.exe是你要运行的应用程序的路径。 End Sub
在按钮单击事件中加入改变按钮颜色属性的代码就可以变色。
2005-03-25 14:17



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-13938-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.074807 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved