Click here to Skip to main content
15,892,537 members
Articles / Programming Languages / C++

Undocumented Visual C++

Rate me:
Please Sign up or sign in to vote.
4.91/5 (75 votes)
17 Sep 2000 746.7K   3.6K   278  
Spelunking in the Badlands of MSDEV
//*******************************************************************************
// COPYRIGHT NOTES
// ---------------
// You may use, compile or redistribute this source as part of your application 
// for free. You may not redistribute it as a part of a software development 
// library without the agreement of the author. If the sources are 
// distributed along with the application, you should leave the original 
// copyright notes in the source code without any changes.
// This code can be used WITHOUT ANY WARRANTIES on your own risk.
// 
// Nick Hodapp
// nhodapp@codeveloper.com
//
//*******************************************************************************

// Commands.cpp : Implementation of CCommands
#include "stdafx.h"
#include "OpenVC.h"
#include "Commands.h"

#include "DlgClasses.h"

/////////////////////////////////////////////////////////////////////////////
// CCommands

CCommands::CCommands()
{
}

/////////////////////////////////////////////////////////////////////////////
// ICommands

STDMETHODIMP CCommands::DeleteNCB()
{
	// save-all
	m_piApplication->ExecuteCommand(_bstr_t("FileSaveAll"));

	// obtain the MSDEV CWinApp object:
	// (this is the "magic")
	CWinApp* pApp = AfxGetApp();
	if (NULL == pApp) return E_FAIL;

	// enumerate document templates, looking for workspace doc template:
	POSITION posdt = pApp->GetFirstDocTemplatePosition();
	while (NULL != posdt)
	{
		CDocTemplate* pdt = pApp->GetNextDocTemplate(posdt);
		if (0 == strcmp("CProjectWorkspaceDocTemplate", pdt->GetRuntimeClass()->m_lpszClassName))
		{
			// found it, grab the first (and only) document:
			POSITION posdoc = pdt->GetFirstDocPosition();
			if (NULL == posdoc) break;

			CDocument* pdoc = pdt->GetNextDoc(posdoc);
			if (NULL == pdoc) break;

			// stash the workspace path+file:
			CString strWorkspace = pdoc->GetPathName();
			if (0 == strWorkspace.GetLength()) break;

			// close the workspace
			pApp->GetMainWnd()->SendMessage(WM_COMMAND, 36633); // magic number for "File/Close Workspace"

			// build the ncb filename
			CString strNCB = strWorkspace.Left(strWorkspace.GetLength()-4);
			strNCB += ".ncb";

			// delete the ncb
			if (FALSE == ::DeleteFile(strNCB))
				AfxMessageBox(CString("Error deleting NCB file:\n\n") + strNCB);
			
			// reopen the workspace
			pApp->OpenDocumentFile(strWorkspace);
		}
	}

	return S_OK;
}


STDMETHODIMP CCommands::ShowInnards()
{
	// show our dialog
	CDlgClasses* pDlg = new CDlgClasses;
	pDlg->Create(IDD_UNDOCUMENTEDVC, NULL);
	pDlg->ShowWindow(SW_SHOW);

	return S_OK;
}


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
Web Developer
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