Click here to Skip to main content
15,886,518 members
Articles / Database Development / SQL Server

Stored Procedure Class Wizard (SPCW)

Rate me:
Please Sign up or sign in to vote.
4.76/5 (15 votes)
8 May 2001 185.6K   3.2K   50  
A tool to generate class files to implement stored procedures
///////////////////////////////////////////////////////////////////////////
// DirDialog.cpp: implementation of the CDirDialog class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "DirDialog.h"
#include "shlobj.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

// Callback function called by SHBrowseForFolder's browse control
// after initialization and when selection changes
static int __stdcall BrowseCtrlCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
{
	CDirDialog* pDirDialogObj = (CDirDialog*)lpData;
	
	if(uMsg == BFFM_INITIALIZED && !pDirDialogObj->m_strSelDir.IsEmpty())
		::SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)(LPCTSTR)(pDirDialogObj->m_strSelDir));
	else // uMsg == BFFM_SELCHANGED
		;
	
	return 0;
}

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CDirDialog::CDirDialog()
{
}

CDirDialog::CDirDialog(CWnd* pWnd)
{
	m_pParent = pWnd;
}

CDirDialog::~CDirDialog( )
{
}

int CDirDialog::DoBrowse()
{
	LPMALLOC pMalloc;
	
	if(SHGetMalloc(&pMalloc) != NOERROR)
		return 0;
	
	BROWSEINFO bInfo;
	LPITEMIDLIST pidl;
	
	::ZeroMemory((PVOID)&bInfo, sizeof(BROWSEINFO));
	
	if(!m_strInitDir.IsEmpty())
	{
		OLECHAR       olePath[MAX_PATH];
		ULONG         chEaten;
		ULONG         dwAttributes;
		HRESULT       hr;
		LPSHELLFOLDER pDesktopFolder;
		
		// Get a pointer to the Desktop's IShellFolder interface. 
		if(SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder)))
		{
			// IShellFolder::ParseDisplayName requires the file name be in Unicode.
			::MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, m_strInitDir.GetBuffer(MAX_PATH), -1,
										olePath, MAX_PATH);
			
			m_strInitDir.ReleaseBuffer(-1);
			
			// Convert the path to an ITEMIDLIST.
			hr = pDesktopFolder->ParseDisplayName(NULL, NULL, olePath, &chEaten, 
								&pidl, &dwAttributes);
			
			if(FAILED(hr))
			{
				pMalloc ->Free(pidl);
				pMalloc ->Release();
				return 0;
			}
			
			bInfo.pidlRoot = pidl;
		}
	}
	
	
	LPTSTR lpszPath = m_strPath.GetBuffer(MAX_PATH);
	m_strPath.ReleaseBuffer();
	bInfo.pszDisplayName = lpszPath;
	bInfo.hwndOwner = m_pParent->m_hWnd;
	bInfo.lpszTitle = (m_strTitle.IsEmpty()) ? "Open" : m_strTitle;
	bInfo.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
	bInfo.lpfn = BrowseCtrlCallback;  // address of callback function
	bInfo.lParam = (LPARAM)this;      // pass address of object to callback function
	
	if((pidl = ::SHBrowseForFolder(&bInfo)) == NULL)
		return 0;
		
	m_nImageIndex = bInfo.iImage;
	
	if(::SHGetPathFromIDList(pidl, lpszPath) == FALSE)
	{
		pMalloc->Free(pidl);
		pMalloc->Release();
		return 0;
	}
	
	pMalloc ->Free(pidl);
	pMalloc ->Release();
	
	return 1;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

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


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

Comments and Discussions