Code : Tout sélectionner
#Window1 = 1
#W1Btn1 = 1
#W1Btn2 = 2
#W1Text1 = 3
#W1Option1 = 4
#W1Option2 = 5
#W1Check1 = 6
#MV_Checked = 1
#MV_RunWait =1
#MV_RunInvisible = 2
#MV_CreateDll = " /DLL"
#MV_createAsm = " /COMMENTED"
#Window1Flags = #PB_Window_ScreenCentered | #PB_Window_SystemMenu
;- Variables definition
DefType.s SourceFileName, DestFileName, CompilFlag, CompilerPath, Compiler, Parameter
DefType.l RunOption
;-Program Start
;Check Program Parameter the Source File
SourceFileName = ProgramParameter()
If SourceFileName = "" ;If not running as PB Tool request Pb File
SourceFileName = OpenFileRequester("PBasic Source File", "", "PBasic file |*.pb", 0 )
If SourceFileName = ""
MessageRequester("Compiler", "Source non trouvée !", #PB_MessageRequester_Ok | #MB_ICONINFORMATION)
End
EndIf
EndIf
If OpenWindow( #Window1, 0,0,390,137, #Window1Flags,"Compiler le fichier...")
If CreateGadgetList(WindowID(1))
ButtonGadget(#W1Btn1,300,110 ,89,25,"Quitter")
ButtonGadget(#W1Btn2,210,110 ,89,25,"Créer")
TextGadget(#W1Text1,10,10 ,381,17,"Fichier source:")
OptionGadget(#W1Option1,240,40 ,153,25,"Créer une DLL")
OptionGadget(#W1Option2,240,70 ,153,25,"Créer un fichier ASM")
CheckBoxGadget(#W1Check1,10,110,153,25,"Voir le compilateur")
EndIf
SetGadgetText(#W1Text1,"Source File: " + SourceFileName)
RunOption = #MV_RunInvisible | #MV_RunWait
Repeat
Delay(1)
EventID.l = WaitWindowEvent()
Select EventID
Case #PB_EventGadget
Select EventGadgetID()
Case #W1Btn1 ;Quit Button
CloseWindow(#Window1)
End
Case #W1Btn2 ;Create Button
If Len(CompilFlag) > 0
DeleteFile(DestFileName) ;Delete the old file
CompilerPath = "C:\Program Files\PureBasic\Compilers" ; Your CompilerPath here !!
Compiler = CompilerPath + "\PbCompiler.exe" ; The PB Compiler !!
Parameter = Chr(34) + SourceFileName + Chr(34) + CompilFlag
RunProgram(compiler , Parameter, CompilerPath, RunOption)
Select CompilFlag
Case #MV_CreateDll
CopyFile(CompilerPath + "\purebasic.dll", DestFileName)
Case #MV_CreateAsm
CopyFile(CompilerPath + "\purebasic.asm", DestFileName)
EndSelect
If ExamineDirectory(0,GetPathPart(DestFileName),GetFilePart(DestFileName))
If NextDirectoryEntry() = 1
MessageRequester("Compile TO ...", DestFileName + " has been created!", #PB_MessageRequester_Ok | #MB_ICONINFORMATION)
Else
MessageRequester("Compile TO ...", "Creation of " + DestFileName + " failled!", #PB_MessageRequester_Ok | #MB_ICONINFORMATION)
EndIf
EndIf
Else
MessageRequester("Compile TO ...", "Please select a file type before", #PB_MessageRequester_Ok | #MB_ICONINFORMATION)
EndIf
Case #W1Option1 ;Dll option checked
If GetGadgetState(#W1Option1) = #MV_Checked
CompilFlag = #MV_CreateDll
DestFileName = Left(SourceFileName,Len(SourceFileName) - 3) + ".dll"
EndIf
Case #W1Option2 ;Asm option checked
If GetGadgetState(#W1Option2) = #MV_Checked
CompilFlag = #MV_CreateAsm
DestFileName = Left(SourceFileName,Len(SourceFileName) - 3) + ".asm"
EndIf
Case #W1Check1 ;Compiler Run Mode
If GetGadgetState(#W1Check1) = #MV_Checked
RunOption = #MV_RunWait
Else
RunOption = #MV_RunInvisible | #MV_RunWait
EndIf
EndSelect
Case #WM_LBUTTONUP ;----LEFT BUTTON UP
Case #WM_LBUTTONDOWN ;----LEFT BUTTON DOWN
Case #WM_MOUSEMOVE ;----MOUSE MOVE
EndSelect
Until EventID = #PB_EventCloseWindow
EndIf
End