Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to change display settings: screen resolution, screen refresh rate
Adding and deleting Scheduled Tasks using NetScheduleJob API functions
Custom GDI+ class
Converting Unicode data from the Clipboard to a character string using a given code page
Capturing keyboard activity of another application with the Raw Input API (VFP9)
Enumerating data formats currently available on the clipboard
Winsock: sending email messages (SMTP, port 25)
Custom FTP Class for Visual FoxPro application
How to download a file from the FTP server using FtpGetFile
Detecting changes in connections to removable drives (VFP9)
Splash Screen for the VFP application
Custom HttpRequest class (WinINet)
Mapping and disconnecting network drives
How to activate Windows Calculator
Enumerating raw input devices attached to the system (keyboard, mouse, human interface device)
How to convert a bitmap file to monochrome format (1 bpp)
Custom HttpRequest class (WinHTTP)
Establishing connection using the SQLDriverConnect
GDI+: copying to the Clipboard (a) image of active FoxPro window/form, (b) image file
Using EnumPrinters function to enumerate locally installed printers
Using Font and Text functions
Using WM_COPYDATA for interprocess communication (VFP9)
Displaying bitmap using the AlphaBlend function
Extensible Storage Engine class library
Dragging files from Explorer window and dropping them on FoxPro control (requires VFP9)

User rating: 7/10 (1 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:
 
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: 7/10 (1 votes)
Rate this code sample:
  • ~
3507 bytes  
Created: 2002-08-10 09:52:33  
Modified: 2005-08-05 15:15:13  
Visits in 7 days: 146  
Listed functions:
CallWindowProc
DragAcceptFiles
DragFinish
DragQueryFile
DragQueryPoint
GetFocus
GetWindowLong
WindowProc
Printer friendly API declarations
My comment:
Read wonderful article of Andrew MacNeill Using Drag and Drop in your Applications. It explains how to use FoxPro native OLEDragOver and OLEDragDrop events for dragging and dropping files from Explorer and Outlook.
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-2013 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.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (107.22.127.92)
4 sec.Example: 'Attaching menu to a top-level form'
6.5 hrs.Example: 'How to print a bitmap file'
 Example: 'How to ping a remote site using IP Helper API calls'
6.98 hrs.Example: 'Custom GDI+ class'
10.53 hrs.Example: 'Storing registration key in the resources of an executable file'
 Example: 'Confining Windows calculator inside the VFP main window'
13.44 hrs.Function: 'BitBlt'
23.54 hrs.Example: 'Pocket PC: custom RAPI class for operating with files and folders on mobile device'
 Function: '_lopen'
2 day(s)Example: 'MapiSendMail class for Visual FoxPro application'
Google
Advertise here!