SWF to EXE 工具制作

来源:百度文库 编辑:神马文学网 时间:2024/07/03 12:36:02
 SWF to EXE 工具制作
最近要做一个电子书,利用的是FlashPaper将Word文件转换为SWF格式文件,因为需要在光盘上自动运行,所以在网上寻找Swf 转 Exe文件的工具,找到JerkFlashV2,试了一下,才发现该工具转换成的EXE文件是基于Flash Player 6.0的,有许多Flash Palery的新功能无法使用,找了一下其它的工具,均为基于6.0版本的,无奈,只好动手自己编写一个。:)
 点此下载EXE文件
参照《FLASH工具的秘密》所说的方法,用VB6编写了一个,改掉了该方法中处理速度慢的问题,并能够在没有COMDLG32.OCX(该控件为VS6中用来显示各种对话框的,如打开文件、保存文件、显示打印机设置等)的计算机上运行。工作摘要如下:
1、准备最新版本的Flash Player,我用的是8.0(文件名为SAFlashPlayer.exe),9.0的我还没用到
2、用VB6新建一个EXE项目,将SAFlashPlayer.exe添加为该工程的资源文件,在此,我使用了其默认属性:
类型:CUSTOM
编号:101
语言:中文(中国)
3、新建一窗体,如下所示:

