Click here to Skip to main content
Click here to Skip to main content

Sharing folders using tree control drag & drop

, 23 Feb 2000
Rate this:
Please Sign up or sign in to vote.
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

    Introduction

    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;
    if(m_lpDropTarget)
    {
    	HRESULT hr = RegisterDragDrop(m_treeShare.m_hWnd, m_lpDropTarget);
    
    	if(SUCCEEDED(hr))
    		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];
    } SHAREINFO, *LPSHAREINFO;
    

    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).

    License

    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

    Share

    About the Author

    Sardaukar
    Web Developer
    Romania Romania
    No Biography provided

    Comments and Discussions

     
    GeneralMy vote of 5 Pinmemberju kwon15-Apr-13 21:28 
    Generaldrag and drop in VB6 Pinmemberangelagke22-Jun-06 22:33 
    GeneralShare Folder in Visual Basic PinmemberRiteshDarling12-Jan-05 3:53 
    GeneralDrag from control Pinsussdan10-Aug-00 9:48 

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

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

    | Advertise | Privacy | Mobile
    Web03 | 2.8.140827.1 | Last Updated 24 Feb 2000
    Article Copyright 2000 by Sardaukar
    Everything else Copyright © CodeProject, 1999-2014
    Terms of Service
    Layout: fixed | fluid