SOL9 2.0 Class: DropFiles

 SOL9 C++ Class Library  SOL9 Samples  SOL9 Tutorial  SOL9 FAQ  SOL9 ClassTree 

Source code

/*
 * DropFiles.h 
 * Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL++2000
#pragma once
#include <sol\Event.h>
#include <sol\StringList.h>

#include <shellapi.h>
#include <shlobj.h>


namespace SOL {

class DropFiles :public Object {
private:
    BOOL    dropped;
    HDROP    hdrop;
    int        num;
private:
    HDROP build(StringList* stringList, POINT pt, BOOL ncFlag,
                     BOOL wcFlag=FALSE)
    {
        HDROP hdrop = NULL;
        if(stringList) {
            ListEntry* ptr = stringList->getEntry();        
            int buffLen = 0;
            while(ptr) {
                String* string = (String*)ptr->getObject();
                if(string) {
                    buffLen = buffLen + string->getLength() + 1;
                }
                ptr = ptr ->getNext();
            }
        
            int    size = sizeof(DROPFILES) + buffLen+1;
    
            hdrop = (HDROP)::GlobalAlloc(GHND, size);
            if(hdrop) {
                DROPFILES* dropFiles = (DROPFILES*)::GlobalLock(hdrop);        
                int   offset = sizeof(DROPFILES);
                dropFiles->pFiles = offset;
                dropFiles->pt  = pt;
                dropFiles->fNC = ncFlag;    // True, if pt is in screen coords.
#ifdef UNICODE
                dropFiles->fWide = TRUE;    // True, if wide TCHAR switching
#else
                dropFiles->fWide = FALSE;    // True, if wide TCHAR switching

#endif
                TCHAR* buffer = (TCHAR*)dropFiles + offset;

                ptr = stringList->getEntry();
                int pos = 0;
                while(ptr) {
                    String* string = (String*)ptr->getObject();
                    if(string) {

                        strcpy(buffer, string->getContents());
                        
                        pos = string->getLength() + 1;
                        buffer = buffer + pos;
                    }
                    ptr = ptr ->getNext();
                }
                ::GlobalUnlock(hdrop);
                num = ::DragQueryFile(hdrop, 0xFFFFFFFF, NULL, 0);
            }
        }
        return hdrop;
    }

public:

    DropFiles(HDROP drop) 
    {
        num      = 0;
        hdrop    = drop;
        dropped  = TRUE;
        num      = ::DragQueryFile(hdrop, 0xFFFFFFFF, NULL, 0);
    }

public:
    DropFiles(const TCHAR* fileName, POINT pt, BOOL ncFlag,
                     BOOL wcFlag)
    {
        num = 0;
        dropped = FALSE;
        hdrop = NULL;

        if(fileName) {
            StringList stringList;
            stringList.addLast(fileName);
            hdrop   = build(&stringList, pt, ncFlag, wcFlag);
        }
    }

public:
    DropFiles(StringList* stringList, POINT pt, BOOL ncFlag,
                     BOOL wcFlag = FALSE)
    {
        num     = 0;
        dropped = FALSE;
        hdrop   = build(stringList, pt, ncFlag, wcFlag);
    }




public:
    ~DropFiles()
    {
        if(hdrop && dropped) {
            ::DragFinish(hdrop);
        }
    }

public:
    int    queryFile(int indx, TCHAR* fileName, int size)
    {
        int length = 0;
        if(indx >= 0 && indx < num) {
            length = ::DragQueryFile(hdrop, indx, fileName, size);
        }
        return length;
    }

public:
    int    DropFiles::queryFileNameLength(int indx)
    {
        int length = 0;
        if(indx >= 0 && indx < num) {
            length = ::DragQueryFile(hdrop, indx, NULL, 0);
        }
        return length;
    }

public:
    void DropFiles::queryPoint(POINT* pt)
    {
        pt->x = 0;
        pt->y = 0;
        if(hdrop) {
            ::DragQueryPoint(hdrop, pt);
        }
    }

    int     queryCount() {
            return num;
    }
    HDROP     getDropHandle() {
            return hdrop;
    }

};

}



Last modified: 1 Feb 2012

Copyright (c) 2009-2012 Antillia.com ALL RIGHTS RESERVED.