3、该窗体代码如下,基本上类似于《FLASH工具的秘密——SWF2EXE》一文所说,但作了一些改动,并优化了一些部分:
Private Sub Command1_Click()
Dim strFile As String
strFile = ShowOpenFileDialog(Me, "动画文件(*.swf)|*.swf|所有文件(*.*)|*.*", "")
If strFile <> "" Then
Text1.Text = strFile
End If
End Sub
Private Sub Command2_Click()
If Trim(Text1.Text) <> "" Then Text2.Text = Left(Text1.Text, InStr(1, Text1.Text, ".")) & "exe"
Dim strFile As String
strFile = ShowSaveFileDialog(Me, "EXE文件(*.exe)|*.exe", "")
If strFile <> "" Then
Text2.Text = strFile
End If
End Sub
Private Sub Command3_Click()
‘暂时Disable掉按钮
Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
Dim exetog As Long      ‘定义EXE形式标识符
Dim filelong As Long
Dim copy() As Byte
copy = LoadResData(101, "CUSTOM") ‘将资源文件存放在copy()中
Open Text1.Text For Binary As #1 ‘打开待转换的SWF文件
Open Text2.Text For Binary As #2 ‘创建将生成的EXE文件
‘将播放器以二进制形式写入到中的内容写入文件2中
Put #2, , copy
‘将SWF文件写入到文件2中
filelong = LOF(1)
ReDim copy(filelong - 1) As Byte
Get #1, , copy
Put #2, , copy
‘写入EXE形式文件标识符
filelong = LOF(2)
exetog = 1193046 ‘1193046是EXE形式的标识符(56 34 12 FA)中的前三个字节56 34 12的十进制值
Put #2, , exetog
Seek #2, filelong + 4 ‘调整文件指针到filelong+4字节处
exetog = 250 ‘250是EXE形式的标识符的最后一个字节FA的十进制值
Put #2, , exetog
Seek #2, filelong + 5 ‘调整文件指针到filelong+5字节处
‘写入SWF文件长度
filelong = LOF(1)
Put #2, , filelong
Close #1
Close #2
MsgBox "转换完毕!"
Command1.Enabled = True
Command2.Enabled = True
Command3.Enabled = True
End Sub
另外,为了能够在没有COMDLG32.OCX的计算机上运行,该程序没有使用CommonDialog控件,而采用API方式,为此建立了一个模块General,内容如下:Public Const OFN_ALLOWMULTISELECT = &H200
Public Const OFN_CREATEPROMPT = &H2000
Public Const OFN_ENABLEHOOK = &H20
Public Const OFN_ENABLETEMPLATE = &H40
Public Const OFN_ENABLETEMPLATEHANDLE = &H80
Public Const OFN_EXPLORER = &H80000
Public Const OFN_EXTENSIONDIFFERENT = &H400
Public Const OFN_FILEMUSTEXIST = &H1000
Public Const OFN_HIDEREADONLY = &H4
Public Const OFN_LONGNAMES = &H200000
Public Const OFN_NOCHANGEDIR = &H8
Public Const OFN_NODEREFERENCELINKS = &H100000
Public Const OFN_NOLONGNAMES = &H40000
Public Const OFN_NONETWORKBUTTON = &H20000
Public Const OFN_NOREADONLYRETURN = &H8000
Public Const OFN_NOTESTFILECREATE = &H10000
Public Const OFN_NOVALIDATE = &H100
Public Const OFN_OVERWRITEPROMPT = &H2
Public Const OFN_PATHMUSTEXIST = &H800
Public Const OFN_READONLY = &H1
Public Const OFN_SHAREAWARE = &H4000
Public Const OFN_SHAREFALLTHROUGH = 2
Public Const OFN_SHAREWARN = 0
Public Const OFN_SHARENOWARN = 1
Public Const OFN_SHOWHELP = &H10
Public Const OFS_MAXPATHNAME = 256
Public Const LF_FACESIZE = 32
‘OFS_FILE_OPEN_FLAGS   and   OFS_FILE_SAVE_FLAGS   below
‘are   mine   to   save   long   statements;   they‘re   not
‘a   standard   Win32   type.
Public Const OFS_FILE_OPEN_FLAGS = OFN_EXPLORER Or OFN_LONGNAMES Or OFN_CREATEPROMPT Or OFN_NODEREFERENCELINKS Or OFN_HIDEREADONLY Or OFN_ALLOWMULTISELECT
Public Const OFS_FILE_SAVE_FLAGS = OFN_EXPLORER Or OFN_LONGNAMES Or OFN_OVERWRITEPROMPT Or OFN_HIDEREADONLY
Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Declare Function GetSaveFileName Lib "comdlg32.dll" Alias _
"GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Public Function ShowOpenFileDialog(Form As Form, Filter As String, Optional OldFileName As String = "") As String
Dim ofn As OPENFILENAME
Dim rtn As Long
ofn.hwndOwner = Form.hWnd
ofn.hInstance = App.hInstance
ofn.lpstrFilter = Replace(Filter, "|", Chr(0))
ofn.lpstrFile = Space(2047)
ofn.nMaxFile = Len(ofn.lpstrFile) + 1
ofn.lpstrFileTitle = Space(510)
ofn.nMaxFileTitle = Len(ofn.lpstrFileTitle) + 1
ofn.lpstrInitialDir = App.Path
ofn.lpstrTitle = "打开文件"
ofn.flags = OFS_FILE_OPEN_FLAGS
ofn.lStructSize = Len(ofn)
rtn = GetOpenFileName(ofn)
If rtn >= 1 Then
Dim il As Integer
il = InStr(1, ofn.lpstrFile, Chr(0))
If il <= 0 Then il = Len(ofn.lpstrFile)
ShowOpenFileDialog = Left(ofn.lpstrFile, il)
Else
ShowOpenFileDialog = OldFileName
End If
End Function
Public Function ShowSaveFileDialog(Form As Form, Filter As String, Optional OldFileName As String = "") As String
Dim ofn As OPENFILENAME
Dim rtn As Long
ofn.hwndOwner = Form.hWnd
ofn.hInstance = App.hInstance
ofn.lpstrFilter = Replace(Filter, "|", Chr(0))
ofn.lpstrFile = Space(2047)
ofn.nMaxFile = Len(ofn.lpstrFile) + 1
ofn.lpstrFileTitle = Space(510)
ofn.nMaxFileTitle = Len(ofn.lpstrFileTitle) + 1
ofn.lpstrInitialDir = App.Path
ofn.lpstrTitle = "打开文件"
ofn.lpstrDefExt = ""
ofn.flags = OFS_FILE_SAVE_FLAGS
ofn.lStructSize = Len(ofn)
rtn = GetSaveFileName(ofn)
If rtn >= 1 Then
Dim il As Integer
il = InStr(1, ofn.lpstrFile, Chr(0))
If il <= 0 Then il = Len(ofn.lpstrFile)
ShowSaveFileDialog = Left(ofn.lpstrFile, il)
Else
ShowSaveFileDialog = OldFileName
End If
End Function