How do you drag a file to screen then return the name of the file dragged?
wb3d drag files
Blitz3D Forums/Blitz3D Programming/wb3d drag files See:
WB3D_WaitEvent
WB3D_DragAcceptFiles
and please read the help file.
WB3D_WaitEvent
WB3D_DragAcceptFiles
and please read the help file.
i read the help file. i cant figure out how to get the name of the file. thats all i need. nothing else.
Ok. for some reason, it only works when you drag & drop the file then click & hold the mouse button on the title bar.
code:
Also. could u check out the ext$ line? for some reason, when i try to select a file extension in request file, it has a memory leak =S and i like extensions to work like this:
.mp3
.mid
not .mp3;.mid
thanks again Kev!
~DarkShadowWing~
code:
Include "WB3DStyles.bb" Global x = 0 Global y = 0 Graphics3D 1024,768, 32, 2 Global RuntimeWindow_hWnd = WB3D_InitializeGUI(SystemProperty("AppHwnd"),0,0,GraphicsWidth(),GraphicsHeight()) ;test1 = WB3D_CreateWindow("Test",x,y,GraphicsWidth()/4,GraphicsHeight()-71,RuntimeWindow_hWnd,0) Global copyright$ = "Copyright (c) 2008 - 2009 MTEAM"+Chr$(13)+" Created by: ~ZeldaX~" WB3D_DragAcceptFiles(RuntimeWindow_hWnd, 1) Global w Global FrameStart Global DeltaTime# = 0.1 Global GameTime# = 0 Global FPS = 60 Global FPSCount = FPS Global timFPS Global menus Global req Global snd Global snd1 Global PlaySound1 Global playa Global menu1 Global menuii Global menuselect = 0 Global file1$ Global keypressed Global menu WB3D_HotKeyEvent MOD_CONTROL,65,1 ; ctrl+a WB3D_HotKeyEvent MOD_CONTROL,76,78 ; ctrl+l ;WB3D_HotKeyEvent MOD_CONTROL,76, ; menus menus = WB3D_WindowMenu(RuntimeWindow_hWnd) file = WB3D_CreateMenu("&File",0,menus,0) OpenItem = WB3D_CreateMenu("Open",1,file,0) SaveItem = WB3D_CreateMenu("Save",2,file,0) WB3D_CreateMenu("",0,file,0) QuitItem = WB3D_CreateMenu("Quit",3,file,0) about = WB3D_CreateMenu("About",0,menus,1) about1 = WB3D_CreateMenu("About...",4,about,0) compile = WB3D_CreateMenu("Compile Code",5,menus,0) WB3D_UpdateWindowMenu(RuntimeWindow_hWnd) statusbar = WB3D_CreateStatusBar(RuntimeWindow_hWnd,"") WB3D_SetStatusParts statusbar,5+1 WB3D_StatusPartWidth(statusbar,0,150) WB3D_StatusPartWidth(statusbar,1,150) WB3D_StatusPartWidth(statusbar,2,150) WB3D_StatusPartWidth(statusbar,3,150) WB3D_StatusPartWidth(statusbar,4,150) WB3D_StatusPartWidth(statusbar,5,150) WB3D_StatusPartWidth(statusbar,6,150) ;WB3D_SetStatusText statusbar,1,"part 1" ;WB3D_SetStatusText statusbar,3,"part 3" ;WB3D_SetStatusText statusbar,4,"part 4" WB3D_UpdateStatusbar statusbar ; cleanup any old creation events, its better to do this before we enter the main ; event loop, when some gadgets are created they generate events. WB3D_FlushEvents ; setup out quit flag, and loop until the flag is set. QUIT = 0 Light = CreateLight() Listener = CreateListener(Cam, .005, 1, 1) Include "particle candy.bb" Include "particle types.bb" cam = CreateCamera() PositionEntity cam, 0, 1, 0 InitParticles(cam,"Media\particles.png", 3) SetParticleUpdateCycle 2 EM8 = CreateEmitter_Waterfall() While Not QUIT = 1 Or KeyHit(1) For do_files = 0 To WB3D_CountDroppedFiles() file1$ = WB3D_DroppedFileName(do_files) If FileExtension(file1$) = ".mp3" Or FileExtension(file1$) = ".mid" request() Else notify() EndIf Next x = 0 : y = 0 ; Frame Update FrameStart = MilliSecs() If timFPS < FrameStart Then FPS = FPSCount FPSCount = 0 timFPS = FrameStart + 1000 DeltaTime = 1.0 / Float(FPS) GameTime = GameTime + DeltaTime End If WB3D_SetStatusText statusbar,0,"FPS:"+FPS WB3D_SetStatusText statusbar,1,"menu:"+menu WB3D_SetStatusText statusbar,2,"menu1:"+menu1 WB3D_SetStatusText statusbar,3,"menuii:"+menuii WB3D_SetStatusText statusbar,4,"playa:"+playa WB3D_SetStatusText statusbar,5,"chanplay:"+ChannelPlaying(snd1) t=WB3D_CreateToolTip%(statusbar,"test",0) WB3D_SetToolTipText(t,"test") time$ = CurrentTime$() If time$ >= 12 Then am_pm$ = "PM" If time$ < 12 Then am_pm$ = "AM" WB3D_SetStatusText statusbar,6,"Time: "+time$+" "+am_pm$ If KeyDown(200) Or KeyDown(208) MoveEntity cam, 0, 0, (KeyDown(200)-KeyDown(208))*.1 If KeyDown(203) Or KeyDown(205) TurnEntity cam, 0, (KeyDown(203)-KeyDown(205))*1, 0 ; get an event of the event queue. event = WB3D_WaitEvent() Select event Case WB3D_EVENT_MENU Select WB3D_EventData() Case 1 ext$ = "*.mid"+Chr$(0)+"*.mid"+Chr$(0)+"*.mp3"+Chr$(0)+"*.mp3" file1$ = WB3D_OpenFileRequest("..","..",ext$,"") request() Case 2 Case 3 QUIT = 1 Case 4 WB3D_Notify "Menu",copyright$,0 Case 5 Write_BB("Test", "Test.bb") Case 6 Default Case WB3D_EVENT_WINDOW_CLOSE ;WB3D_ShowGadget RuntimeWindow_hWnd Select WB3D_EventSource() Case RuntimeWindow_hWnd QUIT = 1 End Select End Select FPSCount = FPSCount + 1 ; generate an internal blitz event UpdateWorld RenderWorld Flip Wend ; use notify using external winapi constants. If ChannelPlaying(snd1) stopm() EndIf WB3D_Notify "WB3D GUI Window Example","Bye, Thats It I Quit",MB_OK Or MB_ICONASTERISK WB3D_EndGUI() EndGraphics End Function notify() WB3D_Notify "WARNING","Sorry, but file "+file1$+" is invalid.",0 End Function Function request() If FileExtension(file1$) = ".mp3" Or FileExtension(file1$) = ".mid" playa = 1 EndIf If playa Then play() End Function Function play() If ChannelPlaying(snd1) = 0 And playa If FileExtension(file1$) = ".mid" music = BASS_MIDI_StreamCreateFile(0,file1$,0,0,0,0) ; we load a midi file If Not BASS_ChannelPlay (music,0) RuntimeError "Midi file not ready!" ; we play the file Else If FileExtension(file1$) = ".mp3" snd=LoadSound(file1$) : snd1 = PlaySound(snd) EndIf EndIf Else If ChannelPlaying(snd1) And playa stopm() play() EndIf EndIf If menus = 1 menu1 = file1$ menuii = FileExtension(file1$) EndIf End Function Function stopm() If playa = 1 StopChannel snd1 EndIf End Function Function Write_BB(appname$, filedata$) readme=WriteFile("README.txt") WriteLine readme, "Please use Blitz3D to compile your project!" file=WriteFile(filedata$) WriteLine file, "AppTitle "+Chr$(34)+appname$+Chr$(34) WriteLine file, "" WriteLine file, "Graphics3D "+screenwidth+", "+screenheight+", "+screendepth+", "+screenmode WriteLine file, "" WriteLine file, "cam = CreateCamera()" WriteLine file, "CameraRange cam, .1, 1000000" WriteLine file, "PositionEntity cam, "+xcam+", 1, "+zcam WriteLine file, "" WriteLine file, "Land = CreatePlane()" WriteLine file, "" WriteLine file, "While Not Keyhit(1)" WriteLine file, "" WriteLine file, "If KeyDown(200) Or KeyDown(208) MoveEntity cam, 0, 0, (KeyDown(200)-KeyDown(208))*1" WriteLine file, "If KeyDown(203) Or KeyDown(205) TurnEntity cam, 0, (KeyDown(203)-KeyDown(205))*1, 0" WriteLine file, "" WriteLine file, "UpdateWorld()" WriteLine file, "RenderWorld()" WriteLine file, "" WriteLine file, "Flip" WriteLine file, "" WriteLine file, "Wend" CloseFile file WB3D_Notify "Menu","Compilation Successful",0 WB3D_Notify "Menu","Compiled file in: "+CurrentDir$(),0 End Function Function get_menu() menu = menu + 1 If menu > 43 Then menu = 43 Return menu End Function Function File_Extension$(ext$) For I% = Len(ext$) To 1 Step -1 If Mid$(ext$, I%,1) = "," Then Return "*"+Left(ext$, I%-1)+";"+"*"+ Right$(ext$, I%-1) Next End Function Function FileName$(File$) For I% = Len(File$) To 1 Step -1 If Mid(File$, I%, 1) = "" Or Mid(File$, I%, 1) = "/" Then Return Mid(File$, I% + 1) Next Return File$ End Function Function FileExtension$(File$) For I% = Len(File$) To 1 Step -1 If Mid(File$, I%, 1) = "." Return "."+Mid(File$, I% + 1) If Mid(File$, I%, 1) = "" Or Mid(File$, I%, 1) = "/" Then Return "" Next End Function Function FilePath$(File$) For I% = Len(File$) To 1 Step -1 If Mid(File$, I%, 1) = "" Or Mid(File$, I%, 1) = "/" Then Return Left(File$, I% - 1) Next End Function ; Adds a file extention, if not exists. | F?Et eine Dateiendung hinzu falls noch keine da ist. Function AddFileExtension$(File$, Extension$) If FileExtension(File$) = "" Then Return File$ + "." + Extension$ Else Return File$ End Function
Also. could u check out the ext$ line? for some reason, when i try to select a file extension in request file, it has a memory leak =S and i like extensions to work like this:
.mp3
.mid
not .mp3;.mid
thanks again Kev!
~DarkShadowWing~
first up where your event loop is your not processing WB3D_EVENT_DRAGDROP so!
think of WB3D_WaitEvent() as the command to check if theres any GUI events, everything WB3D has to be process using the event system. You cant just drop WB3D code in your blitz main loop it needs to be handled using WB3D's event system.
Also. could u check out the ext$ line? for some reason, when i try to select a file extension in request file, it has a memory leak =S and i like extensions to work like this:
umm im not sure about a memory leak when using file requesters i will look into it, extension layout is defined by the windows api i have no control of this.
Kev
; get an event of the event queue. event = WB3D_WaitEvent() Select event Case WB3D_EVENT_DRAGDROP For do_files = 0 To WB3D_CountDroppedFiles() file1$ = WB3D_DroppedFileName(do_files) If FileExtension(file1$) = ".mp3" Or FileExtension(file1$) = ".mid" request() Else notify() EndIf Next End Select
think of WB3D_WaitEvent() as the command to check if theres any GUI events, everything WB3D has to be process using the event system. You cant just drop WB3D code in your blitz main loop it needs to be handled using WB3D's event system.
Also. could u check out the ext$ line? for some reason, when i try to select a file extension in request file, it has a memory leak =S and i like extensions to work like this:
umm im not sure about a memory leak when using file requesters i will look into it, extension layout is defined by the windows api i have no control of this.
Kev
Thanks man! =) Also, delete the Include Particles.bb line, and compile my project then click File => Open File and select a file type to see the said memory leak.
Thanks again! =)
~DarkShadowWing~
Thanks again! =)
~DarkShadowWing~
Also, how would i activate the drag drop case in the main loop?
Copied and saved for the future - thanks Kev.
DarkShadowWing, the window that you want to accept file in pass to WB3D_DragAcceptFiles()
no problems john :)
WB3D_DragAcceptFiles window,True
no problems john :)
i hope you didnt copy my data, john. because this is gonna be a copyright program in the future. please delete it if you did.
and kev, i was sayin how do you activate the case? not the actual drag code.
~DarkShadowWing~
and kev, i was sayin how do you activate the case? not the actual drag code.
~DarkShadowWing~
Err... if you check the WB3D help file you'll see me listed as one of the beta-testers.
So no, I didn't copy your code.
As we say up North, 'Ah, bless'.
So no, I didn't copy your code.
As we say up North, 'Ah, bless'.
Ok its cool man