Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
GDI+: copying to the Clipboard (a) image of active FoxPro window/form, (b) image file
Adding and deleting Scheduled Tasks using NetScheduleJob API functions
How to change display settings: screen resolution, screen refresh rate
Enumerating printer drivers installed
Using Video Capture: displaying on FoxPro form frames and previewing video obtained from a digital camera
Capturing keyboard activity of another application with the Raw Input API (VFP9)
Custom GDI+ class
How to retrieve information about a cache entry (Internet Explorer)
Custom HttpRequest class (WinHTTP)
How to convert a bitmap file to monochrome format (1 bpp)
Using FoxTray ActiveX control: System Tray Icon and menu attached to VFP form
Windows Shell Icons displayed and exported to ICO files (Vista)
Enumerating raw input devices attached to the system (keyboard, mouse, human interface device)
How to activate Windows Calculator
Winsock: retrieving Web pages using sockets (HTTP, port 80)
How to display Windows On-Screen Keyboard
How to set Creation Date/Time for a folder (WinNT)
Custom HttpRequest class (WinINet)
Mapping and disconnecting network drives
Setting the date and time that a file was created
Winsock: sending email messages (SMTP, port 25)
Using EnumPrinters function to enumerate locally installed printers
Using WM_COPYDATA for interprocess communication (VFP9)
GDI+: Implementing image scrolling with inertia
Dragging files from Explorer window and dropping them on FoxPro control (requires VFP9)

