What are the basic concepts of dragging and dropping a file to a window or control?
I assume it causes some message to fire? With the file name and path?
I assume it causes some message to fire? With the file name and path?
DragDrop Multiple Files 'Compilable Example: #Compiler PBWin 9, PBWin 10 #Compile Exe #Dim All %Unicode=1 #Include "Win32API.inc" Global hDlg As Dword Function PBMain() As Long Dialog New Pixels, 0, "Drop Test",600,1400,200,200, %WS_OverlappedWindow To hDlg DragAcceptFiles hDlg, %True Control Add Label, hDlg, 200,"Drag/drop file anywhere within app!", 20,40,170,20 Dialog Show Modal hDlg Call DlgProc End Function CallBack Function DlgProc() As Long Local i,FileCount As Long, FileName As WStringZ * %Max_Path, temp$ Select Case Cb.Msg Case %WM_DROPFILES FileCount = DragQueryFile(Cb.WParam, -1, ByVal 0, 0) For i = 0 To FileCount-1 DragQueryFile Cb.WParam, i, FileName, SizeOf(FileName) temp$ = temp$ + $CrLf + FileName Next i DragFinish Cb.WParam MsgBox "Dropped filenames: " + $CrLf + $CrLf + Trim$(temp$,$CrLf) End Select End Function
Sub Settings_INI(Task$) Local xResult, yResult, tempz, INIFileName As WStringZ * %Max_Path Local WinPla As WindowPlacement, x As Long Local DefaultX, DefaultY, wDeskTop, hDeskTop As Long 'set ini filename INIFileName = Exe.Path$ + "gbprocedures.ini" If Task$ = "get" Then 'get dialog width/height from INI file and use to set Dialog size GetPrivateProfileString "All", "Width", "1200", xResult, %Max_Path, INIFileName GetPrivateProfileString "All", "Height", "600", yResult, %Max_Path, INIFileName Dialog Set Size hDlg,Val(xResult), Val(yResult) 'width/height 'default should be centered on screen Desktop Get Client To wDeskTop, hDeskTop DefaultX = (wDeskTop-Val(xResult))/2 DefaultY = (hDeskTop-Val(yResult))/2 'get dialog top/left from INI file and use to set Dialog location Getprivateprofilestring "All", "Left", Str$(DefaultX), xResult, %Max_Path, INIFileName Getprivateprofilestring "All", "Top", Str$(DefaultY), yResult, %Max_Path, INIFileName Dialog Set Loc hDlg, Val(xResult), Val(yResult) 'left/top
#DIM ALL %Unicode=1 #INCLUDE ONCE "win32api.inc" #INCLUDE ONCE "sqlitening.inc" GLOBAL hDlg AS DWORD FUNCTION SaveImage(sArray() AS STRING) AS LONG LOCAL x,hFile AS LONG, sBlob AS STRING slOpen "images.db3","C" slexe "create table if not exists t1(key integer primary key,data)" slexe "begin exclusive" 'lock database FOR x = LBOUND(sArray) TO UBOUND(sArray) hfile = FREEFILE 'Stuart got this, added OPEN sArray(x) FOR BINARY AS #hfile GET$ #hfile,LOF(hFile),sBlob CLOSE #hfile slexebind "insert into t1 values(null,?)",slBuildBindDat(sBlob) NEXT slexe "end" DIALOG SET TEXT hDlg,"Grand total dropped into Table " +_ slSelStr("select count(*) from t1") END FUNCTION FUNCTION PBMAIN() AS LONG DIALOG NEW PIXELS, 0, "Drop Test",,,400,200, %WS_OVERLAPPEDWINDOW TO hDlg DragAcceptFiles hDlg, 1 '%true CONTROL ADD LABEL, hDlg, 200,"Drag/drop file anywhere within app!", 20,40,170,20 DIALOG SHOW MODAL hDlg CALL DlgProc END FUNCTION CALLBACK FUNCTION DlgProc() AS LONG LOCAL i,FileCount AS LONG, FileName AS WSTRINGZ * %MAX_PATH, temp$ SELECT CASE CB.MSG CASE %WM_DROPFILES FileCount = DragQueryFile(CB.WPARAM, -1, BYVAL 0, 0) DIM sArray(FileCount-1) AS STRING FOR i = 0 TO FileCount-1 DragQueryFile CB.WPARAM, i, FileName, SIZEOF(FileName) sArray(i) = FileName NEXT i DragFinish CB.WPARAM ? JOIN$(sArray(),$CR),,"Dropped filenames" SaveImage sArray() END SELECT END FUNCTION
LOCAL p AS POINT ... dragquerypoint CB.WPARAM,p ? "Dropped at Window pixel co-ordinates: " & STR$(p.x) & " ," & STR$(p.y),%MB_OK,"Files dropped"
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment