Click here to Skip to main content
15,885,366 members
Articles / Programming Languages / C++

Customized Visual Studio .NET package: your fully integrated document window inside the IDE

Rate me:
Please Sign up or sign in to vote.
4.72/5 (20 votes)
20 Dec 200313 min read 63.7K   1.1K   39  
Create a fully integrated document window inside the Visual Studio IDE.
#include "StdAfx.h"
#include ".\fileinfo.h"
#include "commandIDs.h"

CFileInfo::CFileInfo(void):CGraphicObject(),CDataObject()
{
	m_szLength[0] = 0;
	m_szSignature[0] = 0;
	m_szName[0] = 0;
	m_szLastCmd[0] = 0;
	m_hFont = CreateFont( 18, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
		DEFAULT_QUALITY, DEFAULT_PITCH, "Courier New");
}

CFileInfo::~CFileInfo(void)
{
	if ( m_hFont )
	{
		::DeleteObject( m_hFont );
	}
}

void CFileInfo::Draw(HDC hDC)
{
	HGDIOBJ hOldFont = ::SelectObject(hDC,m_hFont);
	this->DrawText( hDC, 2, -2, RGB(230,230,230) );
	this->DrawText( hDC, 0, 0, 0 );
	::SelectObject(hDC,hOldFont);
}

void CFileInfo::DrawText(HDC hDC, int iXOfs, int iYOfs, COLORREF clrText )
{
	RECT rc = m_rcBound;
	rc.left += iXOfs;
	rc.top += iYOfs;
	rc.bottom += iYOfs;
	rc.right += iXOfs;
	int iYStep = (rc.bottom-rc.top)/4;
	
	int iOldBkMode = ::SetBkMode( hDC, TRANSPARENT );
	COLORREF clrOldTxt = ::SetTextColor( hDC, clrText );

	rc.bottom = rc.top + iYStep;
	::DrawTextW(hDC, m_szSignature, lstrlenW(m_szSignature), &rc,
			DT_VCENTER|DT_SINGLELINE );

	rc.top = rc.bottom;
	rc.bottom += iYStep;
	::DrawTextW(hDC, m_szName, lstrlenW(m_szName), &rc,
		DT_VCENTER|DT_SINGLELINE|DT_PATH_ELLIPSIS );

	rc.top = rc.bottom;
	rc.bottom += iYStep;
	::DrawTextW(hDC, m_szLength, lstrlenW(m_szLength), &rc,
		DT_VCENTER|DT_SINGLELINE );

	rc.top = rc.bottom;
	rc.bottom += iYStep;
	::DrawTextW(hDC, m_szLastCmd, lstrlenW(m_szLastCmd), &rc,
		DT_VCENTER|DT_SINGLELINE );

	::SetBkMode( hDC, iOldBkMode );
	::SetTextColor( hDC, clrOldTxt );

}


void CFileInfo::SetSignature(LPCWSTR szSignature)
{
	wsprintfW( m_szSignature, L"%s", szSignature );
	m_bNotSaved = TRUE;
}
void CFileInfo::SetLength( int iLen )
{
	wsprintfW( m_szLength, L"File Length: %d bytes", iLen );
	m_bNotSaved = TRUE;
}

void CFileInfo::SetName(LPCWSTR szName)
{
	wsprintfW( m_szName, L"File Name: %s", szName );
	m_bNotSaved = TRUE;
}

BOOL CFileInfo::UserAction(UINT uMsg, LPVOID pParams)
{
	if ( uMsg & 0x80000000 )
	{
		LPCWSTR wszCmdDescr = NULL;

		switch( ~uMsg )
		{
		case COMMAND_ID_CUT:
			wszCmdDescr = L"Cut";
			break;
		case COMMAND_ID_COPY:
			wszCmdDescr = L"Copy";
			break;
		case COMMAND_ID_PASTE:
			wszCmdDescr = L"Paste";
			break;
		case COMMAND_ID_SAVE:
			wszCmdDescr = L"Save";
			break;
		case COMMAND_ID_SAVEALL:
			wszCmdDescr = L"Save All";
			break;
		case COMMAND_ID_UNDO:
			wszCmdDescr = L"Undo";
			break;
		case COMMAND_ID_REDO:
			wszCmdDescr = L"Redo";
			break;
		case COMMAND_ID_DELETE:
			wszCmdDescr = L"Delete";
			break;
		default:
			wszCmdDescr = L"";
		};
		wsprintfW( m_szLastCmd, L"Last Command: %s", wszCmdDescr );
		return TRUE;
	}
	return FALSE;
}

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
For the last 7 years I have developed software in real-time/embedded and MS-Windows environments for military and civil markets. I hold B.Sc. degree in computer engineering. Living in Ontario, Canada, I like hiking and traveling in general. Currently, I'm looking for employment opportunity inside the GTA.

Comments and Discussions