Download demo executable - 13 Kb
Download source files - 28 Kb

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++;
}
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
:
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).