Click here to Skip to main content
11,576,064 members (59,374 online)
Click here to Skip to main content
Add your own
alternative version

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

, 20 Dec 2003 51.1K 993 38
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

Share

About the Author

Michael Sheinin
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.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150603.1 | Last Updated 21 Dec 2003
Article Copyright 2003 by Michael Sheinin
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid