Click here to Skip to main content
15,790,565 members
Articles / Desktop Programming / MFC

Sharing folders using tree control drag & drop

Rate me:
Please Sign up or sign in to vote.
4.27/5 (5 votes)
23 Feb 2000 97.4K   4.7K   33   4
A very simple manager for shared folders using tree control drag & drop
  • Download demo executable - 13 Kb
  • Download source files - 28 Kb
  • Sample Image - ShTree.gif


    This is a very simple shared folder manager that allows you to shared folders by dragging and dropping them onto a tree control.

    Using the control

    Drag a folder from an Explorer window over the tree control to create a new share. The folder will be shared without any control regarding advanced user rights. If the folder is already shared, or you have no rights, or other error occured, an error message will appear. (Keep in mind that the code is NOT very tested - being only a sample -, was developed on Windows2000/MSVC++ 6.0 SP3, and is managing only the local machine. You have to browse the network, fill a combo - or list box - and read currently selected machine from it.)

    All is done by implementing the interface IDropTargetShare, and especially the IDropTargetShare::Drop method. This implementation send WM_DROPFILES message to parent dialog, where DragQueryFile let you identify the number of dropped items, their names, and calls for each NetShareAdd loaded from netapi32.dll. After that, you can simply call in your OnInitDialog (or OnCreate, if you do not use dialogs MDI child windows, for example):

    m_lpDropTarget = new IDropTargetShare;
    	HRESULT hr = RegisterDragDrop(m_treeShare.m_hWnd, m_lpDropTarget);
    		g_cWndCountT++;	//	reference counter - the most primitive idea

    In dialog OnDestroy override, RevokeDragDrop revokes the OLE drag-drop registration. Pay attention to OleInitialize call performed in OnInitInstance of CWinApp override to ensure at least a chance for RegisterDragDrop. After that, the interface is responsable with drag and drop. Error handling could be enhanced, but you get the point.

    The tree creation uses a thread routine to fill items. Here is used a structure called SHAREINFO:

    /* sharing information */
    typedef struct _tagSHAREINFO
    	HWND  hwndDlg;
    	HWND  hwndTV;
    	UINT     uThreadId;
    	HANDLE	 hCancelEvent;
    	HANDLE	 hCloseEvent;
    	DWORD   dwUnused;
    	TCHAR lpszMachineName[_MAX_PATH + 1];

    The structure members have, I think, quite self-explanatory names. The events are used to intercept, using WaitForMultipleObjects, OnCancel or OnClose dialog events to terminate the FillShareList thread.

    The deleting of a shared folder is nothing more than a normal using of TVN_BEGINDRAG tree control notification used in conjunction with WM_LBUTTONUP and a boolean flag (m_fDragging) to switch states between ON|OFF dragging states.

    Also, the MultipleShowWindowByDlgId routine helped a lot setting the miriad of statics - it is no more that a simple use of variable-arguments functions. You could use the static control simple manipulation in the About dialog as a simple replacement for Chris Maunder's hyperlink control (to send me an e-mail message).


    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    Written By
    Web Developer
    Romania Romania
    This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

    Comments and Discussions

    GeneralMy vote of 5 Pin
    ju kwon15-Apr-13 22:28
    ju kwon15-Apr-13 22:28 
    Generaldrag and drop in VB6 Pin
    angelagke22-Jun-06 23:33
    angelagke22-Jun-06 23:33 
    GeneralShare Folder in Visual Basic Pin
    RiteshDarling12-Jan-05 4:53
    RiteshDarling12-Jan-05 4:53 
    GeneralDrag from control Pin
    dan10-Aug-00 10:48
    dan10-Aug-00 10:48 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.