User rating: 9/10 (3 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Before you begin:


Note that the code sample below just displays the names of files dropped on VFP form in ListBox control. It does not copy or move these files, so the testing is absolutely safe.

See also:
  • Tracking mouse movement to detect when to start dragging
  • How to drag a Form not using its Titlebar or Caption
  • LOCAL oForm As TForm
    oForm = CREATEOBJECT("TForm")
    oForm.Visible=.T.
    READ EVENTS
    * end of main
    
    DEFINE CLASS TForm As Form
    #DEFINE WM_DROPFILES 0x0233
    #DEFINE GWL_WNDPROC -4
    #DEFINE MAX_PATH 260
    
    PROTECTED hWindow, hOrigProc
        hWindow=0
        hOrigProc=0
        Width=350
        Height=200
        MinButton=.F.
        MaxButton=.F.
        Caption=" Dropping files on the form"
        ShowWindow=2
        Autocenter=.T.
    
        ADD OBJECT ch As CheckBox WITH;
        Left=10, Top=10, Autosize=.T., BackStyle=0,;
        Caption="Accept dropped files", Value=0
    
        ADD OBJECT lst As ListBox WITH;
        Left=5, Top=40, Width=340, Height=130
    
        ADD OBJECT lbl As Label WITH;
        Left=10, Top=176, Autosize=.T., BackStyle=0,;
        Caption="Drag files from an Explorer window and drop on the listbox"
    
    PROCEDURE Init
        THIS.declare
    
    PROCEDURE Destroy
        THIS.ReleaseAccept
        CLEAR EVENTS
    
    PROCEDURE ch.InteractiveChange
        IF THIS.Value = 1
            ThisForm.SetAccept
        ELSE
            ThisForm.ReleaseAccept
        ENDIF
    
    PROCEDURE SetAccept
        THIS.hWindow = GetFocus()
        THIS.hOrigProc = GetWindowLong(THIS.hWindow, GWL_WNDPROC)
    
        IF VERSION(5) >= 900
            = BINDEVENT(THIS.hWindow, WM_DROPFILES,;
                THIS, "OnFilesDropped")
        ENDIF
        = DragAcceptFiles(THIS.hWindow, 1)
    
    PROCEDURE ReleaseAccept
        = UNBINDEVENTS(THIS)
    
        IF THIS.hWindow <> 0
            = DragAcceptFiles(THIS.hWindow, 0)
            THIS.hWindow=0
        ENDIF
    
    PROCEDURE OnFilesDropped(hWindow as Integer,;
        nMsgID as Integer, wParam as Integer, lParam as Integer)
    * requires VFP9, otherwise ignored
    * note that input parameters are predefined and should not be changed
    * see WindowProc function for details
    
        LOCAL nReturn
        nReturn=0
    
        DO CASE
        CASE nMsgID=WM_DROPFILES
            THIS.ProcessDroppedFiles(wParam)
    
        OTHERWISE
        * pass control to the original window procedure
            nReturn = CallWindowProc(THIS.hOrigProc, THIS.hWindow,;
                m.nMsgID, m.wParam, m.lParam)
        ENDCASE
    RETURN nReturn
    
    PROTECTED PROCEDURE ProcessDroppedFiles(hDrop)
        LOCAL cPoint, nX, nY
    
        cPoint = REPLICATE(CHR(0),8)  && POINT buffer
        = DragQueryPoint(hDrop, @cPoint)
    
        nX = buf2dword(SUBSTR(cPoint,1,4))
        nY = buf2dword(SUBSTR(cPoint,5,4))
    
        * only if clicked inside the listbox
        WITH THIS.lst
            IF NOT (BETWEEN(nX, .Left, .Left+.Width-1);
                AND BETWEEN(nY, .Top, .Top+.Height-1))
                RETURN
                = DragFinish(hDrop)
            ENDIF
        ENDWITH
    
        THIS.lst.Clear
    
        LOCAL nFilecount, nIndex, cBuffer, nLength
        nFilecount = DragQueryFile(hDrop, 0xFFFFFFFF, Null, 0)
    
        FOR nIndex=0 TO nFilecount-1
            cBuffer = REPLICATE(CHR(0), MAX_PATH)
            nLength = DragQueryFile(hDrop, nIndex, @cBuffer, MAX_PATH)
            cBuffer = SUBSTR(cBuffer, 1, nLength)
            THIS.lst.AddItem(cBuffer)
        NEXT
    
        = DragFinish(hDrop)
    
    PROTECTED PROCEDURE declare
        DECLARE INTEGER GetFocus IN user32
        DECLARE DragFinish IN shell32 INTEGER hDrop
    
        DECLARE DragAcceptFiles IN Shell32;
            INTEGER hWindow, INTEGER fAccept
    
        DECLARE INTEGER DragQueryFile IN shell32;
            INTEGER hDrop, INTEGER iFile,;
            STRING @lpszFile, INTEGER cch
    
        DECLARE INTEGER DragQueryPoint IN shell32;
            INTEGER hDrop, STRING @lppt
    
        DECLARE INTEGER CallWindowProc IN user32;
            INTEGER lpPrevWndFunc, INTEGER hWindow, LONG Msg,;
            INTEGER wParam, INTEGER lParam
    
        DECLARE INTEGER GetWindowLong IN user32;
            INTEGER hWindow, INTEGER nIndex
    
    ENDDEFINE
    
    FUNCTION buf2dword(lcBuffer)
    RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
        BitLShift(Asc(SUBSTR(lcBuffer, 2,1)),  8) +;
        BitLShift(Asc(SUBSTR(lcBuffer, 3,1)), 16) +;
        BitLShift(Asc(SUBSTR(lcBuffer, 4,1)), 24)
    
    
    

    User rating: 9/10 (3 votes)
    Rate this code sample:
    • ~
    3511 bytes  
    Created: 2002-08-10 09:52:33  
    Modified: 2013-09-08 15:13:13  
    Visits in 7 days: 60  
    Listed functions:
    CallWindowProc
    DragAcceptFiles
    DragFinish
    DragQueryFile
    DragQueryPoint
    GetFocus
    GetWindowLong
    WindowProc
    Printer friendly API declarations
    My comment:
    WM_DROPFILES window message -- sent when the user drops a file on the window of an application that has registered itself as a recipient of dropped files.

    DragAcceptFiles function -- registers whether a window accepts dropped files.

    A good reading on the subject, Andrew MacNeill`s Using Drag and Drop in your Applications. The article explains the basics and the more of using FoxPro native OLEDragOver and OLEDragDrop events for dragging and dropping files from Explorer and Outlook windows.
    Word Index links for this example:
    Translate this page:
      Spanish    Portuguese    German    French    Italian  
    FreeTranslation.com offers instant, free translations of text or web pages.
    User Contributed Notes:
    mgreene@bdurham.com | 2005-05-22 22:02:07
    Anatoliy,

    Any ideas on how one can use OLEDragDrop to receive BMP or WAV content dropped on a VFP control? VFP's OLEDragDrop oDataObject.GetFormat() (2 for BMP, 12 for WAV) properly recognizes these data formats, but VFP's oDataObject.GetData() (2 for BMP, 12 for WAV) always returns .F. when one tries to retrieve this data.

    I've tried both the array and non-array versions of GetData() with the same result. Note that I can receive strings and files (VFP 9) fine. Now I want to do the hard stuff.

    Any suggestions appreciated,

    Malcolm

    Copyright 2001-2014 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

    Privacy policy
    Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.68), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (54.204.94.228)
    1 day(s)Function: 'CeFindFirstFile'
    Google
    Advertise here!